77usage () {
88 arg0=" $0 "
99 if [ " $0 " = sh ]; then
10- arg0=" curl -fsSL https://code-server.dev/install.sh | sh -s --"
10+ arg0=" curl -fsSL https://code-server.dev/install.sh | sh -s -- [user@host] "
1111 else
1212 not_curl_usage=" The latest script is available at https://code-server.dev/install.sh
1313"
@@ -20,7 +20,7 @@ After successful installation it explains how to start using code-server.
2020${not_curl_usage-}
2121Usage:
2222
23- $arg0 [--dry-run] [--version X.X.X] [--method detect] [--prefix ~/.local]
23+ $arg0 [--dry-run] [--version X.X.X] [--method detect] [--prefix ~/.local] [user@host]
2424
2525 --dry-run
2626 Echo the commands for the install process without running them.
@@ -128,11 +128,18 @@ main() {
128128 --version=* )
129129 VERSION=" $( parse_arg " $@ " ) "
130130 ;;
131+ --)
132+ shift
133+ break
134+ ;;
131135 -h | --h | -help | --help)
132136 usage
133137 exit 0
134138 ;;
135139 * )
140+ SSH_ARGS=" $1 "
141+ ;;
142+ -* )
136143 echoerr " Unknown flag $1 "
137144 echoerr " Run with --help to see usage."
138145 exit 1
@@ -149,6 +156,7 @@ main() {
149156 echoerr " Run with --help to see usage."
150157 exit 1
151158 fi
159+ RHOME=" $( sh_c_f printenv HOME) "
152160 STANDALONE_INSTALL_PREFIX=" ${STANDALONE_INSTALL_PREFIX-$HOME / .local} "
153161
154162 OS=" $( os) "
@@ -162,11 +170,11 @@ main() {
162170 ARCH=" $( arch) "
163171 if [ ! " $ARCH " ]; then
164172 if [ " $METHOD " = standalone ]; then
165- echoerr " No precompiled releases for $( uname -m) ."
173+ echoerr " No precompiled releases for $( sh_c_f uname -m) ."
166174 echoerr ' Please rerun without the "--method standalone" flag to install from npm.'
167175 exit 1
168176 fi
169- echoh " No precompiled releases for $( uname -m) ."
177+ echoh " No precompiled releases for $( sh_c_f uname -m) ."
170178 install_npm
171179 return
172180 fi
@@ -366,7 +374,7 @@ install_npm() {
366374}
367375
368376os () {
369- case " $( uname) " in
377+ case " $( sh_c_f uname) " in
370378 Linux)
371379 echo linux
372380 ;;
@@ -391,14 +399,15 @@ os() {
391399#
392400# Inspired by https://github.com/docker/docker-install/blob/26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c/install.sh#L111-L120.
393401distro () {
402+ set -x
394403 if [ " $OS " = " macos" ] || [ " $OS " = " freebsd" ]; then
395404 echo " $OS "
396405 return
397406 fi
398407
399- if [ -f /etc/os-release ]; then
408+ if sh_c_f [ -f /etc/os-release ]; then
400409 (
401- . /etc/os-release
410+ ID= " $( sh_c_f ' . /etc/os-release && echo "$ID" ' ) "
402411 case " $ID " in opensuse-* )
403412 # opensuse's ID's look like opensuse-leap and opensuse-tumbleweed.
404413 echo " opensuse"
@@ -414,25 +423,22 @@ distro() {
414423
415424# os_name prints a pretty human readable name for the OS/Distro.
416425distro_name () {
417- if [ " $( uname) " = " Darwin" ]; then
418- echo " macOS v$( sw_vers -productVersion) "
426+ if [ " $( sh_c_f uname) " = " Darwin" ]; then
427+ echo " macOS v$( sh_c_f sw_vers -productVersion) "
419428 return
420429 fi
421430
422- if [ -f /etc/os-release ]; then
423- (
424- . /etc/os-release
425- echo " $PRETTY_NAME "
426- )
431+ if sh_c_f [ -f /etc/os-release ]; then
432+ sh_c_f ' . /etc/os-release && echo "$PRETTY_NAME"'
427433 return
428434 fi
429435
430436 # Prints something like: Linux 4.19.0-9-amd64
431- uname -sr
437+ sh_c_f uname -sr
432438}
433439
434440arch () {
435- case " $( uname -m) " in
441+ case " $( sh_c_f uname -m) " in
436442 aarch64)
437443 echo arm64
438444 ;;
@@ -452,6 +458,20 @@ command_exists() {
452458sh_c () {
453459 echoh " + $* "
454460 if [ ! " ${DRY_RUN-} " ]; then
461+ sh_c_f " $@ "
462+ fi
463+ }
464+
465+ # Always runs.
466+ sh_c_f () {
467+ if [ " $SSH_ARGS " ]; then
468+ mkdir -p ~ /.ssh/sockets
469+ ssh \
470+ -oControlPath=~ /.ssh/sockets/%r@%n.sock \
471+ -oControlMaster=auto \
472+ -oControlPersist=yes \
473+ $SSH_ARGS " $* "
474+ else
455475 sh -c " $* "
456476 fi
457477}
@@ -473,10 +493,10 @@ sudo_sh_c() {
473493}
474494
475495echo_cache_dir () {
476- if [ " ${ XDG_CACHE_HOME-} " ]; then
477- echo " $XDG_CACHE_HOME /code-server"
478- elif [ " ${HOME -} " ]; then
479- echo " $HOME /.cache/code-server"
496+ if [ " $( sh_c_f printenv XDG_CACHE_HOME) " ]; then
497+ echo " $( sh_c_f printenv XDG_CACHE_HOME) /code-server"
498+ elif [ " ${RHOME -} " ]; then
499+ echo " $RHOME /.cache/code-server"
480500 else
481501 echo " /tmp/code-server-cache"
482502 fi
@@ -494,10 +514,10 @@ echoerr() {
494514 echoh " $@ " >&2
495515}
496516
497- # humanpath replaces all occurances of " $HOME " with " ~"
498- # and all occurances of '"$HOME ' with the literal '"$HOME '.
517+ # humanpath replaces all occurances of " $RHOME " with " ~"
518+ # and all occurances of '"$RHOME ' with the literal '"$RHOME '.
499519humanpath () {
500- sed " s# $HOME # ~#g; s#\" $HOME #\"\$ HOME #g"
520+ sed " s# $RHOME # ~#g; s#\" $RHOME #\"\$ RHOME #g"
501521}
502522
503523main " $@ "
0 commit comments