Skip to content

Commit 6204258

Browse files
authored
Merge pull request #157 from rmitchellscott/simplify-swu-install
simplify swupdate install to fix partition switching on 3.22+
2 parents a8dc990 + a9f986f commit 6204258

1 file changed

Lines changed: 18 additions & 44 deletions

File tree

codexctl/device.py

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,6 @@ def install_sw_update(self, version_file: str, bootloader_files: dict[str, bytes
679679
SystemExit: If there was an error installing the update
680680
681681
"""
682-
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"'
683-
684682
if self.client:
685683
ftp_client = self.client.open_sftp()
686684

@@ -693,25 +691,15 @@ def install_sw_update(self, version_file: str, bootloader_files: dict[str, bytes
693691

694692
print("\nDone! Running swupdate (PLEASE BE PATIENT, ~5 MINUTES)")
695693

696-
command = command.replace("VERSION_FILE", out_location)
697-
698-
for num in (1, 2):
699-
command = command.replace(
700-
"stable,copy1", f"stable,copy{num}"
701-
) # terrible hack but it works
702-
self.logger.debug(command)
703-
_stdin, stdout, _stderr = self.client.exec_command(command)
704-
705-
self.logger.debug(f"Stdout of swupdate checking: {stdout.readlines()}")
694+
command = f"/usr/sbin/swupdate-from-image-file {out_location}"
695+
self.logger.debug(command)
696+
_stdin, stdout, _stderr = self.client.exec_command(command)
706697

707-
exit_status = stdout.channel.recv_exit_status()
698+
exit_status = stdout.channel.recv_exit_status()
708699

709-
if exit_status != 0:
710-
if "over our current root" in "".join(_stderr.readlines()):
711-
continue
712-
else:
713-
print("".join(_stderr.readlines()))
714-
raise SystemError("Update failed!")
700+
if exit_status != 0:
701+
print("".join(_stderr.readlines()))
702+
raise SystemError("Update failed!")
715703

716704
if bootloader_files:
717705
print("\nApplying bootloader update...")
@@ -749,34 +737,20 @@ def install_sw_update(self, version_file: str, bootloader_files: dict[str, bytes
749737

750738
else:
751739
print("Running swupdate")
752-
command = command.replace("VERSION_FILE", version_file)
740+
command = ["/usr/sbin/swupdate-from-image-file", version_file]
741+
self.logger.debug(command)
753742

754-
for num in (1, 2):
755-
command = command.replace(
756-
"stable,copy1", f"stable,copy{num}"
757-
) # terrible hack but it works
758-
self.logger.debug(command)
759-
760-
with subprocess.Popen(
743+
try:
744+
output = subprocess.check_output(
761745
command,
746+
stderr=subprocess.STDOUT,
762747
text=True,
763-
shell=True, # Being lazy...
764-
stdout=subprocess.PIPE,
765-
stderr=subprocess.PIPE,
766-
env={"PATH": "/bin:/usr/bin:/sbin"},
767-
) as process:
768-
if process.wait() != 0:
769-
if "installing over our current root" in "".join(
770-
process.stderr.readlines()
771-
):
772-
continue
773-
else:
774-
print("".join(process.stderr.readlines()))
775-
raise SystemError("Update failed")
776-
777-
self.logger.debug(
778-
f"Stdout of update checking service is {''.join(process.stdout.readlines())}"
779-
)
748+
env={"PATH": "/bin:/usr/bin:/sbin:/usr/sbin"},
749+
)
750+
self.logger.debug(f"Stdout of swupdate: {output}")
751+
except subprocess.CalledProcessError as e:
752+
print(e.output)
753+
raise SystemError("Update failed")
780754

781755
print("Update complete and device rebooting")
782756
os.system("reboot")

0 commit comments

Comments
 (0)