diff --git a/codexctl/device.py b/codexctl/device.py index 4cd75b0..74464c7 100644 --- a/codexctl/device.py +++ b/codexctl/device.py @@ -679,8 +679,6 @@ def install_sw_update(self, version_file: str, bootloader_files: dict[str, bytes SystemExit: If there was an error installing the update """ - command = f'/usr/bin/swupdate -v -i VERSION_FILE -k /usr/share/swupdate/swupdate-payload-key-pub.pem -H "{self.hardware.swupdate_hw}:1.0" -e "stable,copy1"' - if self.client: ftp_client = self.client.open_sftp() @@ -693,25 +691,15 @@ def install_sw_update(self, version_file: str, bootloader_files: dict[str, bytes print("\nDone! Running swupdate (PLEASE BE PATIENT, ~5 MINUTES)") - command = command.replace("VERSION_FILE", out_location) - - for num in (1, 2): - command = command.replace( - "stable,copy1", f"stable,copy{num}" - ) # terrible hack but it works - self.logger.debug(command) - _stdin, stdout, _stderr = self.client.exec_command(command) - - self.logger.debug(f"Stdout of swupdate checking: {stdout.readlines()}") + command = f"/usr/sbin/swupdate-from-image-file {out_location}" + self.logger.debug(command) + _stdin, stdout, _stderr = self.client.exec_command(command) - exit_status = stdout.channel.recv_exit_status() + exit_status = stdout.channel.recv_exit_status() - if exit_status != 0: - if "over our current root" in "".join(_stderr.readlines()): - continue - else: - print("".join(_stderr.readlines())) - raise SystemError("Update failed!") + if exit_status != 0: + print("".join(_stderr.readlines())) + raise SystemError("Update failed!") if bootloader_files: print("\nApplying bootloader update...") @@ -749,34 +737,20 @@ def install_sw_update(self, version_file: str, bootloader_files: dict[str, bytes else: print("Running swupdate") - command = command.replace("VERSION_FILE", version_file) + command = ["/usr/sbin/swupdate-from-image-file", version_file] + self.logger.debug(command) - for num in (1, 2): - command = command.replace( - "stable,copy1", f"stable,copy{num}" - ) # terrible hack but it works - self.logger.debug(command) - - with subprocess.Popen( + try: + output = subprocess.check_output( command, + stderr=subprocess.STDOUT, text=True, - shell=True, # Being lazy... - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - env={"PATH": "/bin:/usr/bin:/sbin"}, - ) as process: - if process.wait() != 0: - if "installing over our current root" in "".join( - process.stderr.readlines() - ): - continue - else: - print("".join(process.stderr.readlines())) - raise SystemError("Update failed") - - self.logger.debug( - f"Stdout of update checking service is {''.join(process.stdout.readlines())}" - ) + env={"PATH": "/bin:/usr/bin:/sbin:/usr/sbin"}, + ) + self.logger.debug(f"Stdout of swupdate: {output}") + except subprocess.CalledProcessError as e: + print(e.output) + raise SystemError("Update failed") print("Update complete and device rebooting") os.system("reboot")