diff --git a/README.md b/README.md index b1a48532..b090b779 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,19 @@ Run [VS Code](https://github.com/Microsoft/vscode) on any machine anywhere and a ## Highlights -- **Code everywhere:** Code on your Chromebook, tablet, and laptop with a - consistent dev environment. Develop on a Linux machine and pick up from any - device with a web browser. -- **Server-powered:** Take advantage of large cloud servers to speed up tests, compilations, downloads, and more. - Preserve battery life when you're on the go since all intensive tasks runs on your server. - Make use of a spare computer you have lying around and turn it into a full development environment. +- **Code everywhere** + - Code on your Chromebook, tablet, and laptop with a consistent development environment. + - Develop on a Linux machine and pick up from any device with a web browser. +- **Server-powered** + - Take advantage of large cloud servers to speed up tests, compilations, downloads, and more. + - Preserve battery life when you're on the go as all intensive tasks runs on your server. + - Make use of a spare computer you have lying around and turn it into a full development environment. ## Getting Started For a full setup and walkthrough, please see [./doc/guide.md](./doc/guide.md). -[We have a script](./install.sh) to install code-server for Linux and macOS. +We have a [script](./install.sh) to install code-server for Linux and macOS. It tries to use the system package manager if possible. @@ -35,6 +36,10 @@ curl -fsSL https://code-server.dev/install.sh | sh The install script will print out how to run and start using code-server. +If you believe an install script used with `curl | sh` is insecure, please give +[this wonderful blogpost](https://sandstorm.io/news/2015-09-24-is-curl-bash-insecure-pgp-verified-install) by +[sandstorm.io](https://sandstorm.io) a read. + Docs on the install script, manual installation and docker image are at [./doc/install.md](./doc/install.md). ## FAQ diff --git a/ci/build/build-code-server.sh b/ci/build/build-code-server.sh index 82668f4d..a48ab0e0 100755 --- a/ci/build/build-code-server.sh +++ b/ci/build/build-code-server.sh @@ -9,7 +9,7 @@ MINIFY=${MINIFY-true} main() { cd "$(dirname "${0}")/../.." - npx tsc --outDir out --tsBuildInfoFile .cache/out.tsbuildinfo + tsc --outDir out --tsBuildInfoFile .cache/out.tsbuildinfo # If out/node/entry.js does not already have the shebang, # we make sure to add it and make it executable. if ! grep -q -m1 "^#!/usr/bin/env node" out/node/entry.js; then @@ -17,7 +17,7 @@ main() { chmod +x out/node/entry.js fi - npx parcel build \ + parcel build \ --public-url "/static/$(git rev-parse HEAD)/dist" \ --out-dir dist \ $([[ $MINIFY ]] || echo --no-minify) \ diff --git a/ci/build/build-static-release.sh b/ci/build/build-static-release.sh index 24af32f0..759fa872 100755 --- a/ci/build/build-static-release.sh +++ b/ci/build/build-static-release.sh @@ -34,7 +34,8 @@ main() { } bundle_dynamic_lib() { - lib_name="$1" + local lib_name="$1" + local lib_path if [[ $OS == "linux" ]]; then lib_path="$(ldd "$RELEASE_PATH/lib/node" | grep "$lib_name" | awk '{print $3 }')" diff --git a/ci/build/code-server.sh b/ci/build/code-server.sh index c1aed088..927fe2c6 100755 --- a/ci/build/code-server.sh +++ b/ci/build/code-server.sh @@ -19,7 +19,7 @@ bin_dir() { BIN_DIR=$(bin_dir) if [ "$(uname)" = "Linux" ]; then export LD_LIBRARY_PATH="$BIN_DIR/../lib${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}" -else +elif [ "$(uname)" = "Darwin" ]; then export DYLD_LIBRARY_PATH="$BIN_DIR/../lib${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}" fi exec "$BIN_DIR/../lib/node" "$BIN_DIR/.." "$@" diff --git a/doc/FAQ.md b/doc/FAQ.md index ebecf919..ba565f64 100644 --- a/doc/FAQ.md +++ b/doc/FAQ.md @@ -40,7 +40,7 @@ See https://cdn.vsassets.io/v/M146_20190123.39/_content/Microsoft-Visual-Studio- > Marketplace Offerings are intended for use only with Visual Studio Products and Services > and you may only install and use Marketplace Offerings with Visual Studio Products and Services. -As a result, [Coder](https://coder.com) has created its own marketplace for open source extensions. +As a result, we have created our own marketplace for open source extensions. It works by scraping GitHub for VS Code extensions and building them. It's not perfect but getting better by the day with more and more extensions. diff --git a/doc/guide.md b/doc/guide.md index 6db6a492..fd8219f3 100644 --- a/doc/guide.md +++ b/doc/guide.md @@ -15,21 +15,22 @@ -This guide demonstrates how to setup and use code-server. -To reiterate, code-server lets you run VS Code on a remote server and then access it via a browser. +This guide demonstrates how to setup and use `code-server`. +To reiterate, `code-server` lets you run VS Code on a remote server and then access it via a browser. Further docs are at: -- [README.md](../README.md) for a general overview -- [FAQ.md](./FAQ.md) for common questions. -- [CONTRIBUTING.md](../doc/CONTRIBUTING.md) for development docs +- [README](../README.md) for a general overview +- [INSTALL](../doc/install.md) for installation +- [FAQ](./FAQ.md) for common questions. +- [CONTRIBUTING](../doc/CONTRIBUTING.md) for development docs -We'll walk you through acquiring a remote machine to run code-server on +We'll walk you through acquiring a remote machine to run `code-server` on and then exposing `code-server` so you can securely access it. ## 1. Acquire a remote machine -First, you need a machine to run code-server on. You can use a physical +First, you need a machine to run `code-server` on. You can use a physical machine you have lying around or use a VM on GCP/AWS. ### Requirements @@ -64,7 +65,6 @@ Once you've signed up and created a GCP project, create a new Compute Engine VM - Click `Change` under `Boot Disk` and change the type to `SSD Persistent Disk` and the size to `32`. - You can always grow your disk later. - - The default OS of Debian 10 is fine. 8. Navigate to `Networking -> Network interfaces` and edit the existing interface to use a static external IP. - Click done to save network interface changes. @@ -78,7 +78,7 @@ to avoid the slow dashboard. ## 2. Install code-server -[We have a script](./install.sh) to install code-server for Linux and macOS. +We have a [script](./install.sh) to install `code-server` for Linux and macOS. It tries to use the system package manager if possible. @@ -94,7 +94,7 @@ Now to actually install: curl -fsSL https://code-server.dev/install.sh | sh ``` -The install script will print out how to run and start using code-server. +The install script will print out how to run and start using `code-server`. Docs on the install script, manual installation and docker image are at [./doc/install.md](./doc/install.md). @@ -103,32 +103,29 @@ Docs on the install script, manual installation and docker image are at [./doc/i **Never**, **ever** expose `code-server` directly to the internet without some form of authentication and encryption as someone can completely takeover your machine with the terminal. -By default, code-server will enable password authentication which will -require you to copy the password from the code-server config file to login. Since it -cannot use TLS by default, it will listen on `localhost` to avoid exposing itself -to the world. This is fine for testing but will not work if you want to access `code-server` +By default, `code-server` will enable password authentication which will require you to copy the +password from the`code-server`config file to login. It will listen on`localhost` to avoid exposing +itself to the world. This is fine for testing but will not work if you want to access `code-server` from a different machine. -There are several approaches to securely operating and exposing code-server. +There are several approaches to securely operating and exposing `code-server`. -**tip**: You can list the full set of code-server options with `code-server --help` +**tip**: You can list the full set of `code-server` options with `code-server --help` ### SSH forwarding We highly recommend this approach for not requiring any additional setup, you just need an SSH server on your remote machine. The downside is you won't be able to access `code-server` -without an SSH client like an iPad. If that's important to you, skip to [Let's Encrypt](#lets-encrypt). +on any machine without an SSH client like on iPad. If that's important to you, skip to [Let's Encrypt](#lets-encrypt). -Recommended reading: https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding. - -First, ssh into your instance and edit your code-server config file to disable password authentication. +First, ssh into your instance and edit your `code-server` config file to disable password authentication. ```bash # Replaces "auth: password" with "auth: none" in the code-server config. sed -i.bak 's/auth: password/auth: none/' ~/.config/code-server/config.yaml ``` -Restart code-server with (assuming you followed the guide): +Restart `code-server` with (assuming you followed the guide): ```bash systemctl --user restart code-server @@ -136,12 +133,14 @@ systemctl --user restart code-server Now forward local port 8080 to `127.0.0.1:8080` on the remote instance. +Recommended reading: https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding. + ```bash # -N disables executing a remote shell ssh -N -L 8080:127.0.0.1:8080 ``` -Now if you access http://127.0.0.1:8080 locally, you should see code-server! +Now if you access http://127.0.0.1:8080 locally, you should see `code-server`! If you want to make the SSH port forwarding persistent we recommend using [mutagen](https://mutagen.io/documentation/introduction/installation). @@ -168,8 +167,8 @@ and sign commits without copying your keys. ### Let's Encrypt -[Let's Encrypt](https://letsencrypt.org) is a great option if you want to access code-server on an iPad -or do not want to use SSH forwarding. This does require that the remote machine is exposed to the internet. +[Let's Encrypt](https://letsencrypt.org) is a great option if you want to access `code-server` on an iPad +or do not want to use SSH forwarding. This does require that the remote machine be exposed to the internet. Assuming you have been following the guide, edit your instance and checkmark the allow HTTP/HTTPS traffic options. @@ -198,9 +197,9 @@ reverse_proxy 127.0.0.1:8080 sudo systemctl reload caddy ``` -Visit `https://` to access code-server. Congratulations! +Visit `https://` to access `code-server`. Congratulations! -In a future release we plan to integrate Let's Encrypt directly with code-server to avoid +In a future release we plan to integrate Let's Encrypt directly with `code-server` to avoid the dependency on caddy. ### Self Signed Certificate @@ -210,13 +209,12 @@ have to use [Let's Encrypt](#lets-encrypt) instead. See the [FAQ](https://github Recommended reading: https://security.stackexchange.com/a/8112. -We recommend this as a last resort as self signed certificates do not work with iPads and can -cause other bizarre issues. Not to mention all the warnings when you access code-server. +We recommend this as a last resort because self signed certificates do not work with iPads and can +cause other bizarre issues. Not to mention all the warnings when you access `code-server`. Only use this if: -1. You do not want to buy a domain. -2. You cannot expose the remote machine to the internet. -3. You do not want to use SSH forwarding. +1. You do not want to buy a domain or you cannot expose the remote machine to the internet. +2. You do not want to use SSH forwarding. ssh into your instance and edit your code-server config file to use a randomly generated self signed certificate: @@ -229,7 +227,7 @@ sed -i.bak 's/bind-addr: 127.0.0.1:8080/bind-addr: 0.0.0.0:443/' ~/.config/code- sudo setcap cap_net_bind_service=+ep /usr/lib/code-server/lib/node ``` -Assuming you have been following the guide, restart code-server with: +Assuming you have been following the guide, restart `code-server` with: ```bash systemctl --user restart code-server @@ -237,17 +235,17 @@ systemctl --user restart code-server Edit your instance and checkmark the allow HTTPS traffic option. -Visit `https://` to access code-server. +Visit `https://` to access `code-server`. You'll get a warning when accessing but if you click through you should be good. To avoid the warnings, you can use [mkcert](https://mkcert.dev) to create a self signed certificate -trusted by your OS and then pass it into code-server via the `cert` and `cert-key` config +trusted by your OS and then pass it into `code-server` via the `cert` and `cert-key` config fields. ### Change the password? -Edit the `password` field in the code-server config file at `~/.config/code-server/config.yaml` -and then restart code-server with: +Edit the `password` field in the `code-server` config file at `~/.config/code-server/config.yaml` +and then restart `code-server` with: ```bash systemctl --user restart code-server @@ -255,6 +253,6 @@ systemctl --user restart code-server ### How do I securely access development web services? -If you're working on a web service and want to access it locally, code-server can proxy it for you. +If you're working on a web service and want to access it locally, `code-server` can proxy it for you. -See [FAQ.md](https://github.com/cdr/code-server/blob/master/doc/FAQ.md#how-do-i-securely-access-web-services). +See the [FAQ](https://github.com/cdr/code-server/blob/master/doc/FAQ.md#how-do-i-securely-access-web-services). diff --git a/doc/install.md b/doc/install.md index 7ae35c74..baecf6fd 100644 --- a/doc/install.md +++ b/doc/install.md @@ -4,7 +4,7 @@ - [install.sh](#installsh) - [Flags](#flags) - - [Installation reference](#installation-reference) + - [Detect Reference](#detect-reference) - [Debian, Ubuntu](#debian-ubuntu) - [Fedora, CentOS, RHEL, SUSE](#fedora-centos-rhel-suse) - [Arch Linux](#arch-linux) @@ -20,7 +20,7 @@ various distros and operating systems. ## install.sh -[We have a script](./install.sh) to install code-server for Linux and macOS. +We have a [script](./install.sh) to install code-server for Linux and macOS. It tries to use the system package manager if possible. @@ -42,19 +42,21 @@ If you believe an install script used with `curl | sh` is insecure, please give [this wonderful blogpost](https://sandstorm.io/news/2015-09-24-is-curl-bash-insecure-pgp-verified-install) by [sandstorm.io](https://sandstorm.io) a read. -If you'd still prefer manual installation despite the below [reference](#reference) and `--dry-run` +If you'd still prefer manual installation despite the below [detect reference](#detect-reference) and `--dry-run` then continue on for docs on manual installation. The [`install.sh`](./install.sh) script runs the _exact_ same commands presented in the rest of this document. ### Flags - `--dry-run` to echo the commands for the install process without running them. -- `--static` to install a static release into `~/.local`. -- `--static=/usr/local` to install a static release system wide. +- `--method` to choose the installation method. + - `--method=detect` to detect the package manager but fallback to `--method=archive`. + - `--method=archive` to install a static release archive into `~/.local`. +- `--prefix=/usr/local` to install a static release archive system wide. - `--version=X.X.X` to install version `X.X.X` instead of latest. - `--help` to see full usage docs. -### Reference +### Detect Reference - For Debian, Ubuntu and Raspbian it will install the latest deb package. - For Fedora, CentOS, RHEL and openSUSE it will install the latest rpm package. @@ -66,7 +68,7 @@ commands presented in the rest of this document. - For macOS it will install the Homebrew package. - If Homebrew is not installed it will install the latest static release into `~/.local`. - - Add ~/.local/bin to your \$PATH to run code-server. + - Add `~/.local/bin` to your `$PATH` to run code-server. - If ran on an architecture with no binary releases, it will install the npm package with `yarn` or `npm`. - We only have binary releases for amd64 and arm64 presently. @@ -137,14 +139,14 @@ brew services start code-server ## Static Releases We publish self contained `.tar.gz` archives for every release on [github](https://github.com/cdr/code-server/releases). -They bundle the node binary and node_modules. +They bundle the node binary and `node_modules`. 1. Download the latest release archive for your system from [github](https://github.com/cdr/code-server/releases). 2. Unpack the release. 3. You can run code-server by executing `./bin/code-server`. -You can add the code-server `bin` directory to your `$PATH` or link to it from a -directory in your `$PATH` to easily execute `code-server` without the full path every time. +You can add the code-server `bin` directory to your `$PATH` to easily execute `code-server` +without the full path every time. Here is an example script for installing and using a static `code-server` release on Linux: @@ -174,6 +176,6 @@ docker run -it -p 127.0.0.1:8080:8080 \ Our official image supports `amd64` and `arm64`. -For `arm32` support there is a highly popular community maintained alternative: +For `arm32` support there is a popular community maintained alternative: https://hub.docker.com/r/linuxserver/code-server diff --git a/install.sh b/install.sh index 35dbaa54..70a3a3a1 100755 --- a/install.sh +++ b/install.sh @@ -1,51 +1,59 @@ #!/bin/sh set -eu +# code-server's automatic install script. +# See https://github.com/cdr/code-server/blob/master/doc/install.md + usage() { - cli="$0" + arg0="$0" if [ "$0" = sh ]; then - cli="curl -fsSL https://code-server.dev/install.sh | sh -s --" + arg0="curl -fsSL https://code-server.dev/install.sh | sh -s --" else - curl_usage="The latest script is available at https://code-server.dev/install.sh" + curl_usage="The latest script is available at https://code-server.dev/install.sh +" fi + cat << EOF -Installs code-server for Linux or macOS. +Installs code-server for Linux and macOS. It tries to use the system package manager if possible. After successful installation it explains how to start using code-server. ${curl_usage-} - Usage: - $cli [--dry-run] [--version X.X.X] [--static =~/.local] + $arg0 [--dry-run] [--version X.X.X] [--method detect] [--prefix ~/.local] - --dry-run Echo the commands for the install process without running them. - - --version Install a specific version instead of the latest release. - - --static Install a static release into ~/.local - - The release will be unarchived into ~/.local/lib/code-server.X.X.X - and the binary symlinked into ~/.local/bin/code-server. - Add ~/.local/bin to your \$PATH to use it. - - To install system wide pass ---static=/usr/local + --dry-run + Echo the commands for the install process without running them. + --version X.X.X + Install a specific version instead of the latest. + --method [detect | archive] + Choose the installation method. Defaults to detect. + - detect detects the system package manager and tries to use it. + Full reference on the process is further below. + - archive installs a static release archive into ~/.local + Add ~/.local/bin to your \$PATH to use it. + --prefix + Sets the prefix used by static release archives. Defaults to ~/.local + The release is unarchived into ~/.local/lib/code-server-X.X.X + and the binary symlinked into ~/.local/bin/code-server + To install system wide pass ---prefix=/usr/local - For Debian, Ubuntu and Raspbian it will install the latest deb package. - For Fedora, CentOS, RHEL and openSUSE it will install the latest rpm package. - For Arch Linux it will install the AUR package. - For any unrecognized Linux operating system it will install the latest static release into ~/.local - - Add ~/.local/bin to your \$PATH to run code-server. - For macOS it will install the Homebrew package. - If Homebrew is not installed it will install the latest static release into ~/.local - - Add ~/.local/bin to your \$PATH to run code-server. - If ran on an architecture with no binary releases, it will install the npm package with yarn or npm. - We only have binary releases for amd64 and arm64 presently. +It will cache all downloaded assets into ~/.cache/code-server + More installation docs are at https://github.com/cdr/code-server/blob/master/doc/install.md EOF } @@ -60,10 +68,9 @@ echo_latest_version() { echo_static_postinstall() { echo cat << EOF -Static release has been installed into $STATIC_INSTALL_PREFIX/lib/code-server-$VERSION - +Static release has been installed into $ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION Please extend your path to use code-server: - PATH="$STATIC_INSTALL_PREFIX/bin:\$PATH" + PATH="$ARCHIVE_INSTALL_PREFIX/bin:\$PATH" Then you can run: code-server EOF @@ -86,8 +93,8 @@ main() { unset \ DRY_RUN \ - STATIC \ - STATIC_INSTALL_PREFIX \ + METHOD \ + ARCHIVE_INSTALL_PREFIX \ SKIP_ECHO \ VERSION \ OPTIONAL @@ -97,16 +104,19 @@ main() { --dry-run) DRY_RUN=1 ;; - --static) - STATIC=1 - if [ "${2-}" ]; then - STATIC_INSTALL_PREFIX="$(OPTIONAL=1 parse_arg "$@")" - shift - fi + --method) + METHOD="$(parse_arg "$@")" + shift ;; - --static=*) - STATIC=1 - STATIC_INSTALL_PREFIX="$(OPTIONAL=1 parse_arg "$@")" + --method=*) + METHOD="$(parse_arg "$@")" + ;; + --prefix) + ARCHIVE_INSTALL_PREFIX="$(parse_arg "$@")" + shift + ;; + --prefix=*) + ARCHIVE_INSTALL_PREFIX="$(parse_arg "$@")" ;; --version) VERSION="$(parse_arg "$@")" @@ -115,7 +125,7 @@ main() { --version=*) VERSION="$(parse_arg "$@")" ;; - -h | --help) + -h | --h | -help | --help) usage exit 0 ;; @@ -130,7 +140,13 @@ main() { done VERSION="${VERSION-$(echo_latest_version)}" - STATIC_INSTALL_PREFIX="${STATIC_INSTALL_PREFIX-$HOME/.local}" + METHOD="${METHOD-detect}" + if [ "$METHOD" != detect ] && [ "$METHOD" != archive ]; then + echoerr "Unknown install method \"$METHOD\"" + echoerr "Run with --help to see usage." + exit 1 + fi + ARCHIVE_INSTALL_PREFIX="${ARCHIVE_INSTALL_PREFIX-$HOME/.local}" OS="$(os)" if [ ! "$OS" ]; then @@ -142,11 +158,12 @@ main() { ARCH="$(arch)" if [ ! "$ARCH" ]; then - if [ "${STATIC-}" ]; then + if [ "$METHOD" = archive ]; then echoerr "No static releases available for the architecture $(uname -m)." - echoerr "Please rerun without the --static flag to install from npm." + echoerr 'Please rerun without the "--method archive" flag to install from npm.' exit 1 fi + echo "No precompiled releases for $(uname -m)." install_npm return fi @@ -154,8 +171,8 @@ main() { CACHE_DIR="$(echo_cache_dir)" mkdir -p "$CACHE_DIR" - if [ "${STATIC-}" ]; then - install_static + if [ "$METHOD" = archive ]; then + install_archive return fi @@ -170,10 +187,11 @@ main() { install_rpm ;; arch) - install_arch + install_aur ;; *) - install_static + echo "Unsupported package manager." + install_archive ;; esac } @@ -212,36 +230,43 @@ fetch() { URL="$1" FILE="$2" + echo "+ Downloading $URL" + if [ -e "$FILE" ]; then - echo - echo "+ Using cached $FILE from $URL" + echo "+ Using cached $FILE" return fi + SKIP_ECHO=1 sh_c curl \ -#fL \ - -Ro "$FILE.incomplete" \ + -o "$FILE.incomplete" \ -C - \ "$URL" - SKIP_ECHO=1 sh_c mv "$FILE.incomplete" "$FILE" + sh_c mv "$FILE.incomplete" "$FILE" + unset SKIP_ECHO + + echo "+ Downloaded into $FILE" } install_macos() { if command_exists brew; then echo "Installing from Homebrew." + echo sh_c brew install code-server return fi - echo "Homebrew is not installed so installing static release." + echo "Homebrew not installed." - install_static + install_archive } install_deb() { echo "Installing v$VERSION deb package from GitHub releases." + echo fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server_${VERSION}_$ARCH.deb" "$CACHE_DIR/code-server_${VERSION}_$ARCH.deb" sudo_sh_c dpkg -i "$CACHE_DIR/code-server_${VERSION}_$ARCH.deb" @@ -251,6 +276,7 @@ install_deb() { install_rpm() { echo "Installing v$VERSION rpm package from GitHub releases." + echo fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$ARCH.rpm" "$CACHE_DIR/code-server-$VERSION-$ARCH.rpm" sudo_sh_c rpm -i "$CACHE_DIR/code-server-$VERSION-$ARCH.rpm" @@ -260,65 +286,67 @@ install_rpm() { install_aur() { echo "Installing from the AUR." + echo - fetch "https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz" "$CACHE_DIR/code-server-aur.tar.gz" - + prev_dir="$PWD" tmp_dir="$(mktemp -d)" - ( - cd "$tmp_dir" - SKIP_ECHO=1 sh_c tar -xzf "$CACHE_DIR/code-server-aur.tar.gz" --strip-components 1 - sh_c makepkg -si - ) + cd "$tmp_dir" + + echo "+ Downloading PKGBUILD from https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz" + SKIP_ECHO=1 sh_c 'curl -fsSL https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz | tar -xz --strip-components 1' + unset SKIP_ECHO + echo "+ Downloaded into $tmp_dir" + sh_c makepkg -si + + cd "$prev_dir" rm -Rf "$tmp_dir" echo_systemd_postinstall } -install_static() { - STATIC_INSTALL_PREFIX=${STATIC_INSTALL_PREFIX-/usr/local/lib} - +install_archive() { echo "Installing static release v$VERSION" + echo - fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$OS-$ARCH.tar.gz" "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz" - - if [ ! -d "$STATIC_INSTALL_PREFIX" ]; then - echo - echoerr "Static release install prefix $STATIC_INSTALL_PREFIX does not exist" - exit 1 - fi + fetch "https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-$OS-$ARCH.tar.gz" \ + "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz" sh_c="sh_c" - if [ ! -w "$STATIC_INSTALL_PREFIX" ]; then + if [ ! -w "$ARCHIVE_INSTALL_PREFIX" ]; then sh_c="sudo_sh_c" fi - SKIP_ECHO=1 sh_c mkdir -p "$STATIC_INSTALL_PREFIX/lib" "$STATIC_INSTALL_PREFIX/bin" - if [ -e "$STATIC_INSTALL_PREFIX/lib/code-server-$VERSION" ]; then + SKIP_ECHO=1 sh_c mkdir -p "$ARCHIVE_INSTALL_PREFIX/lib" "$ARCHIVE_INSTALL_PREFIX/bin" + unset SKIP_ECHO + + if [ -e "$ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION" ]; then echo - echoerr "code-server-$VERSION is already installed at $STATIC_INSTALL_PREFIX/lib/code-server-$VERSION" - echoerr "Please remove it to reinstall." - exit 1 + echo "code-server-$VERSION is already installed at $ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION" + echo "Remove it to reinstall." + exit 0 fi - "$sh_c" tar -C "$STATIC_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz" - "$sh_c" mv -f "$STATIC_INSTALL_PREFIX/lib/code-server-$VERSION-$OS-$ARCH" "$STATIC_INSTALL_PREFIX/lib/code-server-$VERSION" + "$sh_c" tar -C "$ARCHIVE_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz" + "$sh_c" mv -f "$ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION-$OS-$ARCH" "$ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION" + "$sh_c" ln -fs "$ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION/bin/code-server" "$ARCHIVE_INSTALL_PREFIX/bin/code-server" echo_static_postinstall } install_npm() { - echoerr "No precompiled releases for $(uname -m)." if command_exists yarn; then echo "Installing with yarn." + echo sh_c yarn global add code-server --unsafe-perm return elif command_exists npm; then echo "Installing with npm." + echo sh_c npm install -g code-server --unsafe-perm return fi - echoerr + echo echoerr "Please install npm or yarn to install code-server!" - echoerr "You will need at least node v12 and a few C build dependencies." + echoerr "You will need at least node v12 and a few C dependencies." echoerr "See the docs https://github.com/cdr/code-server#yarn-npm" exit 1 } @@ -402,7 +430,6 @@ command_exists() { sh_c() { if [ ! "${SKIP_ECHO-}" ]; then - echo echo "+ $*" fi if [ ! "${DRY_RUN-}" ]; then @@ -421,7 +448,7 @@ sudo_sh_c() { echo echoerr "This script needs to run the following command as root." echoerr " $*" - echoerr "Please run this script as root or install sudo or su." + echoerr "Please install sudo or su." exit 1 fi }