Improved install.sh flags

This commit is contained in:
Anmol Sethi 2020-05-22 15:38:03 -04:00
parent 42b5152888
commit 7ef82d8422
No known key found for this signature in database
GPG Key ID: 8CEF1878FF10ADEB
8 changed files with 171 additions and 138 deletions

View File

@ -6,18 +6,19 @@ Run [VS Code](https://github.com/Microsoft/vscode) on any machine anywhere and a
## Highlights ## Highlights
- **Code everywhere:** Code on your Chromebook, tablet, and laptop with a - **Code everywhere**
consistent dev environment. Develop on a Linux machine and pick up from any - Code on your Chromebook, tablet, and laptop with a consistent development environment.
device with a web browser. - 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. - **Server-powered**
Preserve battery life when you're on the go since all intensive tasks runs on your server. - Take advantage of large cloud servers to speed up tests, compilations, downloads, and more.
Make use of a spare computer you have lying around and turn it into a full development environment. - 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 ## Getting Started
For a full setup and walkthrough, please see [./doc/guide.md](./doc/guide.md). 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. 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. 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). Docs on the install script, manual installation and docker image are at [./doc/install.md](./doc/install.md).
## FAQ ## FAQ

View File

@ -9,7 +9,7 @@ MINIFY=${MINIFY-true}
main() { main() {
cd "$(dirname "${0}")/../.." 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, # If out/node/entry.js does not already have the shebang,
# we make sure to add it and make it executable. # we make sure to add it and make it executable.
if ! grep -q -m1 "^#!/usr/bin/env node" out/node/entry.js; then if ! grep -q -m1 "^#!/usr/bin/env node" out/node/entry.js; then
@ -17,7 +17,7 @@ main() {
chmod +x out/node/entry.js chmod +x out/node/entry.js
fi fi
npx parcel build \ parcel build \
--public-url "/static/$(git rev-parse HEAD)/dist" \ --public-url "/static/$(git rev-parse HEAD)/dist" \
--out-dir dist \ --out-dir dist \
$([[ $MINIFY ]] || echo --no-minify) \ $([[ $MINIFY ]] || echo --no-minify) \

View File

@ -34,7 +34,8 @@ main() {
} }
bundle_dynamic_lib() { bundle_dynamic_lib() {
lib_name="$1" local lib_name="$1"
local lib_path
if [[ $OS == "linux" ]]; then if [[ $OS == "linux" ]]; then
lib_path="$(ldd "$RELEASE_PATH/lib/node" | grep "$lib_name" | awk '{print $3 }')" lib_path="$(ldd "$RELEASE_PATH/lib/node" | grep "$lib_name" | awk '{print $3 }')"

View File

@ -19,7 +19,7 @@ bin_dir() {
BIN_DIR=$(bin_dir) BIN_DIR=$(bin_dir)
if [ "$(uname)" = "Linux" ]; then if [ "$(uname)" = "Linux" ]; then
export LD_LIBRARY_PATH="$BIN_DIR/../lib${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}" 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}" export DYLD_LIBRARY_PATH="$BIN_DIR/../lib${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}"
fi fi
exec "$BIN_DIR/../lib/node" "$BIN_DIR/.." "$@" exec "$BIN_DIR/../lib/node" "$BIN_DIR/.." "$@"

View File

@ -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 > 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. > 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 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. better by the day with more and more extensions.

View File

@ -15,21 +15,22 @@
<!-- END doctoc generated TOC please keep comment here to allow auto update --> <!-- END doctoc generated TOC please keep comment here to allow auto update -->
This guide demonstrates how to setup and use code-server. 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. To reiterate, `code-server` lets you run VS Code on a remote server and then access it via a browser.
Further docs are at: Further docs are at:
- [README.md](../README.md) for a general overview - [README](../README.md) for a general overview
- [FAQ.md](./FAQ.md) for common questions. - [INSTALL](../doc/install.md) for installation
- [CONTRIBUTING.md](../doc/CONTRIBUTING.md) for development docs - [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. and then exposing `code-server` so you can securely access it.
## 1. Acquire a remote machine ## 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. machine you have lying around or use a VM on GCP/AWS.
### Requirements ### 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 - Click `Change` under `Boot Disk` and change the type to `SSD Persistent Disk` and the size
to `32`. to `32`.
- You can always grow your disk later. - 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 8. Navigate to `Networking -> Network interfaces` and edit the existing interface
to use a static external IP. to use a static external IP.
- Click done to save network interface changes. - Click done to save network interface changes.
@ -78,7 +78,7 @@ to avoid the slow dashboard.
## 2. Install code-server ## 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. 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 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). 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 **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. and encryption as someone can completely takeover your machine with the terminal.
By default, code-server will enable password authentication which will By default, `code-server` will enable password authentication which will require you to copy the
require you to copy the password from the code-server config file to login. Since it password from the`code-server`config file to login. It will listen on`localhost` to avoid exposing
cannot use TLS by default, it will listen on `localhost` to avoid exposing itself itself to the world. This is fine for testing but will not work if you want to access `code-server`
to the world. This is fine for testing but will not work if you want to access `code-server`
from a different machine. 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 ### SSH forwarding
We highly recommend this approach for not requiring any additional setup, you just need an 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` 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 ```bash
# Replaces "auth: password" with "auth: none" in the code-server config. # Replaces "auth: password" with "auth: none" in the code-server config.
sed -i.bak 's/auth: password/auth: none/' ~/.config/code-server/config.yaml 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 ```bash
systemctl --user restart code-server 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. 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 ```bash
# -N disables executing a remote shell # -N disables executing a remote shell
ssh -N -L 8080:127.0.0.1:8080 <instance-ip> ssh -N -L 8080:127.0.0.1:8080 <instance-ip>
``` ```
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 If you want to make the SSH port forwarding persistent we recommend using
[mutagen](https://mutagen.io/documentation/introduction/installation). [mutagen](https://mutagen.io/documentation/introduction/installation).
@ -168,8 +167,8 @@ and sign commits without copying your keys.
### Let's Encrypt ### Let's Encrypt
[Let's Encrypt](https://letsencrypt.org) is a great option if you want to access code-server on an iPad [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. 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. 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 sudo systemctl reload caddy
``` ```
Visit `https://<your-domain-name>` to access code-server. Congratulations! Visit `https://<your-domain-name>` 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. the dependency on caddy.
### Self Signed Certificate ### 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. 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 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. cause other bizarre issues. Not to mention all the warnings when you access `code-server`.
Only use this if: Only use this if:
1. You do not want to buy a domain. 1. You do not want to buy a domain or you cannot expose the remote machine to the internet.
2. You cannot expose the remote machine to the internet. 2. You do not want to use SSH forwarding.
3. 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: 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 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 ```bash
systemctl --user restart code-server systemctl --user restart code-server
@ -237,17 +235,17 @@ systemctl --user restart code-server
Edit your instance and checkmark the allow HTTPS traffic option. Edit your instance and checkmark the allow HTTPS traffic option.
Visit `https://<your-instance-ip>` to access code-server. Visit `https://<your-instance-ip>` to access `code-server`.
You'll get a warning when accessing but if you click through you should be good. 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 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. fields.
### Change the password? ### Change the password?
Edit the `password` field in the code-server config file at `~/.config/code-server/config.yaml` Edit the `password` field in the `code-server` config file at `~/.config/code-server/config.yaml`
and then restart code-server with: and then restart `code-server` with:
```bash ```bash
systemctl --user restart code-server systemctl --user restart code-server
@ -255,6 +253,6 @@ systemctl --user restart code-server
### How do I securely access development web services? ### 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).

View File

@ -4,7 +4,7 @@
- [install.sh](#installsh) - [install.sh](#installsh)
- [Flags](#flags) - [Flags](#flags)
- [Installation reference](#installation-reference) - [Detect Reference](#detect-reference)
- [Debian, Ubuntu](#debian-ubuntu) - [Debian, Ubuntu](#debian-ubuntu)
- [Fedora, CentOS, RHEL, SUSE](#fedora-centos-rhel-suse) - [Fedora, CentOS, RHEL, SUSE](#fedora-centos-rhel-suse)
- [Arch Linux](#arch-linux) - [Arch Linux](#arch-linux)
@ -20,7 +20,7 @@ various distros and operating systems.
## install.sh ## 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. 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 [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. [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 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. commands presented in the rest of this document.
### Flags ### Flags
- `--dry-run` to echo the commands for the install process without running them. - `--dry-run` to echo the commands for the install process without running them.
- `--static` to install a static release into `~/.local`. - `--method` to choose the installation method.
- `--static=/usr/local` to install a static release system wide. - `--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. - `--version=X.X.X` to install version `X.X.X` instead of latest.
- `--help` to see full usage docs. - `--help` to see full usage docs.
### Reference ### Detect Reference
- For Debian, Ubuntu and Raspbian it will install the latest deb package. - 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 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. - For macOS it will install the Homebrew package.
- If Homebrew is not installed it will install the latest static release into `~/.local`. - 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`. - 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. - We only have binary releases for amd64 and arm64 presently.
@ -137,14 +139,14 @@ brew services start code-server
## Static Releases ## Static Releases
We publish self contained `.tar.gz` archives for every release on [github](https://github.com/cdr/code-server/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). 1. Download the latest release archive for your system from [github](https://github.com/cdr/code-server/releases).
2. Unpack the release. 2. Unpack the release.
3. You can run code-server by executing `./bin/code-server`. 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 You can add the code-server `bin` directory to your `$PATH` to easily execute `code-server`
directory in your `$PATH` to easily execute `code-server` without the full path every time. without the full path every time.
Here is an example script for installing and using a static `code-server` release on Linux: 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`. 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 https://hub.docker.com/r/linuxserver/code-server

View File

@ -1,51 +1,59 @@
#!/bin/sh #!/bin/sh
set -eu set -eu
# code-server's automatic install script.
# See https://github.com/cdr/code-server/blob/master/doc/install.md
usage() { usage() {
cli="$0" arg0="$0"
if [ "$0" = sh ]; then 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 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 fi
cat << EOF 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. It tries to use the system package manager if possible.
After successful installation it explains how to start using code-server. After successful installation it explains how to start using code-server.
${curl_usage-} ${curl_usage-}
Usage: Usage:
$cli [--dry-run] [--version X.X.X] [--static <install-prefix>=~/.local] $arg0 [--dry-run] [--version X.X.X] [--method detect] [--prefix ~/.local]
--dry-run Echo the commands for the install process without running them. --dry-run
Echo the commands for the install process without running them.
--version Install a specific version instead of the latest release. --version X.X.X
Install a specific version instead of the latest.
--static Install a static release into ~/.local --method [detect | archive]
Choose the installation method. Defaults to detect.
The release will be unarchived into ~/.local/lib/code-server.X.X.X - detect detects the system package manager and tries to use it.
and the binary symlinked into ~/.local/bin/code-server. Full reference on the process is further below.
Add ~/.local/bin to your \$PATH to use it. - archive installs a static release archive into ~/.local
Add ~/.local/bin to your \$PATH to use it.
To install system wide pass ---static=/usr/local --prefix <dir>
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 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 Fedora, CentOS, RHEL and openSUSE it will install the latest rpm package.
- For Arch Linux it will install the AUR package. - For Arch Linux it will install the AUR package.
- For any unrecognized Linux operating system it will install the latest static - For any unrecognized Linux operating system it will install the latest static
release into ~/.local release into ~/.local
- Add ~/.local/bin to your \$PATH to run code-server.
- For macOS it will install the Homebrew package. - For macOS it will install the Homebrew package.
- If Homebrew is not installed it will install the latest static release - If Homebrew is not installed it will install the latest static release
into ~/.local 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 - If ran on an architecture with no binary releases, it will install the
npm package with yarn or npm. npm package with yarn or npm.
- We only have binary releases for amd64 and arm64 presently. - 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 More installation docs are at https://github.com/cdr/code-server/blob/master/doc/install.md
EOF EOF
} }
@ -60,10 +68,9 @@ echo_latest_version() {
echo_static_postinstall() { echo_static_postinstall() {
echo echo
cat << EOF 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: Please extend your path to use code-server:
PATH="$STATIC_INSTALL_PREFIX/bin:\$PATH" PATH="$ARCHIVE_INSTALL_PREFIX/bin:\$PATH"
Then you can run: Then you can run:
code-server code-server
EOF EOF
@ -86,8 +93,8 @@ main() {
unset \ unset \
DRY_RUN \ DRY_RUN \
STATIC \ METHOD \
STATIC_INSTALL_PREFIX \ ARCHIVE_INSTALL_PREFIX \
SKIP_ECHO \ SKIP_ECHO \
VERSION \ VERSION \
OPTIONAL OPTIONAL
@ -97,16 +104,19 @@ main() {
--dry-run) --dry-run)
DRY_RUN=1 DRY_RUN=1
;; ;;
--static) --method)
STATIC=1 METHOD="$(parse_arg "$@")"
if [ "${2-}" ]; then shift
STATIC_INSTALL_PREFIX="$(OPTIONAL=1 parse_arg "$@")"
shift
fi
;; ;;
--static=*) --method=*)
STATIC=1 METHOD="$(parse_arg "$@")"
STATIC_INSTALL_PREFIX="$(OPTIONAL=1 parse_arg "$@")" ;;
--prefix)
ARCHIVE_INSTALL_PREFIX="$(parse_arg "$@")"
shift
;;
--prefix=*)
ARCHIVE_INSTALL_PREFIX="$(parse_arg "$@")"
;; ;;
--version) --version)
VERSION="$(parse_arg "$@")" VERSION="$(parse_arg "$@")"
@ -115,7 +125,7 @@ main() {
--version=*) --version=*)
VERSION="$(parse_arg "$@")" VERSION="$(parse_arg "$@")"
;; ;;
-h | --help) -h | --h | -help | --help)
usage usage
exit 0 exit 0
;; ;;
@ -130,7 +140,13 @@ main() {
done done
VERSION="${VERSION-$(echo_latest_version)}" 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)" OS="$(os)"
if [ ! "$OS" ]; then if [ ! "$OS" ]; then
@ -142,11 +158,12 @@ main() {
ARCH="$(arch)" ARCH="$(arch)"
if [ ! "$ARCH" ]; then if [ ! "$ARCH" ]; then
if [ "${STATIC-}" ]; then if [ "$METHOD" = archive ]; then
echoerr "No static releases available for the architecture $(uname -m)." 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 exit 1
fi fi
echo "No precompiled releases for $(uname -m)."
install_npm install_npm
return return
fi fi
@ -154,8 +171,8 @@ main() {
CACHE_DIR="$(echo_cache_dir)" CACHE_DIR="$(echo_cache_dir)"
mkdir -p "$CACHE_DIR" mkdir -p "$CACHE_DIR"
if [ "${STATIC-}" ]; then if [ "$METHOD" = archive ]; then
install_static install_archive
return return
fi fi
@ -170,10 +187,11 @@ main() {
install_rpm install_rpm
;; ;;
arch) arch)
install_arch install_aur
;; ;;
*) *)
install_static echo "Unsupported package manager."
install_archive
;; ;;
esac esac
} }
@ -212,36 +230,43 @@ fetch() {
URL="$1" URL="$1"
FILE="$2" FILE="$2"
echo "+ Downloading $URL"
if [ -e "$FILE" ]; then if [ -e "$FILE" ]; then
echo echo "+ Using cached $FILE"
echo "+ Using cached $FILE from $URL"
return return
fi fi
SKIP_ECHO=1
sh_c curl \ sh_c curl \
-#fL \ -#fL \
-Ro "$FILE.incomplete" \ -o "$FILE.incomplete" \
-C - \ -C - \
"$URL" "$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() { install_macos() {
if command_exists brew; then if command_exists brew; then
echo "Installing from Homebrew." echo "Installing from Homebrew."
echo
sh_c brew install code-server sh_c brew install code-server
return return
fi fi
echo "Homebrew is not installed so installing static release." echo "Homebrew not installed."
install_static install_archive
} }
install_deb() { install_deb() {
echo "Installing v$VERSION deb package from GitHub releases." 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" 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" sudo_sh_c dpkg -i "$CACHE_DIR/code-server_${VERSION}_$ARCH.deb"
@ -251,6 +276,7 @@ install_deb() {
install_rpm() { install_rpm() {
echo "Installing v$VERSION rpm package from GitHub releases." 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" 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" sudo_sh_c rpm -i "$CACHE_DIR/code-server-$VERSION-$ARCH.rpm"
@ -260,65 +286,67 @@ install_rpm() {
install_aur() { install_aur() {
echo "Installing from the 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)" tmp_dir="$(mktemp -d)"
( cd "$tmp_dir"
cd "$tmp_dir"
SKIP_ECHO=1 sh_c tar -xzf "$CACHE_DIR/code-server-aur.tar.gz" --strip-components 1 echo "+ Downloading PKGBUILD from https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz"
sh_c makepkg -si 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" rm -Rf "$tmp_dir"
echo_systemd_postinstall echo_systemd_postinstall
} }
install_static() { install_archive() {
STATIC_INSTALL_PREFIX=${STATIC_INSTALL_PREFIX-/usr/local/lib}
echo "Installing static release v$VERSION" 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" 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
sh_c="sh_c" sh_c="sh_c"
if [ ! -w "$STATIC_INSTALL_PREFIX" ]; then if [ ! -w "$ARCHIVE_INSTALL_PREFIX" ]; then
sh_c="sudo_sh_c" sh_c="sudo_sh_c"
fi 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 echo
echoerr "code-server-$VERSION is already installed at $STATIC_INSTALL_PREFIX/lib/code-server-$VERSION" echo "code-server-$VERSION is already installed at $ARCHIVE_INSTALL_PREFIX/lib/code-server-$VERSION"
echoerr "Please remove it to reinstall." echo "Remove it to reinstall."
exit 1 exit 0
fi fi
"$sh_c" tar -C "$STATIC_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz" "$sh_c" tar -C "$ARCHIVE_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" 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 echo_static_postinstall
} }
install_npm() { install_npm() {
echoerr "No precompiled releases for $(uname -m)."
if command_exists yarn; then if command_exists yarn; then
echo "Installing with yarn." echo "Installing with yarn."
echo
sh_c yarn global add code-server --unsafe-perm sh_c yarn global add code-server --unsafe-perm
return return
elif command_exists npm; then elif command_exists npm; then
echo "Installing with npm." echo "Installing with npm."
echo
sh_c npm install -g code-server --unsafe-perm sh_c npm install -g code-server --unsafe-perm
return return
fi fi
echoerr echo
echoerr "Please install npm or yarn to install code-server!" 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" echoerr "See the docs https://github.com/cdr/code-server#yarn-npm"
exit 1 exit 1
} }
@ -402,7 +430,6 @@ command_exists() {
sh_c() { sh_c() {
if [ ! "${SKIP_ECHO-}" ]; then if [ ! "${SKIP_ECHO-}" ]; then
echo
echo "+ $*" echo "+ $*"
fi fi
if [ ! "${DRY_RUN-}" ]; then if [ ! "${DRY_RUN-}" ]; then
@ -421,7 +448,7 @@ sudo_sh_c() {
echo echo
echoerr "This script needs to run the following command as root." echoerr "This script needs to run the following command as root."
echoerr " $*" echoerr " $*"
echoerr "Please run this script as root or install sudo or su." echoerr "Please install sudo or su."
exit 1 exit 1
fi fi
} }