@@ -17,27 +17,45 @@ usage() {
17
17
Installs code-server for Linux, macOS and FreeBSD.
18
18
It tries to use the system package manager if possible.
19
19
After successful installation it explains how to start using code-server.
20
+
21
+ Pass --start to startup code-server immediately, print the URL it can be
22
+ accessed at and the initial password. Then the script will tail code-server's logs.
23
+
24
+ Pass in user@host to install code-server on user@host over ssh.
25
+ Pass --start to forward the code-server port and start it so that
26
+ you can immediately access it.
27
+
28
+ If you rerun the script, code-server will be updated only if necessary.
20
29
${not_curl_usage-}
21
30
Usage:
22
31
23
- $arg0 [--dry-run] [--version X.X.X] [--method detect] [--prefix ~/.local]
32
+ $arg0 [--dry-run] [--version X.X.X] [--method detect] [--prefix ~/.local] [--start] [user@host]
24
33
25
34
--dry-run
26
35
Echo the commands for the install process without running them.
36
+
27
37
--version X.X.X
28
38
Install a specific version instead of the latest.
39
+
29
40
--method [detect | standalone]
30
41
Choose the installation method. Defaults to detect.
31
42
- detect detects the system package manager and tries to use it.
32
43
Full reference on the process is further below.
33
44
- standalone installs a standalone release archive into ~/.local
34
45
Add ~/.local/bin to your \$ PATH to use it.
46
+
35
47
--prefix <dir>
36
48
Sets the prefix used by standalone release archives. Defaults to ~/.local
37
49
The release is unarchived into ~/.local/lib/code-server-X.X.X
38
50
and the binary symlinked into ~/.local/bin/code-server
39
51
To install system wide pass ---prefix=/usr/local
40
52
53
+ --start
54
+ Ensures code-server is running and prints the URL at which it can be accessed.
55
+ Also will print code-server's password and when installing over ssh, will forward
56
+ the code-server port so that it can be easily accessed locally.
57
+ Will block on tailing code-server's logs.
58
+
41
59
- For Debian, Ubuntu and Raspbian it will install the latest deb package.
42
60
- For Fedora, CentOS, RHEL and openSUSE it will install the latest rpm package.
43
61
- For Arch Linux it will install the AUR package.
56
74
- The npm package builds the native modules on postinstall.
57
75
58
76
It will cache all downloaded assets into ~/.cache/code-server
77
+ With ssh installation, assets will be transferred over via ssh
78
+ as needed instead of being downloaded directly on the ssh host.
59
79
60
80
More installation docs are at https://github.com/cdr/code-server/blob/master/doc/install.md
61
81
EOF
@@ -128,15 +148,28 @@ main() {
128
148
--version=* )
129
149
VERSION=" $( parse_arg " $@ " ) "
130
150
;;
151
+ --)
152
+ shift
153
+ break
154
+ ;;
131
155
-h | --h | -help | --help)
132
156
usage
133
157
exit 0
134
158
;;
135
- * )
159
+ - * )
136
160
echoerr " Unknown flag $1 "
137
161
echoerr " Run with --help to see usage."
138
162
exit 1
139
163
;;
164
+ * )
165
+ SSH_ARGS=" $1 "
166
+ if ! sshs true ; then
167
+ echoerr " could not ssh into remote host"
168
+ echoerr " failed: ssh $SSH_ARGS true"
169
+ exit 1
170
+ fi
171
+ echoh " Installing remotely with ssh $SSH_ARGS "
172
+ ;;
140
173
esac
141
174
142
175
shift
@@ -153,7 +186,7 @@ main() {
153
186
154
187
OS=" $( os) "
155
188
if [ ! " $OS " ]; then
156
- echoerr " Unsupported OS $( uname) ."
189
+ echoerr " Unsupported OS $( sh_f uname) ."
157
190
exit 1
158
191
fi
159
192
@@ -162,11 +195,11 @@ main() {
162
195
ARCH=" $( arch) "
163
196
if [ ! " $ARCH " ]; then
164
197
if [ " $METHOD " = standalone ]; then
165
- echoerr " No precompiled releases for $( uname -m) ."
198
+ echoerr " No precompiled releases for $( sh_f uname -m) ."
166
199
echoerr ' Please rerun without the "--method standalone" flag to install from npm.'
167
200
exit 1
168
201
fi
169
- echoh " No precompiled releases for $( uname -m) ."
202
+ echoh " No precompiled releases for $( sh_f uname -m) ."
170
203
install_npm
171
204
return
172
205
fi
@@ -242,20 +275,25 @@ parse_arg() {
242
275
}
243
276
244
277
fetch () {
245
- URL=" $1 "
246
- FILE=" $2 "
278
+ RHOME=" $( sh_f printenv HOME) "
247
279
248
- if [ -e " $FILE " ]; then
280
+ URL=" $( echo " $1 " | sed " s#$HOME #$RHOME #g" ) "
281
+ FILE=" $( echo " $2 " | sed " s#$HOME #$RHOME #g" ) "
282
+
283
+ if sh_f [ -e " $FILE " ]; then
249
284
echoh " + Reusing $FILE "
250
285
return
251
286
fi
252
287
253
288
sh_c mkdir -p " $CACHE_DIR "
254
- sh_c curl \
289
+ SSH_ARGS= sh_c curl \
255
290
-#fL \
256
291
-o " $FILE .incomplete" \
257
292
-C - \
258
293
" $URL "
294
+ if [ " ${SSH_ARGS} " ]; then
295
+ sh_c cat ' >' " $FILE .incomplete"
296
+ fi
259
297
sh_c mv " $FILE .incomplete" " $FILE "
260
298
}
261
299
@@ -319,11 +357,11 @@ install_standalone() {
319
357
" $CACHE_DIR /code-server-$VERSION -$OS -$ARCH .tar.gz"
320
358
321
359
sh_c=" sh_c"
322
- if [ ! -w " $STANDALONE_INSTALL_PREFIX " ]; then
360
+ if sh_f [ ! -w " $STANDALONE_INSTALL_PREFIX " ]; then
323
361
sh_c=" sudo_sh_c"
324
362
fi
325
363
326
- if [ -e " $STANDALONE_INSTALL_PREFIX /lib/code-server-$VERSION " ]; then
364
+ if sh_f [ -e " $STANDALONE_INSTALL_PREFIX /lib/code-server-$VERSION " ]; then
327
365
echoh
328
366
echoh " code-server-$VERSION is already installed at $STANDALONE_INSTALL_PREFIX /lib/code-server-$VERSION "
329
367
echoh " Remove it to reinstall."
@@ -341,7 +379,7 @@ install_standalone() {
341
379
install_npm () {
342
380
if command_exists yarn; then
343
381
sh_c=" sh_c"
344
- if [ ! -w " $( yarn global bin) " ]; then
382
+ if sh_f [ ! -w " $( sh_f yarn global bin) " ]; then
345
383
sh_c=" sudo_sh_c"
346
384
fi
347
385
echoh " Installing with yarn."
@@ -350,7 +388,7 @@ install_npm() {
350
388
return
351
389
elif command_exists npm; then
352
390
sh_c=" sh_c"
353
- if [ ! -w " $( npm config get prefix) " ]; then
391
+ if sh_f [ ! -w " $( sh_f npm config get prefix) " ]; then
354
392
sh_c=" sudo_sh_c"
355
393
fi
356
394
echoh " Installing with npm."
@@ -366,7 +404,7 @@ install_npm() {
366
404
}
367
405
368
406
os () {
369
- case " $( uname) " in
407
+ case " $( sh_f uname) " in
370
408
Linux)
371
409
echo linux
372
410
;;
@@ -396,9 +434,9 @@ distro() {
396
434
return
397
435
fi
398
436
399
- if [ -f /etc/os-release ]; then
437
+ if sh_f [ -f /etc/os-release ]; then
400
438
(
401
- . /etc/os-release
439
+ ID= " $( sh_f ' . /etc/os-release && echo "$ID" ' ) "
402
440
case " $ID " in opensuse-* )
403
441
# opensuse's ID's look like opensuse-leap and opensuse-tumbleweed.
404
442
echo " opensuse"
@@ -414,25 +452,22 @@ distro() {
414
452
415
453
# os_name prints a pretty human readable name for the OS/Distro.
416
454
distro_name () {
417
- if [ " $( uname) " = " Darwin" ]; then
418
- echo " macOS v$( sw_vers -productVersion) "
455
+ if [ " $( sh_f uname) " = " Darwin" ]; then
456
+ echo " macOS v$( sh_f sw_vers -productVersion) "
419
457
return
420
458
fi
421
459
422
- if [ -f /etc/os-release ]; then
423
- (
424
- . /etc/os-release
425
- echo " $PRETTY_NAME "
426
- )
460
+ if sh_f [ -f /etc/os-release ]; then
461
+ sh_f ' . /etc/os-release && echo "$PRETTY_NAME"'
427
462
return
428
463
fi
429
464
430
465
# Prints something like: Linux 4.19.0-9-amd64
431
- uname -sr
466
+ sh_f uname -sr
432
467
}
433
468
434
469
arch () {
435
- case " $( uname -m) " in
470
+ case " $( sh_f uname -m) " in
436
471
aarch64)
437
472
echo arm64
438
473
;;
@@ -446,18 +481,53 @@ arch() {
446
481
}
447
482
448
483
command_exists () {
449
- command -v " $@ " > /dev/null 2>&1
484
+ sh_f command -v " $@ " > /dev/null
450
485
}
451
486
452
487
sh_c () {
453
488
echoh " + $* "
454
489
if [ ! " ${DRY_RUN-} " ]; then
490
+ sh_f " $@ "
491
+ fi
492
+ }
493
+
494
+ sshs () {
495
+ mkdir -p ~ /.ssh/sockets
496
+ chmod 700 ~ /.ssh
497
+
498
+ set -- \
499
+ -oControlPath=~ /.ssh/sockets/%r@%n.sock \
500
+ -oControlMaster=auto \
501
+ -oControlPersist=yes \
502
+ -oConnectTimeout=5 \
503
+ $SSH_ARGS \
504
+ " $@ "
505
+
506
+ if ssh " $@ " ; then
507
+ return
508
+ fi
509
+
510
+ if ssh -O exit " $@ " ; then
511
+ # Control master has been deleted so we ought to try once more.
512
+ if ssh " $@ " ; then
513
+ return
514
+ fi
515
+ fi
516
+
517
+ return 1
518
+ }
519
+
520
+ # Always runs.
521
+ sh_f () {
522
+ if [ " ${SSH_ARGS-} " ]; then
523
+ sshs " $* "
524
+ else
455
525
sh -c " $* "
456
526
fi
457
527
}
458
528
459
529
sudo_sh_c () {
460
- if [ " $( id -u) " = 0 ]; then
530
+ if [ " $( sh_f id -u) " = 0 ]; then
461
531
sh_c " $@ "
462
532
elif command_exists sudo; then
463
533
sh_c " sudo $* "
@@ -473,8 +543,8 @@ sudo_sh_c() {
473
543
}
474
544
475
545
echo_cache_dir () {
476
- if [ " ${ XDG_CACHE_HOME-} " ]; then
477
- echo " $XDG_CACHE_HOME /code-server"
546
+ if [ " $( sh_f printenv XDG_CACHE_HOME) " ]; then
547
+ echo " $( sh_f printenv XDG_CACHE_HOME) /code-server"
478
548
elif [ " ${HOME-} " ]; then
479
549
echo " $HOME /.cache/code-server"
480
550
else
0 commit comments