7
7
usage () {
8
8
arg0=" $0 "
9
9
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] "
11
11
else
12
12
not_curl_usage=" The latest script is available at https://code-server.dev/install.sh
13
13
"
@@ -20,7 +20,7 @@ After successful installation it explains how to start using code-server.
20
20
${not_curl_usage-}
21
21
Usage:
22
22
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]
24
24
25
25
--dry-run
26
26
Echo the commands for the install process without running them.
@@ -128,11 +128,18 @@ main() {
128
128
--version=* )
129
129
VERSION=" $( parse_arg " $@ " ) "
130
130
;;
131
+ --)
132
+ shift
133
+ break
134
+ ;;
131
135
-h | --h | -help | --help)
132
136
usage
133
137
exit 0
134
138
;;
135
139
* )
140
+ SSH_ARGS=" $1 "
141
+ ;;
142
+ -* )
136
143
echoerr " Unknown flag $1 "
137
144
echoerr " Run with --help to see usage."
138
145
exit 1
@@ -149,6 +156,7 @@ main() {
149
156
echoerr " Run with --help to see usage."
150
157
exit 1
151
158
fi
159
+ RHOME=" $( sh_c_f printenv HOME) "
152
160
STANDALONE_INSTALL_PREFIX=" ${STANDALONE_INSTALL_PREFIX-$HOME / .local} "
153
161
154
162
OS=" $( os) "
@@ -162,11 +170,11 @@ main() {
162
170
ARCH=" $( arch) "
163
171
if [ ! " $ARCH " ]; then
164
172
if [ " $METHOD " = standalone ]; then
165
- echoerr " No precompiled releases for $( uname -m) ."
173
+ echoerr " No precompiled releases for $( sh_c_f uname -m) ."
166
174
echoerr ' Please rerun without the "--method standalone" flag to install from npm.'
167
175
exit 1
168
176
fi
169
- echoh " No precompiled releases for $( uname -m) ."
177
+ echoh " No precompiled releases for $( sh_c_f uname -m) ."
170
178
install_npm
171
179
return
172
180
fi
@@ -366,7 +374,7 @@ install_npm() {
366
374
}
367
375
368
376
os () {
369
- case " $( uname) " in
377
+ case " $( sh_c_f uname) " in
370
378
Linux)
371
379
echo linux
372
380
;;
@@ -391,14 +399,15 @@ os() {
391
399
#
392
400
# Inspired by https://github.com/docker/docker-install/blob/26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c/install.sh#L111-L120.
393
401
distro () {
402
+ set -x
394
403
if [ " $OS " = " macos" ] || [ " $OS " = " freebsd" ]; then
395
404
echo " $OS "
396
405
return
397
406
fi
398
407
399
- if [ -f /etc/os-release ]; then
408
+ if sh_c_f [ -f /etc/os-release ]; then
400
409
(
401
- . /etc/os-release
410
+ ID= " $( sh_c_f ' . /etc/os-release && echo "$ID" ' ) "
402
411
case " $ID " in opensuse-* )
403
412
# opensuse's ID's look like opensuse-leap and opensuse-tumbleweed.
404
413
echo " opensuse"
@@ -414,25 +423,22 @@ distro() {
414
423
415
424
# os_name prints a pretty human readable name for the OS/Distro.
416
425
distro_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) "
419
428
return
420
429
fi
421
430
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"'
427
433
return
428
434
fi
429
435
430
436
# Prints something like: Linux 4.19.0-9-amd64
431
- uname -sr
437
+ sh_c_f uname -sr
432
438
}
433
439
434
440
arch () {
435
- case " $( uname -m) " in
441
+ case " $( sh_c_f uname -m) " in
436
442
aarch64)
437
443
echo arm64
438
444
;;
@@ -452,6 +458,20 @@ command_exists() {
452
458
sh_c () {
453
459
echoh " + $* "
454
460
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
455
475
sh -c " $* "
456
476
fi
457
477
}
@@ -473,10 +493,10 @@ sudo_sh_c() {
473
493
}
474
494
475
495
echo_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"
480
500
else
481
501
echo " /tmp/code-server-cache"
482
502
fi
@@ -494,10 +514,10 @@ echoerr() {
494
514
echoh " $@ " >&2
495
515
}
496
516
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 '.
499
519
humanpath () {
500
- sed " s# $HOME # ~#g; s#\" $HOME #\"\$ HOME #g"
520
+ sed " s# $RHOME # ~#g; s#\" $RHOME #\"\$ RHOME #g"
501
521
}
502
522
503
523
main " $@ "
0 commit comments