#!/bin/sh set -eu # code-server's automatic install script. # See https://github.com/cdr/code-server/blob/v3.9.2/docs/install.md usage() { arg0="$0" if [ "$0" = sh ]; then arg0="curl -fsSL https://code-server.dev/install.sh | sh -s --" else not_curl_usage="The latest script is available at https://code-server.dev/install.sh " fi cath < Sets the prefix used by standalone 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 --rsh Specifies the remote shell for remote installation. Defaults to ssh. - 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 standalone release into ~/.local - For macOS it will install the Homebrew package. - If Homebrew is not installed it will install the latest standalone release into ~/.local - For FreeBSD, it will install the npm package with yarn or npm. - If ran on an architecture with no releases, it will install the npm package with yarn or npm. - We only have releases for amd64 and arm64 presently. - The npm package builds the native modules on postinstall. It will cache all downloaded assets into ~/.cache/code-server More installation docs are at https://github.com/cdr/code-server/blob/v3.9.2/docs/install.md EOF } echo_latest_version() { # https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860 version="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/cdr/code-server/releases/latest)" version="${version#https://github.com/cdr/code-server/releases/tag/}" version="${version#v}" echo "$version" } echo_npm_postinstall() { echoh cath < macos # - freebsd -> freebsd # - ubuntu, raspbian, debian ... -> debian # - amzn, centos, rhel, fedora, ... -> fedora # - opensuse-{leap,tumbleweed} -> opensuse # - alpine -> alpine # - arch -> arch # # Inspired by https://github.com/docker/docker-install/blob/26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c/install.sh#L111-L120. distro() { if [ "$OS" = "macos" ] || [ "$OS" = "freebsd" ]; then echo "$OS" return fi if [ -f /etc/os-release ]; then ( . /etc/os-release if [ "${ID_LIKE-}" ]; then for id_like in $ID_LIKE; do case "$id_like" in debian | fedora | opensuse) echo "$id_like" return ;; esac done fi echo "$ID" ) return fi } # os_name prints a pretty human readable name for the OS/Distro. distro_name() { if [ "$(uname)" = "Darwin" ]; then echo "macOS v$(sw_vers -productVersion)" return fi if [ -f /etc/os-release ]; then ( . /etc/os-release echo "$PRETTY_NAME" ) return fi # Prints something like: Linux 4.19.0-9-amd64 uname -sr } arch() { case "$(uname -m)" in aarch64) echo arm64 ;; x86_64) echo amd64 ;; amd64) # FreeBSD. echo amd64 ;; esac } command_exists() { command -v "$@" >/dev/null } sh_c() { echoh "+ $*" if [ ! "${DRY_RUN-}" ]; then sh -c "$*" fi } sudo_sh_c() { if [ "$(id -u)" = 0 ]; then sh_c "$@" elif command_exists sudo; then sh_c "sudo $*" elif command_exists su; then sh_c "su - -c '$*'" else echoh echoerr "This script needs to run the following command as root." echoerr " $*" echoerr "Please install sudo or su." exit 1 fi } echo_cache_dir() { if [ "${XDG_CACHE_HOME-}" ]; then echo "$XDG_CACHE_HOME/code-server" elif [ "${HOME-}" ]; then echo "$HOME/.cache/code-server" else echo "/tmp/code-server-cache" fi } echoh() { echo "$@" | humanpath } cath() { humanpath } echoerr() { echoh "$@" >&2 } # humanpath replaces all occurances of " $HOME" with " ~" # and all occurances of '"$HOME' with the literal '"$HOME'. humanpath() { sed "s# $HOME# ~#g; s#\"$HOME#\"\$HOME#g" } # We need to make sure we exit with a non zero exit if the command fails. # /bin/sh does not support -o pipefail unfortunately. prefix() { PREFIX="$1" shift fifo="$(mktemp -d)/fifo" mkfifo "$fifo" sed -e "s#^#$PREFIX: #" "$fifo" & "$@" >"$fifo" 2>&1 } main "$@"