|
97 | 97 | installOnHost = pkgs.writeShellScriptBin "microvm-install-on-host" ''
|
98 | 98 | set -eou pipefail
|
99 | 99 |
|
| 100 | + USAGE="Usage: $0 root@<host> [--use-remote-sudo]" |
| 101 | +
|
100 | 102 | HOST="$1"
|
101 | 103 | if [[ -z "$HOST" ]]; then
|
102 |
| - echo "Usage: $0 root@<host>" |
| 104 | + echo $USAGE |
103 | 105 | exit 1
|
104 | 106 | fi
|
105 | 107 | shift
|
| 108 | + SSH_CMD="bash" |
| 109 | + if [ $# -gt 0 ]; then |
| 110 | + if [ "$1" == "--use-remote-sudo" ]; then |
| 111 | + SSH_CMD="sudo bash" |
| 112 | + shift |
| 113 | + else |
| 114 | + echo "$USAGE" |
| 115 | + exit 1 |
| 116 | + fi |
| 117 | + fi |
| 118 | +
|
106 | 119 |
|
107 | 120 | echo "Copying derivations to $HOST"
|
108 | 121 | nix copy --no-check-sigs --to "ssh-ng://$HOST" \
|
109 | 122 | --derivation \
|
110 | 123 | "${paths.closureInfoDrv}^out" \
|
111 | 124 | "${paths.runnerDrv}^out"
|
112 | 125 |
|
113 |
| - ssh "$HOST" -- bash -e <<__SSH__ |
| 126 | + ssh "$HOST" -- $SSH_CMD -e <<__SSH__ |
114 | 127 | set -eou pipefail
|
115 | 128 |
|
116 | 129 | echo "Initializing MicroVM ${hostName} if necessary"
|
|
160 | 173 | pkgs.writeShellScriptBin "microvm-switch" ''
|
161 | 174 | set -eou pipefail
|
162 | 175 |
|
| 176 | + USAGE="Usage: $0 root@<target> [--use-remote-sudo]" |
| 177 | +
|
163 | 178 | TARGET="$1"
|
164 | 179 | if [[ -z "$TARGET" ]]; then
|
165 |
| - echo "Usage: $0 root@<target>" |
| 180 | + echo "$USAGE" |
166 | 181 | exit 1
|
167 | 182 | fi
|
168 | 183 | shift
|
| 184 | + SSH_CMD="bash" |
| 185 | + if [ $# -gt 0 ]; then |
| 186 | + if [ "$1" == "--use-remote-sudo" ]; then |
| 187 | + SSH_CMD="sudo bash" |
| 188 | + shift |
| 189 | + else |
| 190 | + echo "$USAGE" |
| 191 | + exit 1 |
| 192 | + fi |
| 193 | + fi |
169 | 194 |
|
170 |
| - ssh "$TARGET" bash -e <<__SSH__ |
| 195 | + ssh "$TARGET" $SSH_CMD -e <<__SSH__ |
171 | 196 | set -eou pipefail
|
172 | 197 |
|
173 | 198 | hostname=\$(cat /etc/hostname)
|
|
193 | 218 | shift
|
194 | 219 | TARGET="$1"
|
195 | 220 | shift
|
196 |
| - if [[ -z "$HOST" || -z "$TARGET" ]]; then |
197 |
| - echo "Usage: $0 root@<host> root@<target> switch" |
| 221 | + OPTS="$@" |
| 222 | + if [ $# -gt 0 ]; then |
| 223 | + if [ "$1" == "--use-remote-sudo" ]; then |
| 224 | + OPTS="$1" |
| 225 | + shift |
| 226 | + fi |
| 227 | + fi |
| 228 | + if [[ -z "$HOST" || -z "$TARGET" || $# -gt 0 ]]; then |
| 229 | + echo "Usage: $0 root@<host> root@<target> [--use-remote-sudo] switch" |
198 | 230 | exit 1
|
199 | 231 | fi
|
200 | 232 |
|
201 |
| - ${lib.getExe installOnHost} "$HOST" |
| 233 | + ${lib.getExe installOnHost} "$HOST" $OPTS |
202 | 234 | ${if canSwitchViaSsh
|
203 |
| - then ''${lib.getExe sshSwitch} "$TARGET"'' |
| 235 | + then ''${lib.getExe sshSwitch} "$TARGET" $OPTS'' |
204 | 236 | else ''ssh "$HOST" -- systemctl restart "microvm@${hostName}.service"''
|
205 | 237 | }
|
206 | 238 | '';
|
|
0 commit comments