From 2e95077d7455866da70427503113c09a93b0018c Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Tue, 5 Jan 2021 07:15:17 -0500 Subject: [PATCH] upgrades: Check before starting dist upgrade process Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- actions/upgrades | 67 ++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/actions/upgrades b/actions/upgrades index 1ac39fe8b..e4e87194d 100755 --- a/actions/upgrades +++ b/actions/upgrades @@ -93,8 +93,6 @@ def parse_arguments(): subparsers.add_parser('get-log', help='Print the automatic upgrades log') subparsers.add_parser('setup', help='Setup apt preferences') - subparsers.add_parser('start-dist-upgrade', - help='Start dist upgrade process') activate_backports = subparsers.add_parser( 'activate-backports', help='Activate backports if possible') @@ -102,11 +100,12 @@ def parse_arguments(): action='store_true', help='Development mode') - dist_upgrade = subparsers.add_parser( - 'dist-upgrade', help='Perform dist upgrade if possible') - dist_upgrade.add_argument('--test', required=False, default=False, - action='store_true', - help='Test dist-upgrade from stable to testing') + start_dist_upgrade = subparsers.add_parser( + 'start-dist-upgrade', help='Check and start dist upgrade process') + start_dist_upgrade.add_argument( + '--test', required=False, default=False, action='store_true', + help='Test dist-upgrade from stable to testing') + subparsers.add_parser('dist-upgrade', help='Perform dist upgrade') subparsers.required = True return parser.parse_args() @@ -294,22 +293,21 @@ def _add_apt_preferences(): file_handle.write(APT_PREFERENCES_APPS) -def _check_and_dist_upgrade(test_upgrade=False): +def _check_dist_upgrade(test_upgrade=False): """Check for new stable release. If there is one, and updates are - enabled, perform dist-upgrade. + enabled, return True. - If test_upgrade is True, perform upgrade to testing if possible. + If test_upgrade is True, also check for upgrade to testing. """ if dist_upgrade_flag.exists(): - print('Continuing previously interrupted dist-upgrade.') - _perform_dist_upgrade() - return + print('Found previously interrupted dist-upgrade.') + return True release, dist = get_current_release() if release in ['unstable', 'testing']: print(f'System release is {release}. Skip checking for new stable ' 'release.') - return + return False check_dists = ['stable'] if test_upgrade: @@ -335,27 +333,27 @@ def _check_and_dist_upgrade(test_upgrade=False): if not codename: print('"Codename:" not found in release file.') - return + return False if codename == dist: print(f'{dist} is already the latest release.') - return + return False if not _check_auto(): print('Automatic updates are not enabled.') - return + return False if check_dist == 'testing' and not test_upgrade: print(f'Skipping dist-upgrade to {check_dist} since --test is not ' 'set.') - return + return False output = subprocess.check_output(['df', '--output=avail,pcent', '/']) output = output.decode().split('\n')[1].split() free_space, free_percent = int(output[0]), int(output[1][:-1]) if free_space < 1000000 or free_percent < 10: print('Not enough free space in /.') - return + return False print(f'Upgrading from {dist} to {codename}...') with open(SOURCES_LIST, 'r') as sources_list: @@ -377,7 +375,7 @@ def _check_and_dist_upgrade(test_upgrade=False): print('Dist upgrade in progress. Setting flag.') dist_upgrade_flag.touch(mode=0o660) - _perform_dist_upgrade() + return True def _perform_dist_upgrade(): @@ -452,22 +450,23 @@ def subcommand_activate_backports(arguments): _check_and_backports_sources(arguments.develop) -def subcommand_start_dist_upgrade(_): - """Start dist upgrade process.""" - subprocess.Popen(['systemctl', 'start', 'freedombox-dist-upgrade'], - stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, close_fds=True, - start_new_session=True) - - -def subcommand_dist_upgrade(arguments): - """Perform major distribution upgrade. - - Check if a new stable release is available, and perform dist-upgrade if - updates are enabled. +def subcommand_start_dist_upgrade(arguments): + """Start dist upgrade process. + Check if a new stable release is available, and start dist-upgrade process + if updates are enabled. """ - _check_and_dist_upgrade(arguments.test) + if _check_dist_upgrade(arguments.test): + subprocess.Popen(['systemctl', 'start', 'freedombox-dist-upgrade'], + stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, close_fds=True, + start_new_session=True) + + +def subcommand_dist_upgrade(_): + """Perform major distribution upgrade. + """ + _perform_dist_upgrade() def main():