2
2
set -eu
3
3
4
4
# code-server's automatic install script.
5
- # See https://github .com/cdr /code-server/blob/main/docs /install
5
+ # See https://coder .com/docs /code-server/v3.10.2 /install
6
6
7
7
usage () {
8
8
arg0=" $0 "
@@ -14,7 +14,7 @@ usage() {
14
14
fi
15
15
16
16
cath << EOF
17
- Installs code-server for Linux, macOS and FreeBSD .
17
+ Installs code-server.
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
20
@@ -48,24 +48,23 @@ Usage:
48
48
--rsh <bin>
49
49
Specifies the remote shell for remote installation. Defaults to ssh.
50
50
51
- - For Debian, Ubuntu and Raspbian it will install the latest deb package.
52
- - For Fedora, CentOS, RHEL and openSUSE it will install the latest rpm package.
53
- - For Arch Linux it will install the AUR package.
54
- - For any unrecognized Linux operating system it will install the latest standalone
55
- release into ~/.local
51
+ The detection method works as follows:
52
+ - Debian, Ubuntu, Raspbian: install the deb package from GitHub.
53
+ - Fedora, CentOS, RHEL, openSUSE: install the rpm package from GitHub.
54
+ - Arch Linux: install from the AUR (which pulls releases from GitHub).
55
+ - FreeBSD, Alpine: install from yarn/npm.
56
+ - macOS: install using Homebrew if installed otherwise install from GitHub.
57
+ - All others: install the release from GitHub.
56
58
57
- - For macOS it will install the Homebrew package.
58
- - If Homebrew is not installed it will install the latest standalone release
59
- into ~/.local
59
+ We only build releases on GitHub for amd64 and arm64 on Linux and amd64 for
60
+ macOS. When the detection method tries to pull a release from GitHub it will
61
+ fall back to installing from npm when there is no matching release for the
62
+ system's operating system and architecture.
60
63
61
- - For FreeBSD or Alpine, it will install the npm package with yarn or npm.
64
+ The standalone method will force installion using GitHub releases. It will not
65
+ fall back to npm so on architectures without pre-built releases this will error.
62
66
63
- - If ran on an architecture with no releases, it will install the
64
- npm package with yarn or npm.
65
- - We only have releases for amd64 and arm64 presently.
66
- - The npm package builds the native modules on postinstall.
67
-
68
- It will cache all downloaded assets into ~/.cache/code-server
67
+ The installer will cache all downloaded assets into ~/.cache/code-server
69
68
70
69
More installation docs are at https://coder.com/docs/code-server/v3.10.2/install
71
70
EOF
@@ -120,7 +119,6 @@ main() {
120
119
DRY_RUN \
121
120
METHOD \
122
121
STANDALONE_INSTALL_PREFIX \
123
- VERSION \
124
122
OPTIONAL \
125
123
ALL_FLAGS \
126
124
RSH_ARGS \
@@ -198,80 +196,69 @@ main() {
198
196
return
199
197
fi
200
198
201
- VERSION=" ${VERSION-$(echo_latest_version)} "
202
199
METHOD=" ${METHOD-detect} "
203
200
if [ " $METHOD " != detect ] && [ " $METHOD " != standalone ]; then
204
201
echoerr " Unknown install method \" $METHOD \" "
205
202
echoerr " Run with --help to see usage."
206
203
exit 1
207
204
fi
208
- STANDALONE_INSTALL_PREFIX=" ${STANDALONE_INSTALL_PREFIX-$HOME / .local} "
209
205
210
- OS=" $( os) "
211
- if [ ! " $OS " ]; then
212
- echoerr " Unsupported OS $( uname) ."
213
- exit 1
214
- fi
206
+ # These are used by the various install_* functions that make use of GitHub
207
+ # releases in order to download and unpack the right release.
208
+ CACHE_DIR=$( echo_cache_dir)
209
+ STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:- $HOME / .local}
210
+ VERSION=${VERSION:- $(echo_latest_version)}
211
+ # These can be overridden for testing but shouldn't normally be used as it can
212
+ # result in a broken code-server.
213
+ OS=${OS:- $(os)}
214
+ ARCH=${ARCH:- $(arch)}
215
215
216
216
distro_name
217
217
218
- ARCH=" $( arch) "
219
- if [ ! " $ARCH " ]; then
220
- if [ " $METHOD " = standalone ]; then
221
- echoerr " No precompiled releases for $( uname -m) ."
222
- echoerr ' Please rerun without the "--method standalone" flag to install from npm.'
223
- exit 1
224
- fi
225
- echoh " No precompiled releases for $( uname -m) ."
226
- install_npm
227
- return
228
- fi
229
-
230
- if [ " $OS " = " freebsd" ]; then
231
- if [ " $METHOD " = standalone ]; then
232
- echoerr " No precompiled releases available for $OS ."
233
- echoerr ' Please rerun without the "--method standalone" flag to install from npm.'
234
- exit 1
235
- fi
236
- echoh " No precompiled releases available for $OS ."
237
- install_npm
238
- return
239
- fi
240
-
241
- if [ " $OS " = " linux" ] && [ " $( distro) " = " alpine" ]; then
242
- if [ " $METHOD " = standalone ]; then
243
- echoerr " No precompiled releases available for alpine."
244
- echoerr ' Please rerun without the "--method standalone" flag to install from npm.'
218
+ # Standalone installs by pulling pre-built releases from GitHub.
219
+ if [ " $METHOD " = standalone ]; then
220
+ if has_standalone; then
221
+ install_standalone
222
+ else
223
+ echoerr " There are no standalone releases for $ARCH "
224
+ echoerr " Please try again without '--method standalone'"
245
225
exit 1
246
226
fi
247
- echoh " No precompiled releases available for alpine."
248
- install_npm
249
- return
250
227
fi
251
228
252
- CACHE_DIR=" $( echo_cache_dir) "
253
-
254
- if [ " $METHOD " = standalone ]; then
255
- install_standalone
256
- return
257
- fi
229
+ # DISTRO can be overridden for testing but shouldn't normally be used as it
230
+ # can result in a broken code-server.
231
+ DISTRO=${DISTRO:- $(distro)}
258
232
259
- case " $( distro) " in
233
+ case $DISTRO in
234
+ # macOS uses brew when available and falls back to standalone. We only have
235
+ # amd64 for macOS so for anything else use npm.
260
236
macos)
261
- install_macos
262
- ;;
263
- debian)
264
- install_deb
265
- ;;
266
- fedora | opensuse)
267
- install_rpm
268
- ;;
269
- arch)
270
- install_aur
237
+ BREW_PATH=" ${BREW_PATH-brew} "
238
+ if command_exists " $BREW_PATH " ; then
239
+ install_brew
240
+ else
241
+ echoh " Homebrew not installed."
242
+ echoh " Falling back to standalone installation."
243
+ npm_fallback install_standalone
244
+ fi
271
245
;;
246
+ # The .deb and .rpm files are pulled from GitHub and we only have amd64 and
247
+ # arm64 there and need to fall back to npm otherwise.
248
+ debian) npm_fallback install_deb ;;
249
+ fedora | opensuse) npm_fallback install_rpm ;;
250
+ # Arch uses the AUR package which only supports amd64 and arm64 since it
251
+ # pulls releases from GitHub so we need to fall back to npm.
252
+ arch) npm_fallback install_aur ;;
253
+ # We don't have GitHub releases that work on Alpine or FreeBSD so we have no
254
+ # choice but to use npm here.
255
+ alpine | freebsd) install_npm ;;
256
+ # For anything else we'll try to install standalone but fall back to npm if
257
+ # we don't have releases for the architecture.
272
258
* )
273
259
echoh " Unsupported package manager."
274
- install_standalone
260
+ echoh " Falling back to standalone installation."
261
+ npm_fallback install_standalone
275
262
;;
276
263
esac
277
264
}
@@ -326,23 +313,15 @@ fetch() {
326
313
sh_c mv " $FILE .incomplete" " $FILE "
327
314
}
328
315
329
- install_macos () {
330
- if command_exists brew; then
331
- echoh " Installing from Homebrew."
332
- echoh
333
-
334
- sh_c brew install code-server
335
-
336
- return
337
- fi
338
-
339
- echoh " Homebrew not installed."
316
+ install_brew () {
317
+ echoh " Installing latest from Homebrew."
318
+ echoh
340
319
341
- install_standalone
320
+ sh_c " $BREW_PATH " install code-server
342
321
}
343
322
344
323
install_deb () {
345
- echoh " Installing v$VERSION deb package from GitHub releases ."
324
+ echoh " Installing v$VERSION of the $ARCH deb package from GitHub."
346
325
echoh
347
326
348
327
fetch " https://github.com/cdr/code-server/releases/download/v$VERSION /code-server_${VERSION} _$ARCH .deb" \
@@ -353,7 +332,7 @@ install_deb() {
353
332
}
354
333
355
334
install_rpm () {
356
- echoh " Installing v$VERSION rpm package from GitHub releases ."
335
+ echoh " Installing v$VERSION of the $ARCH rpm package from GitHub."
357
336
echoh
358
337
359
338
fetch " https://github.com/cdr/code-server/releases/download/v$VERSION /code-server-$VERSION -$ARCH .rpm" \
@@ -364,7 +343,7 @@ install_rpm() {
364
343
}
365
344
366
345
install_aur () {
367
- echoh " Installing from the AUR."
346
+ echoh " Installing latest from the AUR."
368
347
echoh
369
348
370
349
sh_c mkdir -p " $CACHE_DIR /code-server-aur"
@@ -379,7 +358,7 @@ install_aur() {
379
358
}
380
359
381
360
install_standalone () {
382
- echoh " Installing standalone release archive v $VERSION from GitHub releases ."
361
+ echoh " Installing v $VERSION of the $ARCH release from GitHub."
383
362
echoh
384
363
385
364
fetch " https://github.com/cdr/code-server/releases/download/v$VERSION /code-server-$VERSION -$OS -$ARCH .tar.gz" \
@@ -406,50 +385,74 @@ install_standalone() {
406
385
}
407
386
408
387
install_npm () {
409
- if command_exists yarn; then
388
+ echoh " Installing latest from npm."
389
+ echoh
390
+
391
+ YARN_PATH=" ${YARN_PATH-yarn} "
392
+ NPM_PATH=" ${YARN_PATH-npm} "
393
+ if command_exists " $YARN_PATH " ; then
410
394
sh_c=" sh_c"
411
- if [ ! - w " $( yarn global bin) " ]; then
395
+ if [ ! " ${DRY_RUN-} " ] && [ ! - w " $( $YARN_PATH global bin) " ]; then
412
396
sh_c=" sudo_sh_c"
413
397
fi
414
398
echoh " Installing with yarn."
415
399
echoh
416
- " $sh_c " yarn global add code-server --unsafe-perm
417
- NPM_BIN_DIR=" $( yarn global bin) " echo_npm_postinstall
400
+ " $sh_c " " $YARN_PATH " global add code-server --unsafe-perm
401
+ NPM_BIN_DIR=" \$ ( $YARN_PATH global bin)" echo_npm_postinstall
418
402
return
419
- elif command_exists npm ; then
403
+ elif command_exists " $NPM_PATH " ; then
420
404
sh_c=" sh_c"
421
- if [ ! - w " $( npm config get prefix) " ]; then
405
+ if [ ! " ${DRY_RUN-} " ] && [ ! - w " $( NPM_PATH config get prefix) " ]; then
422
406
sh_c=" sudo_sh_c"
423
407
fi
424
408
echoh " Installing with npm."
425
409
echoh
426
- " $sh_c " npm install -g code-server --unsafe-perm
427
- NPM_BIN_DIR=" $( npm bin -g) " echo_npm_postinstall
410
+ " $sh_c " " $NPM_PATH " install -g code-server --unsafe-perm
411
+ NPM_BIN_DIR=" \$ ( $NPM_PATH bin -g)" echo_npm_postinstall
428
412
return
429
413
fi
430
- echoh
431
414
echoerr " Please install npm or yarn to install code-server!"
432
415
echoerr " You will need at least node v12 and a few C dependencies."
433
416
echoerr " See the docs https://coder.com/docs/code-server/v3.10.2/install#yarn-npm"
417
+
434
418
exit 1
435
419
}
436
420
437
- os () {
438
- case " $( uname) " in
439
- Linux)
440
- echo linux
441
- ;;
442
- Darwin)
443
- echo macos
444
- ;;
445
- FreeBSD)
446
- echo freebsd
421
+ # Run $1 if we have a standalone otherwise run install_npm.
422
+ npm_fallback () {
423
+ if has_standalone; then
424
+ $1
425
+ else
426
+ echoh " No standalone releases for $ARCH ."
427
+ echoh " Falling back to installation from npm."
428
+ install_npm
429
+ fi
430
+ }
431
+
432
+ # Determine if we have standalone releases on GitHub for the system's arch.
433
+ has_standalone () {
434
+ case $ARCH in
435
+ amd64) return 0 ;;
436
+ # We only have amd64 for macOS.
437
+ arm64)
438
+ [ " $( distro) " != macos ]
439
+ return
447
440
;;
441
+ * ) return 1 ;;
448
442
esac
449
443
}
450
444
451
- # distro prints the detected operating system including linux distros.
452
- # Also parses ID_LIKE for common distro bases.
445
+ os () {
446
+ uname=" $( uname) "
447
+ case $uname in
448
+ Linux) echo linux ;;
449
+ Darwin) echo macos ;;
450
+ FreeBSD) echo freebsd ;;
451
+ * ) echo " $uname " ;;
452
+ esac
453
+ }
454
+
455
+ # Print the detected Linux distro, otherwise print the OS name.
453
456
#
454
457
# Example outputs:
455
458
# - macos -> macos
@@ -486,7 +489,7 @@ distro() {
486
489
fi
487
490
}
488
491
489
- # os_name prints a pretty human readable name for the OS/Distro .
492
+ # Print a human- readable name for the OS/distro .
490
493
distro_name () {
491
494
if [ " $( uname) " = " Darwin" ]; then
492
495
echo " macOS v$( sw_vers -productVersion) "
@@ -506,20 +509,16 @@ distro_name() {
506
509
}
507
510
508
511
arch () {
509
- case " $( uname -m) " in
510
- aarch64)
511
- echo arm64
512
- ;;
513
- x86_64)
514
- echo amd64
515
- ;;
516
- amd64) # FreeBSD.
517
- echo amd64
518
- ;;
512
+ uname_m=$( uname -m)
513
+ case $uname_m in
514
+ aarch64) echo arm64 ;;
515
+ x86_64) echo amd64 ;;
516
+ * ) echo " $uname_m " ;;
519
517
esac
520
518
}
521
519
522
520
command_exists () {
521
+ if [ ! " $1 " ]; then return 1 ; fi
523
522
command -v " $@ " > /dev/null
524
523
}
525
524
0 commit comments