upgrades: Set a flag so interrupted dist-upgrade can be continued

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2020-08-26 12:10:40 -04:00 committed by Sunil Mohan Adapa
parent 0308d783e3
commit bacfc4bcee
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -75,6 +75,9 @@ Pin: release a=buster-backports
Pin-Priority: 500
'''
dist_upgrade_flag = pathlib.Path(
'/var/lib/freedombox/dist-upgrade-in-progress')
def parse_arguments():
"""Return parsed command line arguments as dictionary"""
@ -292,6 +295,11 @@ def _check_and_dist_upgrade(develop=False, test_upgrade=False):
If develop is True, check for possible upgrade from stable to testing.
If test_upgrade is True, also perform the upgrade to testing.
"""
if dist_upgrade_flag.exists():
print('Continuing previously interrupted dist-upgrade.')
_perform_dist_upgrade()
return
release, dist = get_current_release()
if release in ['unstable', 'testing']:
print(f'System release is {release}. Skip checking for new stable '
@ -350,6 +358,13 @@ def _check_and_dist_upgrade(develop=False, test_upgrade=False):
sources_list.write(new_line)
print('Dist upgrade in progress. Setting flag.')
dist_upgrade_flag.touch(mode=0o660)
_perform_dist_upgrade()
def _perform_dist_upgrade():
"""Perform upgrade to next release of Debian."""
run_apt_command(['update'])
run_apt_command(['install', 'base-files'])
run_apt_command(['install', 'unattended-upgrades'])
@ -370,6 +385,10 @@ def _check_and_dist_upgrade(develop=False, test_upgrade=False):
run_apt_command(['autoremove'])
print('Dist upgrade complete. Removing flag.')
if dist_upgrade_flag.exists():
dist_upgrade_flag.unlink()
# FreedomBox Service may have tried to restart several times
# during the upgrade, but failed. It will stop trying after 5
# retries. Restart it once more to ensure it is running.