From 510d84898c4ecfca8df9787653507cd5cc08c8de Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 21 May 2020 15:17:02 -0400 Subject: [PATCH] install.sh: Add our own flag parser Fully supports long opts! --- .github/ISSUE_TEMPLATE/bug-report.md | 7 +- .github/ISSUE_TEMPLATE/extension-request.md | 3 +- .github/ISSUE_TEMPLATE/feature-request.md | 5 +- README.md | 48 ++++- ci/dev/fmt.sh | 1 + doc/install.md | 36 +++- install.sh | 205 ++++++++++++++------ 7 files changed, 220 insertions(+), 85 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 10ed7edd..a9d70644 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -1,10 +1,9 @@ --- name: Bug report about: Report a bug and help us improve -title: '' -labels: '' -assignees: '' - +title: "" +labels: "" +assignees: "" --- + # Install +- [Debian, Ubuntu](#debian-ubuntu) +- [Fedora, CentOS, RHEL, SUSE](#fedora-centos-rhel-suse) +- [Arch Linux](#arch-linux) +- [yarn, npm](#yarn-npm) +- [macOS](#macos) +- [Static Releases](#static-releases) +- [Docker](#docker) + + + This document demonstrates how to install `code-server` on various distros and operating systems. @@ -20,7 +32,7 @@ systemctl --user enable --now code-server # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` -## Fedora, CentOS, Red Hat, SUSE +## Fedora, CentOS, RHEL, SUSE ```bash curl -fOL https://github.com/cdr/code-server/releases/download/v3.3.1/code-server-3.3.1-amd64.rpm @@ -49,8 +61,11 @@ systemctl --user enable --now code-server ## yarn, npm -We recommend installing with `yarn` or `npm` if we don't have a precompiled release for your machine's -platform or architecture or your glibc < v2.19. +We recommend installing with `yarn` or `npm` if: + +1. We don't have a precompiled release for your machine's platform or architecture. +2. libc < v2.19 +3. libcxx < 3.4.20 **note:** Installing via `yarn` or `npm` builds native modules on install and so requires C dependencies. See [./doc/npm.md](./doc/npm.md) for installing these dependencies. @@ -81,15 +96,22 @@ They bundle the node binary and node_modules. 2. Unpack the release. 3. You can run code-server by executing `./bin/code-server`. -Add the code-server `bin` directory to your `$PATH` to easily execute `code-server` without the full path every time. +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. Here is an example script for installing and using a static `code-server` release on Linux: ```bash +mkdir -p ~/.local/lib ~/.local/bin curl -fL https://github.com/cdr/code-server/releases/download/v3.3.1/code-server-3.3.1-linux-amd64.tar.gz \ - | sudo tar -C /usr/local/lib -xz -sudo mv /usr/local/lib/code-server-3.3.1-linux-amd64 /usr/local/lib/code-server-3.3.1 -PATH="/usr/local/lib/code-server-3.3.1/bin:$PATH" + | tar -C ~/.local/lib -xz +mv ~/.local/lib/code-server-3.3.1-linux-amd64 ~/.local/lib/code-server-3.3.1 +ln -s ~/.local/lib/code-server-3.3.1/bin/code-server ~/.local/bin/code-server +PATH="~/.local/bin:$PATH" code-server # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` + +## Docker + +Documented in [README.md](../README.md#docker). diff --git a/install.sh b/install.sh index c37798ee..110a4916 100755 --- a/install.sh +++ b/install.sh @@ -1,47 +1,54 @@ #!/bin/sh set -eu -VERSION=3.3.1 - usage() { - cat << EOF -$0 [-d] [-s] [-p ] + cat <=~/.local] -Installs code-server on any macOS or Linux system. +Installs latest code-server on any macOS or Linux system preferring to use the OS package manager. -If ran on Ubuntu, Debian or Raspbian then the GitHub releases v$VERSION -deb package will be fetched and installed. + curl -fsSL https://code-server.dev/install.sh | sh -s -- -If ran on Fedora, CentOS, RHEL or openSUSE then the GitHub releases v$VERSION -rpm package will be fetched and installed. +- For Debian, Ubuntu, Raspbian it will install the latest deb package. +- For Fedora, CentOS, RHEL, 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. -If ran on macOS and Homebrew is installed then the Homebrew code-server -package will be installed. However, if Homebrew is not installed then -v$VERSION of the macOS static release will be installed -into /usr/local/lib/code-server-$VERSION. +- 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 Arch Linux, then the code-server AUR package will be installed. +- If ran on an architecture with no binary releases or outdated libc/libcxx, it will install the + npm package with yarn or npm. + - We only have binary releases for amd64 and arm64 presently. -If ran on an unsupported architecture the npm package will be installed -with yarn or npm. Only amd64 and arm64 are currently supported. + --dry-run Enables a dry run where where the steps that would have taken place + are printed but do not actually execute. -If ran on any other Linux distro, v$VERSION of the linux static release -will be installed into /usr/local/lib/code-server-$VERSION. + --version Pass to install a specific version instead of the latest release. - -d Enables a dry run where where the steps that would have taken place - are printed but do not actually execute. + --static Forces the installation of a static release into ~/.local - -s Forces the installation of a static release into /usr/local/lib/code-server-$VERSION - Set the -p flag to change the installation prefix from /usr/local/lib + This flag takes an optional argument for the installation prefix which defaults to "~/.local". + code-server will be unarchived into ~/.local/lib/code-server.X.X.X and the binary will be symlinked + into "~/.local/bin/code-server". You will need to add ~/.local/bin to your \$PATH to use it without + the full path. - -p Sets the installation prefix for a static release install. + To install system wide set the prefix to /usr/local. EOF - exit 1 +} + +echo_latest_version() { + version="$(curl -fsSL https://api.github.com/repos/cdr/code-server/releases/latest | jq -r .tag_name)" + # Strip leading v. + version="${version:1}" + echo "$version" } echo_static_postinstall() { echo - cat << EOF + cat < /dev/null 2>&1 + command -v "$@" >/dev/null 2>&1 } sh_c() { @@ -325,14 +408,14 @@ sudo_sh_c() { sh_c "su -c '$*'" else echo - echo "This script needs to run the following command as root." - echo " $*" - echo "Please run this script as root or install sudo or su." + echoerr "This script needs to run the following command as root." + echoerr " $*" + echoerr "Please run this script as root or install sudo or su." exit 1 fi } -cache_dir() { +echo_cache_dir() { if [ "${XDG_CACHE_HOME-}" ]; then echo "$XDG_CACHE_HOME/code-server" elif [ "${HOME-}" ]; then @@ -342,4 +425,8 @@ cache_dir() { fi } +echoerr() { + echo "$@" >&2 +} + main "$@"