Skip to content

Commit

Permalink
updates.py: use update-system script if available
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Leonard <[email protected]>
  • Loading branch information
antonlacon committed May 19, 2023
1 parent 458469c commit c33a996
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions resources/lib/modules/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand All @@ -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):
Expand Down

0 comments on commit c33a996

Please sign in to comment.