shell: add quote command

This commit is contained in:
tv 2017-07-23 01:03:53 +02:00
parent 4b894507b2
commit dc0ca967cb

View File

@ -67,6 +67,18 @@ let
exec ${pkgs.jq}/bin/jq -enrf "$script" --arg target "$1" \ exec ${pkgs.jq}/bin/jq -enrf "$script" --arg target "$1" \
''; '';
# usage: quote [ARGS...]
cmds.quote = pkgs.writeDash "cmds.quote" ''
set -efu
prefix=
for x; do
y=$(${pkgs.jq}/bin/jq -nr --arg x "$x" '$x | @sh "\(.)"')
echo -n "$prefix$y"
prefix=' '
done
echo
'';
init.args = pkgs.writeText "init.args" /* sh */ '' init.args = pkgs.writeText "init.args" /* sh */ ''
args=$(${pkgs.utillinux}/bin/getopt -n "$command" -s sh \ args=$(${pkgs.utillinux}/bin/getopt -n "$command" -s sh \
-o s:t:u: \ -o s:t:u: \
@ -117,21 +129,17 @@ let
''; '';
proxy = pkgs.writeDash "init.env.proxy" '' proxy = pkgs.writeDash "init.env.proxy" ''
set -efu set -efu
q() {
${pkgs.jq}/bin/jq -nr --arg x "$*" '$x | @sh "\(.)"'
}
exec ${pkgs.openssh}/bin/ssh \ exec ${pkgs.openssh}/bin/ssh \
"$target_user@$target_host" -p "$target_port" \ "$target_user@$target_host" -p "$target_port" \
cd "$target_path/stockholm" \; \ cd "$target_path/stockholm" \; \
NIX_PATH=$(q "$target_path") \ NIX_PATH=$(quote "$target_path") \
STOCKHOLM_VERSION=$STOCKHOLM_VERSION \ STOCKHOLM_VERSION=$(quote "$STOCKHOLM_VERSION") \
nix-shell \ nix-shell --run "$(quote "
--run $(q \ system=$(quote "$system") \
system=$system \ target=$(quote "$target") \
target=$target \ using_proxy=true \
using_proxy=true \ $(quote "$@")
"$*" ")"
)
''; '';
}; };