Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 18 additions & 44 deletions codexctl/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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...")
Expand Down Expand Up @@ -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")
Expand Down
Loading