From 006a805cbb429b71b0ea48e20d2e95ac053b7ec8 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 16:26:24 +0000 Subject: [PATCH 01/21] feat: one-line install script --- install.sh | 564 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 564 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000000000..a2c6803a993ed --- /dev/null +++ b/install.sh @@ -0,0 +1,564 @@ +#!/bin/sh +set -eu + +# Coder's automatic install script. + +usage() { + arg0="$0" + if [ "$0" = sh ]; then + arg0="curl -fsSL https://coder.com/install.sh | sh -s --" + else + not_curl_usage="The latest script is available at https://coder.com/install.sh +" + fi + + cath << EOF +Installs Coder. +It tries to use the system package manager if possible. +After successful installation it explains how to start Coder. + +Pass in user@host to install Coder on user@host over ssh. +The remote host must have internet access. +${not_curl_usage-} +Usage: + + $arg0 [--dry-run] [--version X.X.X] [--edge] [--method detect] \ + [--prefix ~/.local] [--rsh ssh] [user@host] + + --dry-run + Echo the commands for the install process without running them. + + --version X.X.X + Install a specific version instead of the latest. + + --edge + Install the latest edge version instead of the latest stable version. + + --method [detect | standalone] + 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. + - standalone installs a standalone release archive into ~/.local + Add ~/.local/bin to your \$PATH to use it. + + --prefix + Sets the prefix used by standalone release archives. Defaults to ~/.local + The release is unarchived into ~/.local/lib/coder-X.X.X + and the binary symlinked into ~/.local/bin/coder + To install system wide pass ---prefix=/usr/local + + --rsh + Specifies the remote shell for remote installation. Defaults to ssh. + +The detection method works as follows: + - Debian, Ubuntu, Raspbian: install the deb package from GitHub. + - Fedora, CentOS, RHEL, openSUSE: install the rpm package from GitHub. + - Alpine: install the apk package from GitHub. + - macOS: install the release from GitHub. + - All others: install the release from GitHub. + +We build releases on GitHub for amd64, armv7, and arm64 on Windows, Linux, and macOS. + +When the detection method tries to pull a release from GitHub it will +fall back to installing standalone when there is no matching release for +the system's operating system and architecture. + +The installer will cache all downloaded assets into ~/.cache/coder +EOF +} + +echo_latest_version() { + if [ "${EDGE-}" ]; then + version="$(curl -fsSL https://api.github.com/repos/coder/coder/releases | awk 'match($0,/.*"html_url": "(.*\/releases\/tag\/.*)".*/)' | head -n 1 | awk -F '"' '{print $4}')" + else + # https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860 + version="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/coder/coder/releases/latest)" + fi + version="${version#https://github.com/coder/coder/releases/tag/}" + version="${version#v}" + echo "$version" +} + +echo_standalone_postinstall() { + echoh + cath << EOF +Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/lib/coder-$VERSION + +Extend your path to use coder: + PATH="$STANDALONE_INSTALL_PREFIX/bin:\$PATH" +Then run with: + coder +EOF +} + +echo_brew_postinstall() { + echoh + cath << EOF +Brew release has been installed. + +Run with: + coder +EOF +} + +echo_systemd_postinstall() { + echoh + cath << EOF +$1 package has been installed. + +To have systemd start coder now and restart on boot: + sudo systemctl enable --now coder@\$USER +Or, if you don't want/need a background service you can run: + coder +EOF +} + +main() { + if [ "${TRACE-}" ]; then + set -x + fi + + unset \ + DRY_RUN \ + METHOD \ + OPTIONAL \ + ALL_FLAGS \ + RSH_ARGS \ + EDGE \ + RSH + + ALL_FLAGS="" + while [ "$#" -gt 0 ]; do + case "$1" in + -*) + ALL_FLAGS="${ALL_FLAGS} $1" + ;; + esac + + case "$1" in + --dry-run) + DRY_RUN=1 + ;; + --method) + METHOD="$(parse_arg "$@")" + shift + ;; + --method=*) + METHOD="$(parse_arg "$@")" + ;; + --prefix) + STANDALONE_INSTALL_PREFIX="$(parse_arg "$@")" + shift + ;; + --prefix=*) + STANDALONE_INSTALL_PREFIX="$(parse_arg "$@")" + ;; + --version) + VERSION="$(parse_arg "$@")" + shift + ;; + --version=*) + VERSION="$(parse_arg "$@")" + ;; + --edge) + EDGE=1 + ;; + --rsh) + RSH="$(parse_arg "$@")" + shift + ;; + --rsh=*) + RSH="$(parse_arg "$@")" + ;; + -h | --h | -help | --help) + usage + exit 0 + ;; + --) + shift + # We remove the -- added above. + ALL_FLAGS="${ALL_FLAGS% --}" + RSH_ARGS="$*" + break + ;; + -*) + echoerr "Unknown flag $1" + echoerr "Run with --help to see usage." + exit 1 + ;; + *) + RSH_ARGS="$*" + break + ;; + esac + + shift + done + + if [ "${RSH_ARGS-}" ]; then + RSH="${RSH-ssh}" + echoh "Installing remotely with $RSH $RSH_ARGS" + curl -fsSL https://coder.dev/install.sh | prefix "$RSH_ARGS" "$RSH" "$RSH_ARGS" sh -s -- "$ALL_FLAGS" + return + fi + + METHOD="${METHOD-detect}" + if [ "$METHOD" != detect ] && [ "$METHOD" != standalone ]; then + echoerr "Unknown install method \"$METHOD\"" + echoerr "Run with --help to see usage." + exit 1 + fi + + # These are used by the various install_* functions that make use of GitHub + # releases in order to download and unpack the right release. + CACHE_DIR=$(echo_cache_dir) + STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-$HOME/.local} + VERSION=${VERSION:-$(echo_latest_version)} + # These can be overridden for testing but shouldn't normally be used as it can + # result in a broken coder. + OS=${OS:-$(os)} + ARCH=${ARCH:-$(arch)} + + distro_name + + # Standalone installs by pulling pre-built releases from GitHub. + if [ "$METHOD" = standalone ]; then + if has_standalone; then + install_standalone + exit 0 + else + echoerr "There are no standalone releases for $ARCH" + echoerr "Please try again without '--method standalone'" + exit 1 + fi + fi + + # DISTRO can be overridden for testing but shouldn't normally be used as it + # can result in a broken coder. + DISTRO=${DISTRO:-$(distro)} + + case $DISTRO in + # macOS uses brew when available and falls back to standalone. + macos) + BREW_PATH="${BREW_PATH-brew}" + if command_exists "$BREW_PATH"; then + install_brew + else + echoh "Homebrew not installed." + echoh "Falling back to standalone installation." + install_standalone + fi + ;; + # The .deb and .rpm files are pulled from GitHub. + debian) install_deb ;; + fedora | opensuse) install_rpm ;; + # Arch uses the AUR package which only supports amd64 and arm64 since it + # pulls releases from GitHub so we need to fall back to npm. + arch) install_aur ;; + # We don't have GitHub releases that work on Alpine or FreeBSD so we have no + # choice but to use npm here. + alpine) install_apk ;; + # For anything else we'll try to install standalone but fall back to npm if + # we don't have releases for the architecture. + *) + echoh "Unsupported package manager." + echoh "Falling back to standalone installation." + install_standalone + ;; + esac +} + +parse_arg() { + case "$1" in + *=*) + # Remove everything after first equal sign. + opt="${1%%=*}" + # Remove everything before first equal sign. + optarg="${1#*=}" + if [ ! "$optarg" ] && [ ! "${OPTIONAL-}" ]; then + echoerr "$opt requires an argument" + echoerr "Run with --help to see usage." + exit 1 + fi + echo "$optarg" + return + ;; + esac + + case "${2-}" in + "" | -*) + if [ ! "${OPTIONAL-}" ]; then + echoerr "$1 requires an argument" + echoerr "Run with --help to see usage." + exit 1 + fi + ;; + *) + echo "$2" + return + ;; + esac +} + +fetch() { + URL="$1" + FILE="$2" + + if [ -e "$FILE" ]; then + echoh "+ Reusing $FILE" + return + fi + + sh_c mkdir -p "$CACHE_DIR" + sh_c curl \ + -#fL \ + -o "$FILE.incomplete" \ + -C - \ + "$URL" + sh_c mv "$FILE.incomplete" "$FILE" +} + +install_brew() { + echoh "Installing latest from Homebrew." + echoh + + sh_c "$BREW_PATH" install coder + + echo_brew_postinstall +} + +install_deb() { + echoh "Installing v$VERSION of the $ARCH deb package from GitHub." + echoh + + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_$ARCH.deb" \ + "$CACHE_DIR/coder_${VERSION}_$ARCH.deb" + sudo_sh_c dpkg -i "$CACHE_DIR/coder_${VERSION}_$ARCH.deb" + + echo_systemd_postinstall deb +} + +install_rpm() { + echoh "Installing v$VERSION of the $ARCH rpm package from GitHub." + echoh + + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_$VERSION_$ARCH.rpm" \ + "$CACHE_DIR/coder_$VERSION_$ARCH.rpm" + sudo_sh_c rpm -i "$CACHE_DIR/coder_$VERSION_$ARCH.rpm" + + echo_systemd_postinstall rpm +} + +install_apk() { + echoh "Installing v$VERSION of the $ARCH apk package from GitHub." + echoh + + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_$VERSION_$ARCH.apk" \ + "$CACHE_DIR/coder_$VERSION_$ARCH.apk" + sudo_sh_c apk add --allow-untrusted "$CACHE_DIR/coder_$VERSION_$ARCH.apk" + + echo_systemd_postinstall apk +} + +install_aur() { + echoh "Installing latest from the AUR." + echoh + + sh_c mkdir -p "$CACHE_DIR/coder-aur" + sh_c "curl -#fsSL https://aur.archlinux.org/cgit/aur.git/snapshot/coder.tar.gz | tar -xzC $CACHE_DIR/coder-aur --strip-components 1" + echo "+ cd $CACHE_DIR/coder-aur" + if [ ! "${DRY_RUN-}" ]; then + cd "$CACHE_DIR/coder-aur" + fi + sh_c makepkg -si + + echo_systemd_postinstall AUR +} + +install_standalone() { + echoh "Installing v$VERSION of the $ARCH release from GitHub." + echoh + + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_$VERSION_$OS_$ARCH.tar.gz" \ + "$CACHE_DIR/coder_$VERSION_$OS_$ARCH.tar" + + # -w only works if the directory exists so try creating it first. If this + # fails we can ignore the error as the -w check will then swap us to sudo. + sh_c mkdir -p "$STANDALONE_INSTALL_PREFIX" 2> /dev/null || true + + sh_c="sh_c" + if [ ! -w "$STANDALONE_INSTALL_PREFIX" ]; then + sh_c="sudo_sh_c" + fi + + if [ -e "$STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION" ]; then + echoh + echoh "coder_$VERSION is already installed at $STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION" + echoh "Remove it to reinstall." + exit 0 + fi + + "$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/lib" "$STANDALONE_INSTALL_PREFIX/bin" + "$sh_c" tar -C "$STANDALONE_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/coder_$VERSION_$OS_$ARCH.tar" + "$sh_c" mv -f "$STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION_$OS_$ARCH" "$STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION" + "$sh_c" ln -fs "$STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION/bin/coder" "$STANDALONE_INSTALL_PREFIX/bin/coder" + + echo_standalone_postinstall +} + +# Determine if we have standalone releases on GitHub for the system's arch. +has_standalone() { + case $ARCH in + amd64) return 0 ;; + # We only have amd64 for macOS. + arm64) + [ "$(distro)" != macos ] + return + ;; + *) return 1 ;; + esac +} + +os() { + uname="$(uname)" + case $uname in + Linux) echo linux ;; + Darwin) echo macos ;; + FreeBSD) echo freebsd ;; + *) echo "$uname" ;; + esac +} + +# Print the detected Linux distro, otherwise print the OS name. +# +# Example outputs: +# - macos -> 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 +} + +# Print a 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() { + uname_m=$(uname -m) + case $uname_m in + aarch64) echo arm64 ;; + x86_64) echo amd64 ;; + *) echo "$uname_m" ;; + esac +} + +command_exists() { + if [ ! "$1" ]; then return 1; fi + 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/coder" + elif [ "${HOME-}" ]; then + echo "$HOME/.cache/coder" + else + echo "/tmp/coder-cache" + fi +} + +echoh() { + echo "$@" | humanpath +} + +cath() { + humanpath +} + +echoerr() { + echoh "$@" >&2 +} + +# humanpath replaces all occurrences of " $HOME" with " ~" +# and all occurrences 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 "$@" From 2724aefb7595d1b391d819fbaf7a628a00701a8b Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 16:36:05 +0000 Subject: [PATCH 02/21] remove homebrew support --- install.sh | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/install.sh b/install.sh index a2c6803a993ed..890d174a20072 100644 --- a/install.sh +++ b/install.sh @@ -91,16 +91,6 @@ Then run with: EOF } -echo_brew_postinstall() { - echoh - cath << EOF -Brew release has been installed. - -Run with: - coder -EOF -} - echo_systemd_postinstall() { echoh cath << EOF @@ -238,17 +228,9 @@ main() { DISTRO=${DISTRO:-$(distro)} case $DISTRO in - # macOS uses brew when available and falls back to standalone. - macos) - BREW_PATH="${BREW_PATH-brew}" - if command_exists "$BREW_PATH"; then - install_brew - else - echoh "Homebrew not installed." - echoh "Falling back to standalone installation." - install_standalone - fi - ;; + # macOS uses the standalone installation for now. + # Homebrew support is planned. See: https://github.com/coder/coder/issues/1925 + macos) install_standalone ;; # The .deb and .rpm files are pulled from GitHub. debian) install_deb ;; fedora | opensuse) install_rpm ;; @@ -318,15 +300,6 @@ fetch() { sh_c mv "$FILE.incomplete" "$FILE" } -install_brew() { - echoh "Installing latest from Homebrew." - echoh - - sh_c "$BREW_PATH" install coder - - echo_brew_postinstall -} - install_deb() { echoh "Installing v$VERSION of the $ARCH deb package from GitHub." echoh From f7a5ee8ffffc8d819abea846aa0c11b9e48eb250 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 16:39:38 +0000 Subject: [PATCH 03/21] remove arch linux --- install.sh | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/install.sh b/install.sh index 890d174a20072..dfc581ec5661b 100644 --- a/install.sh +++ b/install.sh @@ -234,9 +234,6 @@ main() { # The .deb and .rpm files are pulled from GitHub. debian) install_deb ;; fedora | opensuse) install_rpm ;; - # Arch uses the AUR package which only supports amd64 and arm64 since it - # pulls releases from GitHub so we need to fall back to npm. - arch) install_aur ;; # We don't have GitHub releases that work on Alpine or FreeBSD so we have no # choice but to use npm here. alpine) install_apk ;; @@ -333,21 +330,6 @@ install_apk() { echo_systemd_postinstall apk } -install_aur() { - echoh "Installing latest from the AUR." - echoh - - sh_c mkdir -p "$CACHE_DIR/coder-aur" - sh_c "curl -#fsSL https://aur.archlinux.org/cgit/aur.git/snapshot/coder.tar.gz | tar -xzC $CACHE_DIR/coder-aur --strip-components 1" - echo "+ cd $CACHE_DIR/coder-aur" - if [ ! "${DRY_RUN-}" ]; then - cd "$CACHE_DIR/coder-aur" - fi - sh_c makepkg -si - - echo_systemd_postinstall AUR -} - install_standalone() { echoh "Installing v$VERSION of the $ARCH release from GitHub." echoh From c3505ed0541272a25d9b1015922a94ffc2f18259 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 16:55:16 +0000 Subject: [PATCH 04/21] use proper filename for packages --- install.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index dfc581ec5661b..bd3e4822c2dd0 100644 --- a/install.sh +++ b/install.sh @@ -301,7 +301,7 @@ install_deb() { echoh "Installing v$VERSION of the $ARCH deb package from GitHub." echoh - fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_$ARCH.deb" \ + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_$OS_$ARCH.deb" \ "$CACHE_DIR/coder_${VERSION}_$ARCH.deb" sudo_sh_c dpkg -i "$CACHE_DIR/coder_${VERSION}_$ARCH.deb" @@ -312,9 +312,9 @@ install_rpm() { echoh "Installing v$VERSION of the $ARCH rpm package from GitHub." echoh - fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_$VERSION_$ARCH.rpm" \ - "$CACHE_DIR/coder_$VERSION_$ARCH.rpm" - sudo_sh_c rpm -i "$CACHE_DIR/coder_$VERSION_$ARCH.rpm" + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_$OS_$ARCH.rpm" \ + "$CACHE_DIR/coder_${VERSION}_$OS_$ARCH.rpm" + sudo_sh_c rpm -i "$CACHE_DIR/coder_${VERSION}_$OS_$ARCH.rpm" echo_systemd_postinstall rpm } @@ -323,9 +323,9 @@ install_apk() { echoh "Installing v$VERSION of the $ARCH apk package from GitHub." echoh - fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_$VERSION_$ARCH.apk" \ - "$CACHE_DIR/coder_$VERSION_$ARCH.apk" - sudo_sh_c apk add --allow-untrusted "$CACHE_DIR/coder_$VERSION_$ARCH.apk" + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_$OS_$ARCH.apk" \ + "$CACHE_DIR/coder_${VERSION}_$OS_$ARCH.apk" + sudo_sh_c apk add --allow-untrusted "$CACHE_DIR/coder_${VERSION}_$OS_$ARCH.apk" echo_systemd_postinstall apk } From 5d236005af9e9134a10c23f39bce94833e4022c2 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 16:56:32 +0000 Subject: [PATCH 05/21] fix variable format --- install.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index bd3e4822c2dd0..af4c7fdbf4703 100644 --- a/install.sh +++ b/install.sh @@ -301,7 +301,7 @@ install_deb() { echoh "Installing v$VERSION of the $ARCH deb package from GitHub." echoh - fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_$OS_$ARCH.deb" \ + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_${OS}_${ARCH}.deb" \ "$CACHE_DIR/coder_${VERSION}_$ARCH.deb" sudo_sh_c dpkg -i "$CACHE_DIR/coder_${VERSION}_$ARCH.deb" @@ -312,9 +312,9 @@ install_rpm() { echoh "Installing v$VERSION of the $ARCH rpm package from GitHub." echoh - fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_$OS_$ARCH.rpm" \ - "$CACHE_DIR/coder_${VERSION}_$OS_$ARCH.rpm" - sudo_sh_c rpm -i "$CACHE_DIR/coder_${VERSION}_$OS_$ARCH.rpm" + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_${OS}_${ARCH}.rpm" \ + "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.rpm" + sudo_sh_c rpm -i "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.rpm" echo_systemd_postinstall rpm } @@ -323,9 +323,9 @@ install_apk() { echoh "Installing v$VERSION of the $ARCH apk package from GitHub." echoh - fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_$OS_$ARCH.apk" \ - "$CACHE_DIR/coder_${VERSION}_$OS_$ARCH.apk" - sudo_sh_c apk add --allow-untrusted "$CACHE_DIR/coder_${VERSION}_$OS_$ARCH.apk" + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_${OS}_${ARCH}.apk" \ + "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.apk" + sudo_sh_c apk add --allow-untrusted "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.apk" echo_systemd_postinstall apk } From 936c4665f0bb198cf338dc091bcab45b10dabf41 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 17:48:44 +0000 Subject: [PATCH 06/21] fix systemd instructions --- install.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index af4c7fdbf4703..20975c23a082c 100644 --- a/install.sh +++ b/install.sh @@ -96,10 +96,18 @@ echo_systemd_postinstall() { cath << EOF $1 package has been installed. -To have systemd start coder now and restart on boot: - sudo systemctl enable --now coder@\$USER -Or, if you don't want/need a background service you can run: - coder +To run Coder as a system service: + + # Configure the PostgreSQL database for Coder + sudo vim /etc/coder.d/coder.env + + # Have systemd start Coder now and restart on boot + sudo systemctl enable --now coder + +Or, run a temporary deployment (all data is in-memory +and destroyed on exit): + + coder server --dev EOF } From 086e30e786b77462321a378839171793d80eec7e Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 17:52:38 +0000 Subject: [PATCH 07/21] fixes to standalone script --- install.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 20975c23a082c..d9c212b1ac297 100644 --- a/install.sh +++ b/install.sh @@ -86,8 +86,12 @@ Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/lib/coder- Extend your path to use coder: PATH="$STANDALONE_INSTALL_PREFIX/bin:\$PATH" -Then run with: - coder +Then run Coder (temporary): + coder server --dev +Or run a production deployment with PostgreSQL: + CODER_PG_CONNECTION_URL="postgres://@/?password=" \ + coder server + EOF } @@ -100,7 +104,6 @@ To run Coder as a system service: # Configure the PostgreSQL database for Coder sudo vim /etc/coder.d/coder.env - # Have systemd start Coder now and restart on boot sudo systemctl enable --now coder @@ -108,6 +111,7 @@ Or, run a temporary deployment (all data is in-memory and destroyed on exit): coder server --dev + EOF } @@ -342,8 +346,8 @@ install_standalone() { echoh "Installing v$VERSION of the $ARCH release from GitHub." echoh - fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_$VERSION_$OS_$ARCH.tar.gz" \ - "$CACHE_DIR/coder_$VERSION_$OS_$ARCH.tar" + fetch "https://github.com/coder/coder/releases/download/v$VERSION/coder_${VERSION}_${OS}_${ARCH}.tar.gz" \ + "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar" # -w only works if the directory exists so try creating it first. If this # fails we can ignore the error as the -w check will then swap us to sudo. From 3a65b94ab8352588bb950eb2bfc3b211fba5e74c Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 17:54:25 +0000 Subject: [PATCH 08/21] fix missing var bugs --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index d9c212b1ac297..52c66b932e6a1 100644 --- a/install.sh +++ b/install.sh @@ -366,8 +366,8 @@ install_standalone() { fi "$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/lib" "$STANDALONE_INSTALL_PREFIX/bin" - "$sh_c" tar -C "$STANDALONE_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/coder_$VERSION_$OS_$ARCH.tar" - "$sh_c" mv -f "$STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION_$OS_$ARCH" "$STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION" + "$sh_c" tar -C "$STANDALONE_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/coder_$${VERSION}_${OS}_${ARCH}.tar" + "$sh_c" mv -f "$STANDALONE_INSTALL_PREFIX/lib/coder_$${VERSION}_${OS}_${ARCH}" "$STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION" "$sh_c" ln -fs "$STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION/bin/coder" "$STANDALONE_INSTALL_PREFIX/bin/coder" echo_standalone_postinstall From 26ab8677d167fa868630a41f553b1d045e9a6385 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 18:02:50 +0000 Subject: [PATCH 09/21] fix standalone install --- install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 52c66b932e6a1..61ac981165317 100644 --- a/install.sh +++ b/install.sh @@ -84,8 +84,9 @@ echo_standalone_postinstall() { cath << EOF Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/lib/coder-$VERSION -Extend your path to use coder: +Extend your path to use Coder: PATH="$STANDALONE_INSTALL_PREFIX/bin:\$PATH" + Then run Coder (temporary): coder server --dev Or run a production deployment with PostgreSQL: @@ -366,9 +367,8 @@ install_standalone() { fi "$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/lib" "$STANDALONE_INSTALL_PREFIX/bin" - "$sh_c" tar -C "$STANDALONE_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/coder_$${VERSION}_${OS}_${ARCH}.tar" - "$sh_c" mv -f "$STANDALONE_INSTALL_PREFIX/lib/coder_$${VERSION}_${OS}_${ARCH}" "$STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION" - "$sh_c" ln -fs "$STANDALONE_INSTALL_PREFIX/lib/coder_$VERSION/bin/coder" "$STANDALONE_INSTALL_PREFIX/bin/coder" + "$sh_c" tar -C "$STANDALONE_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar" + "$sh_c" ln -fs "$STANDALONE_INSTALL_PREFIX/lib/coder/bin/coder" "$STANDALONE_INSTALL_PREFIX/bin/coder" echo_standalone_postinstall } From 356808598f5ffdc3657f3777812e8fdf9907946f Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 18:47:37 +0000 Subject: [PATCH 10/21] fix for MacOS --- install.sh | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/install.sh b/install.sh index 61ac981165317..7c15bdf83cfd8 100644 --- a/install.sh +++ b/install.sh @@ -81,8 +81,8 @@ echo_latest_version() { echo_standalone_postinstall() { echoh - cath << EOF -Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/lib/coder-$VERSION + cath < macos +# - darwin -> darwin # - freebsd -> freebsd # - ubuntu, raspbian, debian ... -> debian # - amzn, centos, rhel, fedora, ... -> fedora @@ -409,7 +415,7 @@ os() { # # Inspired by https://github.com/docker/docker-install/blob/26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c/install.sh#L111-L120. distro() { - if [ "$OS" = "macos" ] || [ "$OS" = "freebsd" ]; then + if [ "$OS" = "darwin" ] || [ "$OS" = "freebsd" ]; then echo "$OS" return fi From a022e3b74d9a5013514667629fa919d20b2d3937 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 18:47:51 +0000 Subject: [PATCH 11/21] format --- install.sh | 232 ++++++++++++++++++++++++++--------------------------- 1 file changed, 116 insertions(+), 116 deletions(-) diff --git a/install.sh b/install.sh index 7c15bdf83cfd8..f4c82296f00e6 100644 --- a/install.sh +++ b/install.sh @@ -12,7 +12,7 @@ usage() { " fi - cath << EOF + cath < /dev/null || true + sh_c mkdir -p "$STANDALONE_INSTALL_PREFIX" 2>/dev/null || true sh_c="sh_c" if [ ! -w "$STANDALONE_INSTALL_PREFIX" ]; then @@ -382,23 +382,23 @@ install_standalone() { # TODO: fix for Coder v2 has_standalone() { case $ARCH in - amd64) return 0 ;; - # We only have amd64 for macOS. - arm64) - [ "$(distro)" != darwin ] - return - ;; - *) return 1 ;; + amd64) return 0 ;; + # We only have amd64 for macOS. + arm64) + [ "$(distro)" != darwin ] + return + ;; + *) return 1 ;; esac } os() { uname="$(uname)" case $uname in - Linux) echo linux ;; - Darwin) echo darwin ;; - FreeBSD) echo freebsd ;; - *) echo "$uname" ;; + Linux) echo linux ;; + Darwin) echo darwin ;; + FreeBSD) echo freebsd ;; + *) echo "$uname" ;; esac } @@ -461,15 +461,15 @@ distro_name() { arch() { uname_m=$(uname -m) case $uname_m in - aarch64) echo arm64 ;; - x86_64) echo amd64 ;; - *) echo "$uname_m" ;; + aarch64) echo arm64 ;; + x86_64) echo amd64 ;; + *) echo "$uname_m" ;; esac } command_exists() { if [ ! "$1" ]; then return 1; fi - command -v "$@" > /dev/null + command -v "$@" >/dev/null } sh_c() { @@ -531,7 +531,7 @@ prefix() { fifo="$(mktemp -d)/fifo" mkfifo "$fifo" sed -e "s#^#$PREFIX: #" "$fifo" & - "$@" > "$fifo" 2>&1 + "$@" >"$fifo" 2>&1 } main "$@" From 038dc8c17d3aa3f67365256b90b7c9cf225b71a3 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 19:32:24 +0000 Subject: [PATCH 12/21] fix armv7 assets and zips --- install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index f4c82296f00e6..e122e28d34ed7 100644 --- a/install.sh +++ b/install.sh @@ -367,7 +367,7 @@ install_standalone() { fi "$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/bin" - if [ "$STANDALONE_ARCHIVE_FORMAT" == tar.gz ]; then + if [ "$STANDALONE_ARCHIVE_FORMAT" = tar.gz ]; then "$sh_c" tar -C "$CACHE_DIR" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar.gz" else "$sh_c" unzip -d "$CACHE_DIR" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip" @@ -383,8 +383,8 @@ install_standalone() { has_standalone() { case $ARCH in amd64) return 0 ;; - # We only have amd64 for macOS. - arm64) + ard64) return 0 ;; + armv7) [ "$(distro)" != darwin ] return ;; @@ -463,6 +463,7 @@ arch() { case $uname_m in aarch64) echo arm64 ;; x86_64) echo amd64 ;; + armv7l) echo armv7 ;; *) echo "$uname_m" ;; esac } From fa59da0a49941ee1f6367224ed00ab2e4b114906 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 31 May 2022 19:44:14 +0000 Subject: [PATCH 13/21] remove windows --- install.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install.sh b/install.sh index e122e28d34ed7..117c864e31f05 100644 --- a/install.sh +++ b/install.sh @@ -347,10 +347,9 @@ install_standalone() { echoh "Installing v$VERSION of the $ARCH release from GitHub." echoh - # MacOS and Windows releases are packaged as .zip + # MacOS releases are packaged as .zip case $OS in darwin) STANDALONE_ARCHIVE_FORMAT=zip ;; - windows) STANDALONE_ARCHIVE_FORMAT=zip ;; *) STANDALONE_ARCHIVE_FORMAT=tar.gz ;; esac From bec55847845c178e1d9418377bb13347164a7040 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 1 Jun 2022 03:34:48 +0000 Subject: [PATCH 14/21] update install docs --- README.md | 51 ++++++++++-------------------- docs/install.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ install.sh | 2 +- 3 files changed, 100 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 17cc962d845af..1c6876efb6f8c 100644 --- a/README.md +++ b/README.md @@ -56,47 +56,30 @@ You can use any Web IDE ([code-server](https://github.com/coder/code-server), [p ## Installing Coder -We recommend installing [the latest -release](https://github.com/coder/coder/releases) on a system with at least 1 -CPU core and 2 GB RAM: +There are a few ways to install Coder: -1. Download the [release asset](https://github.com/coder/coder/releases) appropriate for your operating system -1. Unzip the folder you just downloaded, and move the `coder` executable to a location that's on your `PATH` +- [install script](./docs/install.md#installsh) (MacOS & Linux). The script uses the system package manager if possible. +- with [system packages](./docs/install.md#system-packages) (Debian, Fedora, Alpine) +- with [Docker or docker-compose](./docs/install.md#docker-compose) (MacOS, Windows, Linux) +- [manually](./docs/install.md#manual) (MacOS, Windows, Linux) - ```sh - # ex. MacOS and Linux - mv coder /usr/local/bin - ``` +If you use the install script, you can preview what occurs during the install process: - Windows: see [this guide](https://answers.microsoft.com/en-us/windows/forum/all/adding-path-variable/97300613-20cb-4d85-8d0e-cc9d3549ba23) on adding a folder to `PATH` - -There are a few ways to run Coder: - -- To run a **temporary deployment**, start with dev mode (all data is in-memory and destroyed on exit): - - ```bash - coder server --dev - ``` - -- To run a **production deployment** with PostgreSQL: - - ```bash - CODER_PG_CONNECTION_URL="postgres://@/?password=" \ - coder server - ``` +```sh +curl -fsSL https://coder.com/install.sh | sh -s -- --dry-run +``` -- To run as a **system service**, install with `.deb` (Debian, Ubuntu) or `.rpm` (Fedora, CentOS, RHEL, SUSE): +To install, run: - ```bash - # Edit the configuration! - sudo vim /etc/coder.d/coder.env - sudo service coder restart - ``` +```sh +curl -fsSL https://coder.com/install.sh | sh +``` - > macOS and Windows users: You'll need to write your own - > configuration to run Coder as a system service. +Once installed, you can run a temporary deployment in dev mode (all data is in-memory and destroyed on exit): -- See the [installation guide](./docs/install.md) for additional ways to run Coder (e.g., docker-compose) +```sh +coder server --dev +``` Use `coder --help` to get a complete list of flags and environment variables. diff --git a/docs/install.md b/docs/install.md index 04e680448f705..de56fa3572bd6 100644 --- a/docs/install.md +++ b/docs/install.md @@ -2,6 +2,58 @@ This article walks you through the various ways of installing and deploying Coder. +## install.sh + +The easiest way to install Coder is to use our [install script](https://github.com/coder/coder/main/install.sh) for Linux and macOS. The install script +attempts to use the system package manager detection-reference if possible. + +You can preview what occurs during the install process: + +```bash +curl -fsSL https://coder.com/install.sh | sh -s -- --dry-run +``` + +To install, run: + +```bash +curl -fsSL https://coder.com/install.sh | sh +``` + +> If you're concerned about the install script's use of `curl | sh` and the +> security implications, please see [this blog +> post](https://sandstorm.io/news/2015-09-24-is-curl-bash-insecure-pgp-verified-install) +> by [sandstorm.io](https://sandstorm.io). + +You can modify the installation process by including flags. Run the help command for reference: + +```bash +curl -fsSL https://coder.com/install.sh | sh -s -- --help +``` + +## System packages + +Coder publishes the following system packages [in GitHub releases](https://github.com/coder/coder/releases): + +- .deb (Debian, Ubuntu) +- .rpm (Fedora, CentOS, RHEL, SUSE) +- .apk (Alpine) + +Once installed, you can run Coder as a system service: + +```sh +# Specify a PostgreSQL database +# in the configuration first: +sudo vim /etc/coder.d/coder.env +sudo service coder restart +``` + +Or run a **temporary deployment** with dev mode (all data is in-memory and destroyed on exit): + + +```sh +coder server --dev +``` + ## docker-compose Before proceeding, please ensure that you have both Docker and the [latest version of @@ -99,3 +151,33 @@ access URL, or you can connect to it via SSH by running: ```console coder ssh [workspace name] ``` + +## Manual + +We publish self-contained .zip and .tar.gz archives in [GitHub releases](https://github.com/coder/coder/releases). The archives bundle `coder` binary. + +1. Download the [release archive](https://github.com/coder/coder/releases) appropriate for your operating system + +1. Unzip the folder you just downloaded, and move the `coder` executable to a location that's on your `PATH` + + ```sh + # ex. MacOS and Linux + mv coder /usr/local/bin + ``` + + > Windows users: see [this guide](https://answers.microsoft.com/en-us/windows/forum/all/adding-path-variable/97300613-20cb-4d85-8d0e-cc9d3549ba23) for adding folders to `PATH`. + +1. Start a Coder server + + To run a **temporary deployment**, start with dev mode (all data is in-memory and destroyed on exit): + + ```bash + coder server --dev + ``` + + To run a **production deployment** with PostgreSQL: + + ```bash + CODER_PG_CONNECTION_URL="postgres://@/?password=" \ + coder server + ``` diff --git a/install.sh b/install.sh index 117c864e31f05..993bd42c39f8c 100644 --- a/install.sh +++ b/install.sh @@ -2,6 +2,7 @@ set -eu # Coder's automatic install script. +# See https://github.com/coder/coder#installing-coder usage() { arg0="$0" @@ -378,7 +379,6 @@ install_standalone() { } # Determine if we have standalone releases on GitHub for the system's arch. -# TODO: fix for Coder v2 has_standalone() { case $ARCH in amd64) return 0 ;; From c308d60b4aeb92eb6e2ff6a1f87789359e1013b3 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 1 Jun 2022 04:00:33 +0000 Subject: [PATCH 15/21] support external sources with shellcheck --- Makefile | 2 +- docs/install.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 61fb4a5537bde..917f21b306556 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ lint/go: # Use shfmt to determine the shell files, takes editorconfig into consideration. lint/shellcheck: $(shell shfmt -f .) @echo "--- shellcheck" - shellcheck $(shell shfmt -f .) + shellcheck -x $(shell shfmt -f .) peerbroker/proto/peerbroker.pb.go: peerbroker/proto/peerbroker.proto protoc \ diff --git a/docs/install.md b/docs/install.md index de56fa3572bd6..fd5b120627628 100644 --- a/docs/install.md +++ b/docs/install.md @@ -10,13 +10,13 @@ attempts to use the system package manager detection-reference if possible. You can preview what occurs during the install process: ```bash -curl -fsSL https://coder.com/install.sh | sh -s -- --dry-run +curl -L https://coder.com/install.sh | sh -s -- --dry-run ``` To install, run: ```bash -curl -fsSL https://coder.com/install.sh | sh +curl -L https://coder.com/install.sh | sh ``` > If you're concerned about the install script's use of `curl | sh` and the @@ -27,7 +27,7 @@ curl -fsSL https://coder.com/install.sh | sh You can modify the installation process by including flags. Run the help command for reference: ```bash -curl -fsSL https://coder.com/install.sh | sh -s -- --help +curl -L https://coder.com/install.sh | sh -s -- --help ``` ## System packages From 898921120c78503424c6d440f71bbe78a6678873 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 1 Jun 2022 04:01:12 +0000 Subject: [PATCH 16/21] shfmt --- install.sh | 686 ++++++++++++++++++++++++++--------------------------- 1 file changed, 343 insertions(+), 343 deletions(-) diff --git a/install.sh b/install.sh index 993bd42c39f8c..e35d615fe617a 100644 --- a/install.sh +++ b/install.sh @@ -5,15 +5,15 @@ set -eu # See https://github.com/coder/coder#installing-coder usage() { - arg0="$0" - if [ "$0" = sh ]; then - arg0="curl -fsSL https://coder.com/install.sh | sh -s --" - else - not_curl_usage="The latest script is available at https://coder.com/install.sh + arg0="$0" + if [ "$0" = sh ]; then + arg0="curl -fsSL https://coder.com/install.sh | sh -s --" + else + not_curl_usage="The latest script is available at https://coder.com/install.sh " - fi + fi - cath </dev/null || true + # -w only works if the directory exists so try creating it first. If this + # fails we can ignore the error as the -w check will then swap us to sudo. + sh_c mkdir -p "$STANDALONE_INSTALL_PREFIX" 2>/dev/null || true - sh_c="sh_c" - if [ ! -w "$STANDALONE_INSTALL_PREFIX" ]; then - sh_c="sudo_sh_c" - fi + sh_c="sh_c" + if [ ! -w "$STANDALONE_INSTALL_PREFIX" ]; then + sh_c="sudo_sh_c" + fi - "$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/bin" - if [ "$STANDALONE_ARCHIVE_FORMAT" = tar.gz ]; then - "$sh_c" tar -C "$CACHE_DIR" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar.gz" - else - "$sh_c" unzip -d "$CACHE_DIR" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip" - fi + "$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/bin" + if [ "$STANDALONE_ARCHIVE_FORMAT" = tar.gz ]; then + "$sh_c" tar -C "$CACHE_DIR" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar.gz" + else + "$sh_c" unzip -d "$CACHE_DIR" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip" + fi - "$sh_c" cp "$CACHE_DIR/coder" "$STANDALONE_INSTALL_PREFIX/bin/coder" + "$sh_c" cp "$CACHE_DIR/coder" "$STANDALONE_INSTALL_PREFIX/bin/coder" - echo_standalone_postinstall + echo_standalone_postinstall } # Determine if we have standalone releases on GitHub for the system's arch. has_standalone() { - case $ARCH in - amd64) return 0 ;; - ard64) return 0 ;; - armv7) - [ "$(distro)" != darwin ] - return - ;; - *) return 1 ;; - esac + case $ARCH in + amd64) return 0 ;; + ard64) return 0 ;; + armv7) + [ "$(distro)" != darwin ] + return + ;; + *) return 1 ;; + esac } os() { - uname="$(uname)" - case $uname in - Linux) echo linux ;; - Darwin) echo darwin ;; - FreeBSD) echo freebsd ;; - *) echo "$uname" ;; - esac + uname="$(uname)" + case $uname in + Linux) echo linux ;; + Darwin) echo darwin ;; + FreeBSD) echo freebsd ;; + *) echo "$uname" ;; + esac } # Print the detected Linux distro, otherwise print the OS name. @@ -414,124 +414,124 @@ os() { # # Inspired by https://github.com/docker/docker-install/blob/26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c/install.sh#L111-L120. distro() { - if [ "$OS" = "darwin" ] || [ "$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 + if [ "$OS" = "darwin" ] || [ "$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 } # Print a 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 + 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() { - uname_m=$(uname -m) - case $uname_m in - aarch64) echo arm64 ;; - x86_64) echo amd64 ;; - armv7l) echo armv7 ;; - *) echo "$uname_m" ;; - esac + uname_m=$(uname -m) + case $uname_m in + aarch64) echo arm64 ;; + x86_64) echo amd64 ;; + armv7l) echo armv7 ;; + *) echo "$uname_m" ;; + esac } command_exists() { - if [ ! "$1" ]; then return 1; fi - command -v "$@" >/dev/null + if [ ! "$1" ]; then return 1; fi + command -v "$@" >/dev/null } sh_c() { - echoh "+ $*" - if [ ! "${DRY_RUN-}" ]; then - sh -c "$*" - fi + 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 + 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/coder" - elif [ "${HOME-}" ]; then - echo "$HOME/.cache/coder" - else - echo "/tmp/coder-cache" - fi + if [ "${XDG_CACHE_HOME-}" ]; then + echo "$XDG_CACHE_HOME/coder" + elif [ "${HOME-}" ]; then + echo "$HOME/.cache/coder" + else + echo "/tmp/coder-cache" + fi } echoh() { - echo "$@" | humanpath + echo "$@" | humanpath } cath() { - humanpath + humanpath } echoerr() { - echoh "$@" >&2 + echoh "$@" >&2 } # humanpath replaces all occurrences of " $HOME" with " ~" # and all occurrences of '"$HOME' with the literal '"$HOME'. humanpath() { - sed "s# $HOME# ~#g; s#\"$HOME#\"\$HOME#g" + 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 + PREFIX="$1" + shift + fifo="$(mktemp -d)/fifo" + mkfifo "$fifo" + sed -e "s#^#$PREFIX: #" "$fifo" & + "$@" >"$fifo" 2>&1 } main "$@" From cf1912a6c1159170904b653fa6e6be0afccf9c16 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 1 Jun 2022 04:06:53 +0000 Subject: [PATCH 17/21] add external sources to GitHub action & unfold --- .github/workflows/coder.yaml | 2 ++ Makefile | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coder.yaml b/.github/workflows/coder.yaml index 6a32d6babc1aa..398c7e6c8210b 100644 --- a/.github/workflows/coder.yaml +++ b/.github/workflows/coder.yaml @@ -52,6 +52,8 @@ jobs: - uses: actions/checkout@v3 - name: Run ShellCheck uses: ludeeus/action-shellcheck@1.1.0 + env: + SHELLCHECK_OPTS: --external-sources with: ignore: node_modules diff --git a/Makefile b/Makefile index 917f21b306556..a75a9cb2884c9 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ lint/go: # Use shfmt to determine the shell files, takes editorconfig into consideration. lint/shellcheck: $(shell shfmt -f .) @echo "--- shellcheck" - shellcheck -x $(shell shfmt -f .) + shellcheck --external-sources $(shell shfmt -f .) peerbroker/proto/peerbroker.pb.go: peerbroker/proto/peerbroker.proto protoc \ From a611c7b1d69148926d6f1ce017209c8cde378981 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 1 Jun 2022 14:41:00 +0000 Subject: [PATCH 18/21] change wording --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 1c6876efb6f8c..2b6ab2ad62bfb 100644 --- a/README.md +++ b/README.md @@ -56,12 +56,7 @@ You can use any Web IDE ([code-server](https://github.com/coder/code-server), [p ## Installing Coder -There are a few ways to install Coder: - -- [install script](./docs/install.md#installsh) (MacOS & Linux). The script uses the system package manager if possible. -- with [system packages](./docs/install.md#system-packages) (Debian, Fedora, Alpine) -- with [Docker or docker-compose](./docs/install.md#docker-compose) (MacOS, Windows, Linux) -- [manually](./docs/install.md#manual) (MacOS, Windows, Linux) +There are a few ways to install Coder: [install script](./docs/install.md#installsh) (macOS, Linux), [docker-compose](./docs/install.md#docker-compose), or [manually](./docs/install.md#manual) via the latest release (macOS, Windows, and Linux). If you use the install script, you can preview what occurs during the install process: From a16a04a4a38a8b5160a9ac4aed4c394eacaadc1a Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 1 Jun 2022 14:41:55 +0000 Subject: [PATCH 19/21] first template docs --- docs/install.md | 60 +------------------------------------------------ 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/docs/install.md b/docs/install.md index fd5b120627628..5f055f7224513 100644 --- a/docs/install.md +++ b/docs/install.md @@ -92,65 +92,7 @@ Coder](https://github.com/coder/coder/releases) installed. ghcr.io/coder/coder:v0.5.10 ``` -1. Open a new terminal window, and run `coder login ` to create - your first user (once you've done so, you can navigate to `yourAccessURL` and - log in with these credentials). - -1. Next, copy a sample template into a new directory so that you can create a custom template in a - subsequent step (be sure that you're working in the directory where you want - your templates stored): - - ```console - coder templates init - ``` - - Choose the "Develop in Docker" example to generate a sample template in the - `docker` subdirectory. - -1. Navigate into the new directory and create a new template: - - ```console - cd docker - coder templates create - ``` - - Follow the prompts displayed to proceed. When done, you'll see the following - message: - - ```console - The docker template has been created! Developers can - provision a workspace with this template using: - - coder create --template="docker" [workspace name] - ``` - -1. At this point, you're ready to provision your first workspace: - - ```console - coder create --template="docker" [workspace name] - ``` - - Follow the on-screen prompts to set the parameters for your workspace. If - the process is successful, you'll get information regarding your workspace: - - ```console - ┌─────────────────────────────────────────────────────────────────┐ - │ RESOURCE STATUS ACCESS │ - ├─────────────────────────────────────────────────────────────────┤ - │ docker_container.workspace ephemeral │ - │ └─ dev (linux, amd64) ⦾ connecting [0s] coder ssh main │ - ├─────────────────────────────────────────────────────────────────┤ - │ docker_volume.coder_volume ephemeral │ - └─────────────────────────────────────────────────────────────────┘ - The main workspace has been created! - ``` - -You can now access your workspace via your web browser by navigating to your -access URL, or you can connect to it via SSH by running: - -```console -coder ssh [workspace name] -``` +1. Follow the on-screen instructions to create your first template and workspace ## Manual From 6879752d98a39007591102667a0f1781d7738e6e Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 1 Jun 2022 17:33:25 +0000 Subject: [PATCH 20/21] default to /usr/local instead --- install.sh | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) mode change 100644 => 100755 install.sh diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index e35d615fe617a..3c5fe98594b12 --- a/install.sh +++ b/install.sh @@ -39,14 +39,12 @@ Usage: 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. - - standalone installs a standalone release archive into ~/.local - Add ~/.local/bin to your \$PATH to use it. + - standalone installs a standalone release archive into /usr/local/bin --prefix - Sets the prefix used by standalone release archives. Defaults to ~/.local - The release is unarchived into ~/.local/lib/coder-X.X.X - and the binary symlinked into ~/.local/bin/coder - To install system wide pass ---prefix=/usr/local + Sets the prefix used by standalone release archives. Defaults to /usr/local + and the binary is copied into /usr/local/bin + To install in \$HOME, pass ---prefix=\$HOME/.local --rsh Specifies the remote shell for remote installation. Defaults to ssh. @@ -81,17 +79,27 @@ echo_latest_version() { } echo_standalone_postinstall() { - echoh - cath < Date: Wed, 1 Jun 2022 17:50:32 +0000 Subject: [PATCH 21/21] add option for binary name --- install.sh | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/install.sh b/install.sh index 3c5fe98594b12..795c1af367bc6 100755 --- a/install.sh +++ b/install.sh @@ -45,6 +45,11 @@ Usage: Sets the prefix used by standalone release archives. Defaults to /usr/local and the binary is copied into /usr/local/bin To install in \$HOME, pass ---prefix=\$HOME/.local + + --binary-name + Sets the name for the CLI in standalone release archives. Defaults to "coder" + To use the CLI as coder2, pass --binary-name=coder2 + Note: in-product documentation will always refer to the CLI as "coder" --rsh Specifies the remote shell for remote installation. Defaults to ssh. @@ -79,16 +84,13 @@ echo_latest_version() { } echo_standalone_postinstall() { - if [ "$STANDALONE_INSTALL_PREFIX" = /usr/local ]; then - cath <