22set -eu
33
44usage () {
5+ cli=" $0 "
6+ if [ " $0 " = sh ]; then
7+ cli=" curl -fsSL https://code-server.dev/install.sh | sh -s --"
8+ else
9+ curl_usage=" $(
10+ cat << EOF
11+
12+ To use latest:
13+
14+ curl -fsSL https://code-server.dev/install.sh | sh -s -- <args>
15+ EOF
16+ ) " $" \n"
17+ fi
518 cat << EOF
6- $0 [--dry-run] [--version X.X.X] [--static <install-prefix>=~/.local]
19+ Installs latest code-server on Linux or macOS preferring to use the system package manager.
720
8- Installs latest code-server on any macOS or Linux system preferring to use the OS package manager.
21+ Lives at https:// code-server.dev/install.sh
922
10- curl -fsSL https://code-server.dev/install.sh | sh -s --
23+ Usage:
1124
25+ $cli [--dry-run] [--version X.X.X] [--static <install-prefix>=~/.local]
26+ ${curl_usage-}
1227- For Debian, Ubuntu, Raspbian it will install the latest deb package.
1328- For Fedora, CentOS, RHEL, openSUSE it will install the latest rpm package.
1429- For Arch Linux it will install the AUR package.
@@ -19,8 +34,7 @@ Installs latest code-server on any macOS or Linux system preferring to use the O
1934 - If Homebrew is not installed it will install the latest static release into ~/.local
2035 - Add ~/.local/bin to your \$ PATH to run code-server.
2136
22- - If ran on an architecture with no binary releases or outdated libc/libcxx, it will install the
23- npm package with yarn or npm.
37+ - If ran on an architecture with no binary releases, it will install the npm package with yarn or npm.
2438 - We only have binary releases for amd64 and arm64 presently.
2539
2640 --dry-run Enables a dry run where where the steps that would have taken place
4054}
4155
4256echo_latest_version () {
43- version= " $( curl -fsSL https://api .github.com/repos/cdr/code-server/releases/latest | jq -r .tag_name ) "
44- # Strip leading v.
45- version=" ${version: 1 } "
57+ # https://gist .github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860
58+ version= " $( curl -fsSLI -o /dev/null -w " %{url_effective} " https://github.com/cdr/code-server/releases/latest ) "
59+ version=" ${version# https :// github.com / cdr / code-server / releases / tag / v } "
4660 echo " $version "
4761}
4862
@@ -172,7 +186,7 @@ parse_arg() {
172186 * =* )
173187 opt=" ${1# =* } "
174188 optarg=" ${1#* =} "
175- if [ ! " $optarg " -a ! " ${OPTIONAL-} " ]; then
189+ if [ ! " $optarg " ] && [ ! " ${OPTIONAL-} " ]; then
176190 echoerr " $opt requires an argument"
177191 echoerr " Run with --help to see usage."
178192 exit 1
@@ -183,7 +197,7 @@ parse_arg() {
183197 esac
184198
185199 case " ${2-} " in
186- " " | -* | -- * )
200+ " " | -* )
187201 if [ ! " ${OPTIONAL-} " ]; then
188202 echoerr " $1 requires an argument"
189203 echoerr " Run with --help to see usage."
@@ -282,7 +296,7 @@ install_static() {
282296 fi
283297 SKIP_ECHO=1 sh_c mkdir -p " $STATIC_INSTALL_PREFIX /lib" " $STATIC_INSTALL_PREFIX /bin"
284298
285- if [[ -e " $STATIC_INSTALL_PREFIX /lib/code-server-$VERSION " ] ]; then
299+ if [ -e " $STATIC_INSTALL_PREFIX /lib/code-server-$VERSION " ]; then
286300 echo
287301 echoerr " code-server-$VERSION is already installed at $STATIC_INSTALL_PREFIX /lib/code-server-$VERSION "
288302 echoerr " Please remove it to reinstall."
@@ -339,21 +353,20 @@ distro() {
339353 return
340354 fi
341355
342- if [ ! -f /etc/os-release ]; then
356+ if [ -f /etc/os-release ]; then
357+ (
358+ . /etc/os-release
359+ case " $ID " in opensuse-* )
360+ # opensuse's ID's look like opensuse-leap and opensuse-tumbleweed.
361+ echo " opensuse"
362+ return
363+ ;;
364+ esac
365+
366+ echo " $ID "
367+ )
343368 return
344369 fi
345-
346- (
347- . /etc/os-release
348- case " $ID " in opensuse-* )
349- # opensuse's ID's look like opensuse-leap and opensuse-tumbleweed.
350- echo " opensuse"
351- return
352- ;;
353- esac
354-
355- echo " $ID "
356- )
357370}
358371
359372# os_name prints a pretty human readable name for the OS/Distro.
@@ -363,11 +376,12 @@ distro_name() {
363376 return
364377 fi
365378
366- if [ ! -f /etc/os-release ]; then
379+ if [ -f /etc/os-release ]; then
367380 (
368381 . /etc/os-release
369382 echo " $PRETTY_NAME "
370383 )
384+ return
371385 fi
372386
373387 # Prints something like: Linux 4.19.0-9-amd64
0 commit comments