machine: use sudo password for commands if available
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
272f7b946d
commit
db7474aa88
|
@ -259,19 +259,23 @@ class Machine:
|
||||||
cmds = ["systemctl --version", "ls /lost+found"]
|
cmds = ["systemctl --version", "ls /lost+found"]
|
||||||
shell_cmd: SCMDComp = self.server.lookup_component("shell_command")
|
shell_cmd: SCMDComp = self.server.lookup_component("shell_command")
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
proc_input = None
|
|
||||||
full_cmd = f"sudo {cmd}"
|
|
||||||
if self._sudo_password is not None:
|
|
||||||
proc_input = self._sudo_password
|
|
||||||
full_cmd = f"sudo -S {cmd}"
|
|
||||||
try:
|
try:
|
||||||
ret = await shell_cmd.exec_cmd(
|
await self.exec_sudo_command(cmd)
|
||||||
full_cmd, proc_input=proc_input, log_complete=False
|
|
||||||
)
|
|
||||||
except shell_cmd.error:
|
except shell_cmd.error:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
async def exec_sudo_command(self, command: str) -> str:
|
||||||
|
proc_input = None
|
||||||
|
full_cmd = f"sudo {command}"
|
||||||
|
if self._sudo_password is not None:
|
||||||
|
proc_input = self._sudo_password
|
||||||
|
full_cmd = f"sudo -S {command}"
|
||||||
|
shell_cmd: SCMDComp = self.server.lookup_component("shell_command")
|
||||||
|
return await shell_cmd.exec_cmd(
|
||||||
|
full_cmd, proc_input=proc_input, log_complete=False
|
||||||
|
)
|
||||||
|
|
||||||
def _get_sdcard_info(self) -> Dict[str, Any]:
|
def _get_sdcard_info(self) -> Dict[str, Any]:
|
||||||
sd_info: Dict[str, Any] = {}
|
sd_info: Dict[str, Any] = {}
|
||||||
cid_file = pathlib.Path(SD_CID_PATH)
|
cid_file = pathlib.Path(SD_CID_PATH)
|
||||||
|
@ -576,11 +580,15 @@ class BaseProvider:
|
||||||
async def initialize(self) -> None:
|
async def initialize(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def _exec_sudo_command(self, command: str):
|
||||||
|
machine: Machine = self.server.lookup_component("machine")
|
||||||
|
return await machine.exec_sudo_command(command)
|
||||||
|
|
||||||
async def shutdown(self) -> None:
|
async def shutdown(self) -> None:
|
||||||
await self.shell_cmd.exec_cmd(f"sudo shutdown now")
|
await self._exec_sudo_command(f"shutdown now")
|
||||||
|
|
||||||
async def reboot(self) -> None:
|
async def reboot(self) -> None:
|
||||||
await self.shell_cmd.exec_cmd(f"sudo shutdown -r now")
|
await self._exec_sudo_command(f"shutdown -r now")
|
||||||
|
|
||||||
async def do_service_action(self,
|
async def do_service_action(self,
|
||||||
action: str,
|
action: str,
|
||||||
|
@ -621,8 +629,7 @@ class SystemdCliProvider(BaseProvider):
|
||||||
action: str,
|
action: str,
|
||||||
service_name: str
|
service_name: str
|
||||||
) -> None:
|
) -> None:
|
||||||
await self.shell_cmd.exec_cmd(
|
await self._exec_sudo_command(f"systemctl {action} {service_name}")
|
||||||
f'sudo systemctl {action} {service_name}')
|
|
||||||
|
|
||||||
async def check_virt_status(self) -> Dict[str, Any]:
|
async def check_virt_status(self) -> Dict[str, Any]:
|
||||||
# Fallback virtualization check
|
# Fallback virtualization check
|
||||||
|
|
Loading…
Reference in New Issue