Skip to content

Commit 811cf33

Browse files
authored
install.sh: Allow installing directly onto a remote host (#2183)
Updates #1729 To fully close that issue see the various TODOs.
1 parent 64a6a46 commit 811cf33

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

install.sh

+48-4
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,28 @@ usage() {
1717
Installs code-server for Linux, macOS and FreeBSD.
1818
It tries to use the system package manager if possible.
1919
After successful installation it explains how to start using code-server.
20+
21+
Pass in user@host to install code-server on user@host over ssh.
22+
The remote host must have internet access.
2023
${not_curl_usage-}
2124
Usage:
2225
23-
$arg0 [--dry-run] [--version X.X.X] [--method detect] [--prefix ~/.local]
26+
$arg0 [--dry-run] [--version X.X.X] [--method detect] \
27+
[--prefix ~/.local] [user@host]
2428
2529
--dry-run
2630
Echo the commands for the install process without running them.
31+
2732
--version X.X.X
2833
Install a specific version instead of the latest.
34+
2935
--method [detect | standalone]
3036
Choose the installation method. Defaults to detect.
3137
- detect detects the system package manager and tries to use it.
3238
Full reference on the process is further below.
3339
- standalone installs a standalone release archive into ~/.local
3440
Add ~/.local/bin to your \$PATH to use it.
41+
3542
--prefix <dir>
3643
Sets the prefix used by standalone release archives. Defaults to ~/.local
3744
The release is unarchived into ~/.local/lib/code-server-X.X.X
@@ -100,9 +107,18 @@ main() {
100107
METHOD \
101108
STANDALONE_INSTALL_PREFIX \
102109
VERSION \
103-
OPTIONAL
110+
OPTIONAL \
111+
ALL_FLAGS \
112+
SSH_ARGS
104113

114+
ALL_FLAGS=""
105115
while [ "$#" -gt 0 ]; do
116+
case "$1" in
117+
-*)
118+
ALL_FLAGS="${ALL_FLAGS} $1"
119+
;;
120+
esac
121+
106122
case "$1" in
107123
--dry-run)
108124
DRY_RUN=1
@@ -132,16 +148,33 @@ main() {
132148
usage
133149
exit 0
134150
;;
135-
*)
151+
--)
152+
shift
153+
# We remove the -- added above.
154+
ALL_FLAGS="${ALL_FLAGS% --}"
155+
SSH_ARGS="$*"
156+
break
157+
;;
158+
-*)
136159
echoerr "Unknown flag $1"
137160
echoerr "Run with --help to see usage."
138161
exit 1
139162
;;
163+
*)
164+
SSH_ARGS="$*"
165+
break
166+
;;
140167
esac
141168

142169
shift
143170
done
144171

172+
if [ "${SSH_ARGS-}" ]; then
173+
echoh "Installing remotely with ssh $SSH_ARGS"
174+
curl -fsSL https://code-server.dev/install.sh | prefix "$SSH_ARGS" ssh "$SSH_ARGS" sh -s -- "$ALL_FLAGS"
175+
return
176+
fi
177+
145178
VERSION="${VERSION-$(echo_latest_version)}"
146179
METHOD="${METHOD-detect}"
147180
if [ "$METHOD" != detect ] && [ "$METHOD" != standalone ]; then
@@ -446,7 +479,7 @@ arch() {
446479
}
447480

448481
command_exists() {
449-
command -v "$@" > /dev/null 2>&1
482+
command -v "$@" > /dev/null
450483
}
451484

452485
sh_c() {
@@ -500,4 +533,15 @@ humanpath() {
500533
sed "s# $HOME# ~#g; s#\"$HOME#\"\$HOME#g"
501534
}
502535

536+
# We need to make sure we exit with a non zero exit if the command fails.
537+
# /bin/sh does not support -o pipefail unfortunately.
538+
prefix() {
539+
PREFIX="$1"
540+
shift
541+
fifo="$(mktemp -d)/fifo"
542+
mkfifo "$fifo"
543+
sed -e "s#^#$PREFIX: #" "$fifo" &
544+
"$@" > "$fifo" 2>&1
545+
}
546+
503547
main "$@"

0 commit comments

Comments
 (0)