Skip to content

Commit 2df6360

Browse files
committed
updates: use standalone python module for client side update check
Import /usr/bin/update-system and use it for the system's automated update check. If there is no such script, it uses the server side check. Add an on/off toggle in the GUI with the default set to off. Signed-off-by: Ian Leonard <antonlacon@gmail.com>
1 parent 42dfc4b commit 2df6360

1 file changed

Lines changed: 55 additions & 7 deletions

File tree

resources/lib/modules/updates.py

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
import oe
2222
import os_tools
2323

24+
if os.path.isfile('/usr/bin/update-system'):
25+
update_system = os_tools.import_from_file('update_system', '/usr/bin/update-system')
26+
else:
27+
log.log('No client side update script found; feature will be disabled', log.DEBUG)
28+
2429

2530
class updates(modules.Module):
2631

@@ -55,7 +60,7 @@ class updates(modules.Module):
5560
'action': 'set_custom_channel',
5661
'type': 'text',
5762
'parent': {
58-
'entry': 'ReleaseChannel',
63+
'entry': 'ReleaseChannel',
5964
'value': ['custom'],
6065
},
6166
'InfoText': 762,
@@ -69,38 +74,46 @@ class updates(modules.Module):
6974
'InfoText': 714,
7075
'order': 3,
7176
},
77+
'ClientSideUpdate': {
78+
'name': 32016,
79+
'value': '0',
80+
'action': 'set_value',
81+
'type': 'bool',
82+
'InfoText': 717,
83+
'order': 4,
84+
},
7285
'Channel': {
7386
'name': 32015,
7487
'value': '',
7588
'action': 'set_channel',
7689
'type': 'multivalue',
7790
'values': [],
7891
'InfoText': 760,
79-
'order': 4,
92+
'order': 5,
8093
},
8194
'Build': {
8295
'name': 32020,
8396
'value': '',
8497
'action': 'do_manual_update',
8598
'type': 'button',
8699
'InfoText': 770,
87-
'order': 5,
100+
'order': 6,
88101
},
89102
'UpdateNotify': {
90103
'name': 32365,
91104
'value': '1',
92105
'action': 'set_value',
93106
'type': 'bool',
94107
'InfoText': 715,
95-
'order': 6,
108+
'order': 7,
96109
},
97110
'SubmitStats': {
98111
'name': 32021,
99112
'value': '1',
100113
'action': 'set_value',
101114
'type': 'bool',
102115
'InfoText': 772,
103-
'order': 7,
116+
'order': 8,
104117
},
105118
},
106119
},
@@ -135,6 +148,7 @@ def __init__(self, oeMain):
135148
self.is_service = False
136149
self.last_update_check = 0
137150
self.update_file = None
151+
self.update_checksum = None
138152
self.update_in_progress = False
139153
self.update_json = None
140154
self.update_thread = None
@@ -250,6 +264,15 @@ def load_values(self):
250264
if os.path.isfile(f'{self.LOCAL_UPDATE_DIR}/SYSTEM'):
251265
self.update_in_progress = True
252266

267+
# Client Side Update
268+
if not os.path.isfile('/usr/bin/update-system'):
269+
self.struct['update']['settings']['ClientSideUpdate']['value'] = '0'
270+
self.struct['update']['settings']['ClientSideUpdate']['hidden'] = 'true'
271+
else:
272+
value = oe.read_setting('updates', 'ClientSideUpdate')
273+
if value:
274+
self.struct['update']['settings']['ClientSideUpdate']['value'] = value
275+
253276
# Manual Update
254277
value = oe.read_setting('updates', 'Channel')
255278
if value:
@@ -301,6 +324,9 @@ def set_release_channel(self, listItem):
301324
# Automatic update only on stable releases
302325
if 'hidden' in self.struct['update']['settings']['AutoUpdate']:
303326
del(self.struct['update']['settings']['AutoUpdate']['hidden'])
327+
# Client side update only available on stable channel
328+
if 'hidden' in self.struct['update']['settings']['ClientSideUpdate'] and os.path.isfile('/usr/bin/update-system'):
329+
del(self.struct['update']['settings']['ClientSideUpdate']['hidden'])
304330
# Only show manual update options if automatic update disabled
305331
if self.struct['update']['settings']['AutoUpdate']['value'] == '0':
306332
if 'hidden' in self.struct['update']['settings']['Channel']:
@@ -311,8 +337,9 @@ def set_release_channel(self, listItem):
311337
self.struct['update']['settings']['Channel']['hidden'] = 'true'
312338
self.struct['update']['settings']['Build']['hidden'] = 'true'
313339
else:
314-
# Hide automatic update and show manual update options
340+
# Hide automatic update and client side update, while showing manual update options
315341
self.struct['update']['settings']['AutoUpdate']['hidden'] = 'true'
342+
self.struct['update']['settings']['ClientSideUpdate']['hidden'] = 'true'
316343
if 'hidden' in self.struct['update']['settings']['Channel']:
317344
del(self.struct['update']['settings']['Channel']['hidden'])
318345
if 'hidden' in self.struct['update']['settings']['Build']:
@@ -566,7 +593,28 @@ def check_updates_v2(self, force=False):
566593
if self.struct['update']['settings']['ReleaseChannel']['value'] != 'stable':
567594
log.log('Not on stable release channel (exit)', log.DEBUG)
568595
return
569-
if update_json:
596+
if os.path.isfile('/usr/bin/update-system') and \
597+
self.struct['update']['settings']['ClientSideUpdate']['value'] == '1':
598+
# Discard server response
599+
update_json = None
600+
self.last_update_check = time.time()
601+
client_update_check = update_system.UpdateSystem()
602+
update_available, update_major, update_url, update_checksum = client_update_check.check_for_update()
603+
if update_available:
604+
if update_url:
605+
log.log(f'Found update: {update_url}', log.INFO)
606+
self.update_file = update_url
607+
if update_checksum:
608+
log.log(f'JSON update checksum: {update_checksum}', log.DEBUG)
609+
self.update_checksum = update_checksum
610+
# On screen notification
611+
if self.struct['update']['settings']['UpdateNotify']['value'] == '1':
612+
oe.notify(oe._(32363), oe._(32364))
613+
# Automatic update if enabled and not a major release
614+
if not update_major and (self.struct['update']['settings']['AutoUpdate']['value'] == '1' and force is False):
615+
self.update_in_progress = True
616+
self.do_autoupdate(True)
617+
elif update_json:
570618
update_json = json.loads(update_json)
571619
self.last_update_check = time.time()
572620
if 'update' in update_json['data'] and 'folder' in update_json['data']:

0 commit comments

Comments
 (0)