From ddeefa037d6d69ef12d938d77e43153771479282 Mon Sep 17 00:00:00 2001 From: Simone Margaritelli <evilsocket@gmail.com> Date: Sun, 20 Oct 2019 19:27:31 +0200 Subject: [PATCH] misc: small fix or general refactoring i did not bother commenting --- pwnagotchi/plugins/default/auto-update.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pwnagotchi/plugins/default/auto-update.py b/pwnagotchi/plugins/default/auto-update.py index 6580377..7c04506 100644 --- a/pwnagotchi/plugins/default/auto-update.py +++ b/pwnagotchi/plugins/default/auto-update.py @@ -36,13 +36,13 @@ def check(version, repo, native=True): 'available': None, 'url': None, 'native': native, + 'arch': platform.machine() } resp = requests.get("https://api.github.com/repos/%s/releases/latest" % repo) latest = resp.json() - info['available'] = latest_ver = latest['tag_name'].replace('v', ' ') - arch = platform.machine() - is_arm = arch.startswith('arm') + info['available'] = latest_ver = latest['tag_name'].replace('v', '') + is_arm = info['arch'].startswith('arm') if latest_ver != info['current']: if not native: @@ -61,11 +61,12 @@ def check(version, repo, native=True): def install(display, update): name = update['repo'].split('/')[1] - display.set('status', 'Updating %s ...' % name) + display.set('status', 'Downloading %s ...' % name) display.update(force=True) - path = os.path.join("/tmp/updates/%s_%s" % (name, update['available'])) + path = os.path.join("/tmp/updates/", name) if os.path.exists(path): + logging.debug("[update] deleting %s" % path) shutil.rmtree(path, ignore_errors=True, onerror=None) os.makedirs(path) @@ -77,6 +78,15 @@ def install(display, update): os.system('wget -q "%s" -O "%s"' % (update['url'], target_path)) + logging.info("[update] extracting %s to %s ..." % (target_path, path)) + + display.set('status', 'Extracting %s ...' % name) + display.update(force=True) + + os.system('unzip "%s" -d "%s"' % (target_path, path)) + + logging.info("TODO") + def on_internet_available(agent): global STATUS