@@ -11,6 +11,7 @@ buildArgs=(
11
11
)
12
12
profile=/nix/var/nix/profiles/system
13
13
# will be set later
14
+ controlPath=
14
15
sshOpts=(
15
16
-o " ControlMaster=auto"
16
17
-o " ControlPersist=60"
@@ -31,7 +32,7 @@ outPath="$2"
31
32
targetHost=" $3 "
32
33
targetPort=" $4 "
33
34
buildOnTarget=" $5 "
34
- sshPrivateKey =" $6 "
35
+ sshPrivateKeyFile =" $6 "
35
36
action=" $7 "
36
37
shift 7
37
38
@@ -41,13 +42,8 @@ buildArgs+=("$@")
41
42
42
43
sshOpts+=( -p " ${targetPort} " )
43
44
44
- workDir=$( mktemp -d)
45
- trap ' rm -rf "$workDir"' EXIT
46
-
47
- if [[ -n " ${sshPrivateKey} " ]]; then
48
- sshPrivateKeyFile=" $workDir /ssh_key"
49
- echo " $sshPrivateKey " > " $sshPrivateKeyFile "
50
- sshOpts+=( -o " IdentityFile=${sshPrivateKeyFile} " )
45
+ if [[ -n " ${sshPrivateKeyFile} " && " ${sshPrivateKeyFile} " != " -" ]]; then
46
+ sshOpts+=( -o " IdentityFile=${sshPrivateKeyFile} " )
51
47
fi
52
48
53
49
# ## Functions ###
@@ -66,17 +62,16 @@ targetHostCmd() {
66
62
# `ssh` did not properly maintain the array nature of the command line,
67
63
# erroneously splitting arguments with internal spaces, even when using `--`.
68
64
# Tested with OpenSSH_7.9p1.
69
- #
70
- # shellcheck disable=SC2029
71
65
ssh " ${sshOpts[@]} " " $targetHost " " ./maybe-sudo.sh ${*@ Q} "
72
66
}
73
67
74
68
# Setup a temporary ControlPath for this session. This speeds-up the
75
69
# operations by not re-creating SSH sessions between each command. At the end
76
70
# of the run, the session is forcefully terminated.
77
71
setupControlPath () {
72
+ controlPath=$( mktemp)
78
73
sshOpts+=(
79
- -o " ControlPath=$workDir /ssh_control "
74
+ -o " ControlPath=$controlPath "
80
75
)
81
76
cleanupControlPath () {
82
77
local ret=$?
@@ -85,7 +80,7 @@ setupControlPath() {
85
80
# Close ssh multiplex-master process gracefully
86
81
log " closing persistent ssh-connection"
87
82
ssh " ${sshOpts[@]} " -O stop " $targetHost "
88
- rm -rf " $workDir "
83
+ rm -f " $controlPath "
89
84
exit " $ret "
90
85
}
91
86
trap cleanupControlPath EXIT
0 commit comments