upgrades: Check before starting dist upgrade process

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2021-01-05 07:15:17 -05:00 committed by Sunil Mohan Adapa
parent a66520f3ff
commit 2e95077d74
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -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():