clan_cli: fix support for non-root deployment user

This commit is contained in:
RTUnreal
2025-03-25 22:40:02 +01:00
committed by Qubasa
parent 48fa29afad
commit 0ea9b45838
2 changed files with 14 additions and 30 deletions

View File

@@ -185,6 +185,7 @@ def deploy_machines(machines: list[Machine]) -> None:
test_cmd, test_cmd,
RunOpts(msg_color=MsgColor(stderr=AnsiColor.DEFAULT)), RunOpts(msg_color=MsgColor(stderr=AnsiColor.DEFAULT)),
extra_env=env, extra_env=env,
become_root=True,
) )
# retry nixos-rebuild switch if the first attempt failed # retry nixos-rebuild switch if the first attempt failed
@@ -193,6 +194,7 @@ def deploy_machines(machines: list[Machine]) -> None:
switch_cmd, switch_cmd,
RunOpts(msg_color=MsgColor(stderr=AnsiColor.DEFAULT)), RunOpts(msg_color=MsgColor(stderr=AnsiColor.DEFAULT)),
extra_env=env, extra_env=env,
become_root=True,
) )
with AsyncRuntime() as runtime: with AsyncRuntime() as runtime:

View File

@@ -55,44 +55,26 @@ def upload(
with local_src.open("rb") as f: with local_src.open("rb") as f:
tar.addfile(tarinfo, f) tar.addfile(tarinfo, f)
priviledge_escalation = []
if host.user != "root":
priviledge_escalation = ["sudo", "--"]
if local_src.is_dir(): if local_src.is_dir():
cmd = [ cmd = [
*host.ssh_cmd(), *host.ssh_cmd(),
"rm", "--",
"-r", *priviledge_escalation,
str(remote_dest), "bash", "-c", "exec \"$@\"", "--",
";", f"rm -r {remote_dest!s} ; mkdir -m {dir_mode:o} -p {str(remote_dest)} && tar -C {str(remote_dest)} -xzf -",
"mkdir",
"-m",
f"{dir_mode:o}",
"-p",
str(remote_dest),
"&&",
"tar",
"-C",
str(remote_dest),
"-xzf",
"-",
] ]
else: else:
# For single file, extract to parent directory and ensure correct name # For single file, extract to parent directory and ensure correct name
cmd = [ cmd = [
*host.ssh_cmd(), *host.ssh_cmd(),
"rm", "--",
"-f", *priviledge_escalation,
str(remote_dest), "bash", "-c", "exec \"$@\"", "--",
";", f"rm -f {str(remote_dest)} ; mkdir -m {dir_mode:o} -p {str(remote_dest.parent)} && tar -C {str(remote_dest.parent)} -xzf -",
"mkdir",
"-m",
f"{dir_mode:o}",
"-p",
str(remote_dest.parent),
"&&",
"tar",
"-C",
str(remote_dest.parent),
"-xzf",
"-",
] ]
# TODO accept `input` to be an IO object instead of bytes so that we don't have to read the tarfile into memory. # TODO accept `input` to be an IO object instead of bytes so that we don't have to read the tarfile into memory.