From c33a9968a0432d0b349f231a2c0526d882bd7d1c Mon Sep 17 00:00:00 2001 From: Ian Leonard Date: Sun, 2 Apr 2023 09:16:06 +0000 Subject: [PATCH] updates.py: use update-system script if available Signed-off-by: Ian Leonard --- resources/lib/modules/updates.py | 41 ++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/resources/lib/modules/updates.py b/resources/lib/modules/updates.py index 89e0cd3cb..519691203 100644 --- a/resources/lib/modules/updates.py +++ b/resources/lib/modules/updates.py @@ -566,22 +566,41 @@ def check_updates_v2(self, force=False): if hasattr(self, 'update_in_progress'): log.log('Update in progress (exit)', log.DEBUG) return - if self.struct['update']['settings']['SubmitStats']['value'] == '1': - systemid = oe.SYSTEMID - else: - systemid = "NOSTATS" - if oe.BUILDER_VERSION: - version = oe.BUILDER_VERSION - else: - version = oe.VERSION + systemid = oe.SYSTEMID if self.struct['update']['settings']['SubmitStats']['value'] == '1' else 'NOSTATS' + version = oe.BUILDER_VERSION if oe.BUILDER_VERSION else oe.VERSION url = f'{self.UPDATE_REQUEST_URL}?i={oe.url_quote(systemid)}&d={oe.url_quote(oe.DISTRIBUTION)}&pa={oe.url_quote(oe.ARCHITECTURE)}&v={oe.url_quote(version)}&f={oe.url_quote(self.hardware_flags)}' if oe.BUILDER_NAME: - url += f'&b={oe.url_quote(oe.BUILDER_NAME)}' + url += f'&b={oe.url_quote(oe.BUILDER_NAME)}' log.log(f'URL: {url}', log.DEBUG) update_json = oe.load_url(url) log.log(f'RESULT: {repr(update_json)}', log.DEBUG) - if update_json: + # use system script if available + if os.path.isfile('/usr/bin/update-system'): + # Discard server response + update_json = None + self.last_update_check = time.time() + update_result = os_tools.execute('/usr/bin/update-system --settingsonly', get_result=True).strip() + if update_result: + log.log(f'update-system result: {update_result}', log.DEBUG) + # Bugfix update found. Notify and automatic update if enabled. + if update_result.startswith('http://') or update_result.startswith('https://'): + log.log(f'Found update: {update_result}', log.INFO) + self.update_file, self.update_checksum = update_result.split(' ') + if self.struct['update']['settings']['UpdateNotify']['value'] == '1': + oe.notify(oe._(32363), oe._(32364)) + if self.struct['update']['settings']['AutoUpdate']['value'] == 'auto' and force == False: + self.update_in_progress = True + self.do_autoupdate(None, True) + # Major update found. Notify if enabled but no automatic update. + elif update_result == 'True': + log.log('Major update found.', log.DEBUG) + if self.struct['update']['settings']['UpdateNotify']['value'] == '1': + oe.notify(oe._(32363), oe._(32364)) + else: + log.log('No update found.', log.DEBUG) + # fallback to server update check + elif update_json: update_json = json.loads(update_json) self.last_update_check = time.time() if 'update' in update_json['data'] and 'folder' in update_json['data']: @@ -592,6 +611,8 @@ def check_updates_v2(self, force=False): if self.struct['update']['settings']['AutoUpdate']['value'] == 'auto' and force == False: self.update_in_progress = True self.do_autoupdate(None, True) + else: + log.log('No system update information found.', log.DEBUG) @log.log_function() def do_autoupdate(self, listItem=None, silent=False):