From 9021fbea484708df827e41a31daf918e10d4d40c Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Mon, 3 Oct 2022 11:08:00 -0400 Subject: [PATCH] machine: use default password for validation For legacy Raspberry Pi installations attempt to automate the update using the default password. Signed-off-by: Eric Callahan --- moonraker/components/machine.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/moonraker/components/machine.py b/moonraker/components/machine.py index 038461c..8579e0d 100644 --- a/moonraker/components/machine.py +++ b/moonraker/components/machine.py @@ -352,6 +352,10 @@ class Machine: def sudo_password(self) -> Optional[str]: return self._sudo_password + @sudo_password.setter + def sudo_password(self, pwd: Optional[str]) -> None: + self._sudo_password = pwd + @property def sudo_requested(self) -> bool: return len(self.sudo_requests) > 0 @@ -1292,9 +1296,15 @@ class InstallValidator: # A non-default datapath requires successful update of the # service self.data_path_valid = False + user: str = props["User"] + has_sudo = False if await machine.check_sudo_access(): + has_sudo = True logging.info("Moonraker has sudo access") - else: + elif user == "pi" and machine.sudo_password is None: + machine.sudo_password = "raspberry" + has_sudo = await machine.check_sudo_access() + if not has_sudo: self._request_sudo_access() raise ValidationError( "Moonraker requires sudo permission to update the system " @@ -1303,7 +1313,6 @@ class InstallValidator: ) self._sudo_requested = False svc_dest = pathlib.Path(props["FragmentPath"]) - user: str = props["User"] tmp_svc = pathlib.Path( tempfile.gettempdir() ).joinpath(f"{unit}-tmp.svc")