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,11 +156,12 @@ main() {
149
156
echoerr " Run with --help to see usage."
150
157
exit 1
151
158
fi
152
- STANDALONE_INSTALL_PREFIX=" ${STANDALONE_INSTALL_PREFIX-$HOME / .local} "
159
+ RHOME=" $( sh_f printenv HOME) "
160
+ STANDALONE_INSTALL_PREFIX=" ${STANDALONE_INSTALL_PREFIX-$RHOME / .local} "
153
161
154
162
OS=" $( os) "
155
163
if [ ! " $OS " ]; then
156
- echoerr " Unsupported OS $( uname) ."
164
+ echoerr " Unsupported OS $( sh_f uname) ."
157
165
exit 1
158
166
fi
159
167
@@ -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_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_f uname -m) ."
170
178
install_npm
171
179
return
172
180
fi
@@ -245,7 +253,7 @@ fetch() {
245
253
URL=" $1 "
246
254
FILE=" $2 "
247
255
248
- if [ -e " $FILE " ]; then
256
+ if sh_f [ -e " $FILE " ]; then
249
257
echoh " + Reusing $FILE "
250
258
return
251
259
fi
@@ -319,11 +327,11 @@ install_standalone() {
319
327
" $CACHE_DIR /code-server-$VERSION -$OS -$ARCH .tar.gz"
320
328
321
329
sh_c=" sh_c"
322
- if [ ! -w " $STANDALONE_INSTALL_PREFIX " ]; then
330
+ if sh-f [ ! -w " $STANDALONE_INSTALL_PREFIX " ]; then
323
331
sh_c=" sudo_sh_c"
324
332
fi
325
333
326
- if [ -e " $STANDALONE_INSTALL_PREFIX /lib/code-server-$VERSION " ]; then
334
+ if sh_f [ -e " $STANDALONE_INSTALL_PREFIX /lib/code-server-$VERSION " ]; then
327
335
echoh
328
336
echoh " code-server-$VERSION is already installed at $STANDALONE_INSTALL_PREFIX /lib/code-server-$VERSION "
329
337
echoh " Remove it to reinstall."
@@ -341,7 +349,7 @@ install_standalone() {
341
349
install_npm () {
342
350
if command_exists yarn; then
343
351
sh_c=" sh_c"
344
- if [ ! -w " $( yarn global bin) " ]; then
352
+ if sh_f [ ! -w " $( sh_f yarn global bin) " ]; then
345
353
sh_c=" sudo_sh_c"
346
354
fi
347
355
echoh " Installing with yarn."
@@ -350,7 +358,7 @@ install_npm() {
350
358
return
351
359
elif command_exists npm; then
352
360
sh_c=" sh_c"
353
- if [ ! -w " $( npm config get prefix) " ]; then
361
+ if sh_f [ ! -w " $( sh_f npm config get prefix) " ]; then
354
362
sh_c=" sudo_sh_c"
355
363
fi
356
364
echoh " Installing with npm."
@@ -366,7 +374,7 @@ install_npm() {
366
374
}
367
375
368
376
os () {
369
- case " $( uname) " in
377
+ case " $( sh_f uname) " in
370
378
Linux)
371
379
echo linux
372
380
;;
@@ -396,9 +404,9 @@ distro() {
396
404
return
397
405
fi
398
406
399
- if [ -f /etc/os-release ]; then
407
+ if sh_f [ -f /etc/os-release ]; then
400
408
(
401
- . /etc/os-release
409
+ ID= " $( sh_f ' . /etc/os-release && echo "$ID" ' ) "
402
410
case " $ID " in opensuse-* )
403
411
# opensuse's ID's look like opensuse-leap and opensuse-tumbleweed.
404
412
echo " opensuse"
@@ -414,25 +422,22 @@ distro() {
414
422
415
423
# os_name prints a pretty human readable name for the OS/Distro.
416
424
distro_name () {
417
- if [ " $( uname) " = " Darwin" ]; then
418
- echo " macOS v$( sw_vers -productVersion) "
425
+ if [ " $( sh_f uname) " = " Darwin" ]; then
426
+ echo " macOS v$( sh_f sw_vers -productVersion) "
419
427
return
420
428
fi
421
429
422
- if [ -f /etc/os-release ]; then
423
- (
424
- . /etc/os-release
425
- echo " $PRETTY_NAME "
426
- )
430
+ if sh_f [ -f /etc/os-release ]; then
431
+ sh_f ' . /etc/os-release && echo "$PRETTY_NAME"'
427
432
return
428
433
fi
429
434
430
435
# Prints something like: Linux 4.19.0-9-amd64
431
- uname -sr
436
+ sh_f uname -sr
432
437
}
433
438
434
439
arch () {
435
- case " $( uname -m) " in
440
+ case " $( sh_f uname -m) " in
436
441
aarch64)
437
442
echo arm64
438
443
;;
@@ -446,18 +451,32 @@ arch() {
446
451
}
447
452
448
453
command_exists () {
449
- command -v " $@ " > /dev/null 2>&1
454
+ sh_f command -v " $@ " > /dev/null
450
455
}
451
456
452
457
sh_c () {
453
458
echoh " + $* "
454
459
if [ ! " ${DRY_RUN-} " ]; then
460
+ sh_f " $@ "
461
+ fi
462
+ }
463
+
464
+ # Always runs.
465
+ sh_f () {
466
+ if [ " $SSH_ARGS " ]; then
467
+ mkdir -p ~ /.ssh/sockets
468
+ ssh \
469
+ -oControlPath=~ /.ssh/sockets/%r@%n.sock \
470
+ -oControlMaster=auto \
471
+ -oControlPersist=yes \
472
+ $SSH_ARGS " $* "
473
+ else
455
474
sh -c " $* "
456
475
fi
457
476
}
458
477
459
478
sudo_sh_c () {
460
- if [ " $( id -u) " = 0 ]; then
479
+ if [ " $( sh_f id -u) " = 0 ]; then
461
480
sh_c " $@ "
462
481
elif command_exists sudo; then
463
482
sh_c " sudo $* "
@@ -473,10 +492,10 @@ sudo_sh_c() {
473
492
}
474
493
475
494
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"
495
+ if [ " $( sh_f printenv XDG_CACHE_HOME) " ]; then
496
+ echo " $( sh_f printenv XDG_CACHE_HOME) /code-server"
497
+ elif [ " ${RHOME -} " ]; then
498
+ echo " $RHOME /.cache/code-server"
480
499
else
481
500
echo " /tmp/code-server-cache"
482
501
fi
@@ -494,10 +513,10 @@ echoerr() {
494
513
echoh " $@ " >&2
495
514
}
496
515
497
- # humanpath replaces all occurances of " $HOME " with " ~"
498
- # and all occurances of '"$HOME ' with the literal '"$HOME '.
516
+ # humanpath replaces all occurances of " $RHOME " with " ~"
517
+ # and all occurances of '"$RHOME ' with the literal '"$RHOME '.
499
518
humanpath () {
500
- sed " s# $HOME # ~#g; s#\" $HOME #\"\$ HOME #g"
519
+ sed " s# $RHOME # ~#g; s#\" $RHOME #\"\$ RHOME #g"
501
520
}
502
521
503
522
main " $@ "
0 commit comments