From 738c8ff08a05591b1b1fc67609d7f34fc11b19af Mon Sep 17 00:00:00 2001 From: ralphwetzel Date: Sat, 2 May 2020 18:13:34 +0200 Subject: [PATCH] WIP: Auto-Update --- theonionpack/top/pack.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/theonionpack/top/pack.py b/theonionpack/top/pack.py index 7377437..5b0f96e 100644 --- a/theonionpack/top/pack.py +++ b/theonionpack/top/pack.py @@ -274,7 +274,7 @@ def check_update(self, mode: Optional[str] = None) -> bool: if mode == 'auto': self.update_status = 4 # Update found, trying to run auto-update - if self.get_latest_pack(): + if self.launch_latest_theonionpack(): sleep(2) self.do_quit() else: @@ -344,27 +344,36 @@ def version(self): return None - def get_latest_pack(self): + def launch_latest_theonionpack(self): url = self.get_updater_url() - if url is not None: + if url is None: + return False + + file = tempfile.NamedTemporaryFile(suffix='.exe', delete=False) + + r = requests.get(url, stream=True) + for chunk in r.iter_content(chunk_size=512): + if chunk: # filter out keep-alive new chunks + file.write(chunk) + + file.close() + + params = [file.name] - file = tempfile.NamedTemporaryFile(suffix='.exe', delete=False) + # Be sure to run the installer in our working directory! + # This is especially demanded as we are going to uninstall previous versions! + params.append(f'/DIR="{os.getcwd()}"') - r = requests.get(url, stream=True) - for chunk in r.iter_content(chunk_size=512): - if chunk: # filter out keep-alive new chunks - file.write(chunk) + params.append('/RunUninstall') - file.close() + params.append('/SILENT') + # params.append('/VERYSILENT') + params.append('/LOG') + params.append('/SUPPRESSMSGBOXES') - params = [file.name] - params.append('/SILENT') - # params.append('/VERYSILENT') - params.append('/LOG') - params.append('/SUPPRESSMSGBOXES') - params.append('/TASKS="startup,obfs4proxy"') + with contextlib.suppress(Exception): subprocess.Popen(params, close_fds=True, creationflags=subprocess.DETACHED_PROCESS + subprocess.CREATE_NEW_PROCESS_GROUP) return True