mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-03 10:50:20 +00:00
*: Make force upgrading part of app rather than a module
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
f6ef0135d2
commit
bb2cbace6c
@ -16,7 +16,7 @@ from plinth import cfg, menu
|
||||
from plinth.daemon import Daemon
|
||||
from plinth.modules.backups.components import BackupRestore
|
||||
from plinth.modules.firewall.components import Firewall
|
||||
from plinth.package import Packages
|
||||
from plinth.package import Packages, install
|
||||
from plinth.utils import format_lazy
|
||||
|
||||
from . import manifest
|
||||
@ -107,11 +107,10 @@ class BindApp(app_module.App):
|
||||
str(old_version)])
|
||||
self.enable()
|
||||
|
||||
|
||||
def force_upgrade(helper, _packages):
|
||||
"""Force upgrade the managed packages to resolve conffile prompt."""
|
||||
helper.install(['bind9'], force_configuration='old')
|
||||
return True
|
||||
def force_upgrade(self, _packages):
|
||||
"""Force upgrade the managed packages to resolve conffile prompt."""
|
||||
install(['bind9'], force_configuration='old')
|
||||
return True
|
||||
|
||||
|
||||
def get_config():
|
||||
|
||||
@ -13,7 +13,7 @@ from plinth import app as app_module
|
||||
from plinth import cfg, menu
|
||||
from plinth.daemon import Daemon
|
||||
from plinth.modules.backups.components import BackupRestore
|
||||
from plinth.package import Packages
|
||||
from plinth.package import Packages, install
|
||||
from plinth.utils import Version, format_lazy, import_from_gi
|
||||
|
||||
from . import manifest
|
||||
@ -83,6 +83,22 @@ class FirewallApp(app_module.App):
|
||||
super().setup(old_version)
|
||||
_run_setup()
|
||||
|
||||
def force_upgrade(self, packages):
|
||||
"""Force upgrade firewalld to resolve conffile prompts."""
|
||||
if 'firewalld' not in packages:
|
||||
return False
|
||||
|
||||
# firewalld 0.6.x -> 0.7.x, 0.6.x -> 0.8.x, 0.7.x -> 0.8.x, 0.9.x ->
|
||||
# 1.0.x
|
||||
package = packages['firewalld']
|
||||
if Version(package['current_version']) >= Version('1.0') or \
|
||||
Version(package['new_version']) < Version('0.7'):
|
||||
return False
|
||||
|
||||
install(['firewalld'], force_configuration='new')
|
||||
_run_setup()
|
||||
return True
|
||||
|
||||
|
||||
def _run_setup():
|
||||
"""Run firewalld setup."""
|
||||
@ -95,22 +111,6 @@ def _run_setup():
|
||||
add_service('dhcp', 'internal')
|
||||
|
||||
|
||||
def force_upgrade(helper, packages):
|
||||
"""Force upgrade firewalld to resolve conffile prompts."""
|
||||
if 'firewalld' not in packages:
|
||||
return False
|
||||
|
||||
# firewalld 0.6.x -> 0.7.x, 0.6.x -> 0.8.x, 0.7.x -> 0.8.x, 0.9.x -> 1.0.x
|
||||
package = packages['firewalld']
|
||||
if Version(package['current_version']) >= Version('1.0') or \
|
||||
Version(package['new_version']) < Version('0.7'):
|
||||
return False
|
||||
|
||||
helper.install(['firewalld'], force_configuration='new')
|
||||
_run_setup()
|
||||
return True
|
||||
|
||||
|
||||
def _get_dbus_proxy(object, interface):
|
||||
"""Return a DBusProxy for a given firewalld object and interface."""
|
||||
connection = gio.bus_get_sync(gio.BusType.SYSTEM)
|
||||
|
||||
@ -11,7 +11,7 @@ from plinth.modules.apache.components import Webserver
|
||||
from plinth.modules.backups.components import BackupRestore
|
||||
from plinth.modules.firewall.components import Firewall
|
||||
from plinth.modules.users.components import UsersAndGroups
|
||||
from plinth.package import Packages
|
||||
from plinth.package import Packages, install
|
||||
from plinth.utils import Version
|
||||
|
||||
from . import manifest
|
||||
@ -97,6 +97,22 @@ class MiniDLNAApp(app_module.App):
|
||||
if not old_version:
|
||||
self.enable()
|
||||
|
||||
def force_upgrade(self, packages):
|
||||
"""Force upgrade minidlna to resolve conffile prompt."""
|
||||
if 'minidlna' not in packages:
|
||||
return False
|
||||
|
||||
# Allow upgrade from 1.2.1+dfsg-1+b1 to 1.3.x
|
||||
package = packages['minidlna']
|
||||
if Version(package['new_version']) > Version('1.4~'):
|
||||
return False
|
||||
|
||||
media_dir = get_media_dir()
|
||||
install(['minidlna'], force_configuration='new')
|
||||
set_media_dir(media_dir)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def get_media_dir():
|
||||
"""Return the currently set media directory."""
|
||||
@ -106,20 +122,3 @@ def get_media_dir():
|
||||
def set_media_dir(media_dir):
|
||||
"""Set the media directory from which files will be scanned for sharing."""
|
||||
actions.superuser_run('minidlna', ['set-media-dir', '--dir', media_dir])
|
||||
|
||||
|
||||
def force_upgrade(helper, packages):
|
||||
"""Force upgrade minidlna to resolve conffile prompt."""
|
||||
if 'minidlna' not in packages:
|
||||
return False
|
||||
|
||||
# Allow upgrade from 1.2.1+dfsg-1+b1 to 1.3.x
|
||||
package = packages['minidlna']
|
||||
if Version(package['new_version']) > Version('1.4~'):
|
||||
return False
|
||||
|
||||
media_dir = get_media_dir()
|
||||
helper.install(['minidlna'], force_configuration='new')
|
||||
set_media_dir(media_dir)
|
||||
|
||||
return True
|
||||
|
||||
@ -16,7 +16,7 @@ from plinth.modules.backups.components import BackupRestore
|
||||
from plinth.modules.firewall.components import Firewall
|
||||
from plinth.modules.letsencrypt.components import LetsEncrypt
|
||||
from plinth.modules.users.components import UsersAndGroups
|
||||
from plinth.package import Packages
|
||||
from plinth.package import Packages, install
|
||||
from plinth.utils import Version
|
||||
|
||||
from . import manifest, privileged
|
||||
@ -102,20 +102,19 @@ class MumbleApp(app_module.App):
|
||||
|
||||
app.get_component('letsencrypt-mumble').setup_certificates()
|
||||
|
||||
def force_upgrade(self, packages):
|
||||
"""Force upgrade mumble-server to resolve conffile prompts."""
|
||||
if 'mumble-server' not in packages:
|
||||
return False
|
||||
|
||||
def force_upgrade(helper, packages):
|
||||
"""Force upgrade mumble-server to resolve conffile prompts."""
|
||||
if 'mumble-server' not in packages:
|
||||
return False
|
||||
# Allow upgrades within 1.3.*
|
||||
package = packages['mumble-server']
|
||||
if Version(package['new_version']) > Version('1.4~'):
|
||||
return False
|
||||
|
||||
# Allow upgrades within 1.3.*
|
||||
package = packages['mumble-server']
|
||||
if Version(package['new_version']) > Version('1.4~'):
|
||||
return False
|
||||
|
||||
helper.install(['mumble-server'], force_configuration='new')
|
||||
privileged.setup()
|
||||
return True
|
||||
install(['mumble-server'], force_configuration='new')
|
||||
privileged.setup()
|
||||
return True
|
||||
|
||||
|
||||
def get_available_domains():
|
||||
|
||||
@ -15,7 +15,7 @@ from plinth.modules.apache.components import Uwsgi, Webserver
|
||||
from plinth.modules.backups.components import BackupRestore
|
||||
from plinth.modules.firewall.components import Firewall
|
||||
from plinth.modules.users.components import UsersAndGroups
|
||||
from plinth.package import Packages
|
||||
from plinth.package import Packages, install
|
||||
from plinth.utils import Version, format_lazy
|
||||
|
||||
from . import manifest
|
||||
@ -103,22 +103,22 @@ class RadicaleApp(app_module.App):
|
||||
super().setup(old_version)
|
||||
self.enable()
|
||||
|
||||
def force_upgrade(self, packages):
|
||||
"""Force upgrade radicale to resolve conffile prompt."""
|
||||
if 'radicale' not in packages:
|
||||
return False
|
||||
|
||||
def force_upgrade(helper, packages):
|
||||
"""Force upgrade radicale to resolve conffile prompt."""
|
||||
if 'radicale' not in packages:
|
||||
return False
|
||||
# Allow upgrade from 2.* to newer 2.* and 3.*
|
||||
package = packages['radicale']
|
||||
if Version(package['new_version']) > Version('4~'):
|
||||
return False
|
||||
|
||||
# Allow upgrade from 2.* to newer 2.* and 3.*
|
||||
package = packages['radicale']
|
||||
if Version(package['new_version']) > Version('4~'):
|
||||
return False
|
||||
rights = get_rights_value()
|
||||
install(['radicale'], force_configuration='new')
|
||||
actions.superuser_run('radicale',
|
||||
['configure', '--rights_type', rights])
|
||||
|
||||
rights = get_rights_value()
|
||||
helper.install(['radicale'], force_configuration='new')
|
||||
actions.superuser_run('radicale', ['configure', '--rights_type', rights])
|
||||
|
||||
return True
|
||||
return True
|
||||
|
||||
|
||||
def load_augeas():
|
||||
|
||||
@ -10,7 +10,7 @@ from plinth import frontpage, menu
|
||||
from plinth.modules.apache.components import Webserver
|
||||
from plinth.modules.backups.components import BackupRestore
|
||||
from plinth.modules.firewall.components import Firewall
|
||||
from plinth.package import Packages
|
||||
from plinth.package import Packages, install
|
||||
|
||||
from . import manifest, privileged
|
||||
|
||||
@ -97,16 +97,15 @@ class RoundcubeApp(app_module.App):
|
||||
privileged.set_config(local_only=True)
|
||||
self.enable()
|
||||
|
||||
def force_upgrade(self, packages):
|
||||
"""Force upgrade package to resolve conffile prompts."""
|
||||
if 'roundcube-core' not in packages:
|
||||
return False
|
||||
|
||||
def force_upgrade(helper, packages):
|
||||
"""Force upgrade package to resolve conffile prompts."""
|
||||
if 'roundcube-core' not in packages:
|
||||
return False
|
||||
# Allow roundcube any version to upgrade to any version. This is okay
|
||||
# because there will no longer be conflicting file changes.
|
||||
install(['roundcube-core'], force_configuration='new')
|
||||
if self.get_component('webserver-roundcube').is_enabled():
|
||||
self.get_component('webserver-roundcube-freedombox').enable()
|
||||
|
||||
# Allow roundcube any version to upgrade to any version. This is okay
|
||||
# because there will no longer be conflicting file changes.
|
||||
helper.install(['roundcube-core'], force_configuration='new')
|
||||
if app.get_component('webserver-roundcube').is_enabled():
|
||||
app.get_component('webserver-roundcube-freedombox').enable()
|
||||
|
||||
return True
|
||||
return True
|
||||
|
||||
@ -14,7 +14,7 @@ from plinth.modules.apache.components import Webserver
|
||||
from plinth.modules.backups.components import BackupRestore
|
||||
from plinth.modules.firewall.components import Firewall
|
||||
from plinth.modules.users.components import UsersAndGroups
|
||||
from plinth.package import Packages
|
||||
from plinth.package import Packages, install
|
||||
from plinth.utils import Version, format_lazy
|
||||
|
||||
from . import manifest
|
||||
@ -114,6 +114,20 @@ class TTRSSApp(app_module.App):
|
||||
actions.superuser_run('ttrss', ['setup'])
|
||||
self.enable()
|
||||
|
||||
def force_upgrade(self, packages):
|
||||
"""Force update package to resolve conffile prompts."""
|
||||
if 'tt-rss' not in packages:
|
||||
return False
|
||||
|
||||
# Allow tt-rss any lower version to upgrade to 21.*
|
||||
package = packages['tt-rss']
|
||||
if Version(package['new_version']) > Version('22~'):
|
||||
return False
|
||||
|
||||
install(['tt-rss'], force_configuration='new')
|
||||
actions.superuser_run('ttrss', ['setup'])
|
||||
return True
|
||||
|
||||
|
||||
class TTRSSBackupRestore(BackupRestore):
|
||||
"""Component to backup/restore TT-RSS"""
|
||||
@ -129,21 +143,6 @@ class TTRSSBackupRestore(BackupRestore):
|
||||
actions.superuser_run('ttrss', ['restore-database'])
|
||||
|
||||
|
||||
def force_upgrade(helper, packages):
|
||||
"""Force update package to resolve conffile prompts."""
|
||||
if 'tt-rss' not in packages:
|
||||
return False
|
||||
|
||||
# Allow tt-rss any lower version to upgrade to 21.*
|
||||
package = packages['tt-rss']
|
||||
if Version(package['new_version']) > Version('22~'):
|
||||
return False
|
||||
|
||||
helper.install(['tt-rss'], force_configuration='new')
|
||||
actions.superuser_run('ttrss', ['setup'])
|
||||
return True
|
||||
|
||||
|
||||
def get_domain():
|
||||
"""Read TLS domain from tt-rss config file."""
|
||||
return actions.superuser_run('ttrss', ['get-domain']).strip()
|
||||
|
||||
@ -428,10 +428,9 @@ class ForceUpgrader():
|
||||
need_retry = False
|
||||
for app_id, packages in apps.items():
|
||||
app = app_module.App.get(app_id)
|
||||
module = sys.modules[app.__module__]
|
||||
try:
|
||||
logger.info('Force upgrading app: %s', app.info.name)
|
||||
if module.force_upgrade(module.setup_helper, packages):
|
||||
if self._run_force_upgrade_as_operation(app, packages):
|
||||
logger.info('Successfully force upgraded app: %s',
|
||||
app.info.name)
|
||||
else:
|
||||
@ -445,6 +444,15 @@ class ForceUpgrader():
|
||||
if need_retry:
|
||||
raise self.TemporaryFailure('Some apps failed to force upgrade.')
|
||||
|
||||
def _run_force_upgrade_as_operation(self, app, packages):
|
||||
"""Start an operation for force upgrading."""
|
||||
name = gettext_noop('Updating app packages')
|
||||
operation = operation_module.manager.new(app.app_id, name,
|
||||
app.force_upgrade, [packages],
|
||||
show_message=False,
|
||||
show_notification=False)
|
||||
return operation.join() # Wait for completion, raise Exception
|
||||
|
||||
def _get_list_of_apps_to_force_upgrade(self):
|
||||
"""Return a list of app on which to run force upgrade."""
|
||||
packages = self._get_list_of_upgradable_packages()
|
||||
@ -489,8 +497,7 @@ class ForceUpgrader():
|
||||
package_apps_map = defaultdict(set)
|
||||
upgradable_packages = set()
|
||||
for app in app_module.App.list():
|
||||
module = sys.modules[app.__module__]
|
||||
if not getattr(module, 'force_upgrade', None):
|
||||
if not getattr(app, 'force_upgrade', None):
|
||||
# App does not implement force upgrade
|
||||
continue
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user