1
0
Fork 0
mirror of https://cgit.krebsco.de/krops synced 2024-11-26 21:19:47 +01:00

Merge pull request #7 from nyantec/feature/sudo

ssh, rsync: support using sudo on remote
This commit is contained in:
tv 2019-11-29 13:20:21 +01:00 committed by GitHub
commit 8de797dae0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View file

@ -46,12 +46,13 @@ let {
default = defVal: val: if val != null then val else defVal;
parse = lib.match "(([^@]+)@)?(([^:/]+))?(:([^/]+))?(/.*)?" s;
elemAt' = xs: i: if lib.length xs > i then lib.elemAt xs i else null;
in {
in if lib.isString s then {
user = default (lib.getEnv "LOGNAME") (elemAt' parse 1);
host = default (lib.maybeEnv "HOSTNAME" lib.getHostName) (elemAt' parse 3);
port = default "22" /* "ssh"? */ (elemAt' parse 5);
path = default "/var/src" /* no default? */ (elemAt' parse 6);
};
sudo = false;
} else s;
shell = let
isSafeChar = lib.testString "[-+./0-9:=A-Z_a-z]";

View file

@ -26,7 +26,7 @@ in
"-p" target.port
"-t"
target.host
command
(if target.sudo then command else "sudo ${command}")
];
};

View file

@ -157,6 +157,7 @@ let
fi
${rsync}/bin/rsync \
${optionalString (config.useChecksum or false) /* sh */ "--checksum"} \
${optionalString target.sudo /* sh */ "--rsync-path=\"sudo rsync\""} \
-e ${quote (ssh' target)} \
-vFrlptD \
--delete-excluded \
@ -172,7 +173,10 @@ let
shell' = target: script:
if isLocalTarget target
then script
else /* sh */ ''
else
if target.sudo then /* sh */ ''
${ssh' target} ${quote target.host} ${quote "sudo bash -c ${quote script}"}
'' else ''
${ssh' target} ${quote target.host} ${quote script}
'';