From 0cf437e542bc9e674052da002e4a3e5ed1be5cf5 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Wed, 6 Sep 2023 15:38:23 +0000 Subject: [PATCH 1/5] refactor: improve installation method detection --- install.sh | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/install.sh b/install.sh index 9831e0177545a..6070b0abab978 100755 --- a/install.sh +++ b/install.sh @@ -178,9 +178,11 @@ EOF main() { TERRAFORM_VERSION="1.3.4" + if [ "${TRACE-}" ]; then set -x fi + unset \ DRY_RUN \ METHOD \ @@ -188,9 +190,11 @@ main() { ALL_FLAGS \ RSH_ARGS \ EDGE \ - RSH + RSH \ + WITH_TERRAFORM ALL_FLAGS="" + while [ "$#" -gt 0 ]; do case "$1" in -*) @@ -245,7 +249,7 @@ main() { exit 0 ;; --with-terraform) - METHOD=with_terraform + WITH_TERRAFORM=1 ;; --) shift @@ -275,8 +279,22 @@ main() { return fi + # 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)} + TERRAFORM_ARCH=${TERRAFORM_ARCH:-$(terraform_arch)} + + # We can't reasonably support installing specific versions of Coder through + # Homebrew, so if we're on macOS and the `--version` flag was set, we should + # "detect" the best installation strategy to be standalone. This check needs + # to occur before we default `VERSION` to the latest release. + if [ "$OS" = "darwin" ] && [ "${VERSION-}" ]; then + METHOD=standalone + fi + METHOD="${METHOD-detect}" - if [ "$METHOD" != detect ] && [ "$METHOD" != with_terraform ] && [ "$METHOD" != standalone ]; then + if [ "$METHOD" != detect ] && [ "$METHOD" != standalone ]; then echoerr "Unknown install method \"$METHOD\"" echoerr "Run with --help to see usage." exit 1 @@ -289,11 +307,6 @@ main() { TERRAFORM_INSTALL_PREFIX=${TERRAFORM_INSTALL_PREFIX:-/usr/local} STANDALONE_BINARY_NAME=${STANDALONE_BINARY_NAME:-coder} 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)} - TERRAFORM_ARCH=${TERRAFORM_ARCH:-$(terraform_arch)} distro_name @@ -302,6 +315,11 @@ main() { echoh fi + # Start by installing Terraform, if requested + if [ "${WITH_TERRAFORM-}" = 1 ]; then + with_terraform + fi + # Standalone installs by pulling pre-built releases from GitHub. if [ "$METHOD" = standalone ]; then if has_standalone; then @@ -313,10 +331,6 @@ main() { exit 1 fi fi - if [ "$METHOD" = with_terraform ]; then - # Install terraform then continue the script - with_terraform - fi # DISTRO can be overridden for testing but shouldn't normally be used as it # can result in a broken coder. From 441719cd4f467a81465172132d6320edc255bcc4 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Wed, 6 Sep 2023 16:39:49 +0000 Subject: [PATCH 2/5] detect standalone path conflicts, better defaults --- install.sh | 63 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/install.sh b/install.sh index 6070b0abab978..ff768592026dd 100755 --- a/install.sh +++ b/install.sh @@ -104,18 +104,29 @@ Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/bin/$STAND EOF - if [ "$STANDALONE_INSTALL_PREFIX" != /usr/local ]; then + CODER_COMMAND="$(command -v "$STANDALONE_BINARY_NAME")" + + if [ ! "$CODER_COMMAND" ]; then cath < EOF + fi } echo_brew_postinstall() { @@ -125,7 +136,7 @@ echo_brew_postinstall() { fi cath < Date: Wed, 6 Sep 2023 16:43:27 +0000 Subject: [PATCH 3/5] detect homebrew conflicts --- install.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/install.sh b/install.sh index ff768592026dd..af754dd4a44a3 100755 --- a/install.sh +++ b/install.sh @@ -135,6 +135,13 @@ echo_brew_postinstall() { return fi + CODER_COMMAND="$(command -v "coder")" + BREW_PREFIX="$(brew --prefix)" + + if [ "$CODER_COMMAND" != "$BREW_PREFIX/bin/coder" ]; then + echo_path_conflict "$CODER_COMMAND" "$BREW_PREFIX" + fi + cath < Date: Wed, 6 Sep 2023 18:02:57 +0000 Subject: [PATCH 4/5] documentation! --- docs/install/install.sh.md | 81 ++++++++++++++++++++++++++++++++++++++ install.sh | 7 ++-- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/docs/install/install.sh.md b/docs/install/install.sh.md index 93c04d74d573f..4ae89e26257a3 100644 --- a/docs/install/install.sh.md +++ b/docs/install/install.sh.md @@ -34,6 +34,87 @@ manually via `coder server` or as a system package. By default, the Coder server runs on `http://127.0.0.1:3000` and uses a [public tunnel](../admin/configure.md#tunnel) for workspace connections. +## `PATH` conflicts + +It's possible to end up in situations where you have multiple `coder` +binaries in your `PATH`, and your system may use a version that you don't +intend. Your `PATH` is a variable that tells your shell where to look for +programs to run. + +You can check where all of the versions are by running `which -a coder`. + +For example, a common conflict on macOS might be between a version +installed by Homebrew, and a version installed manually to the /usr/local/bin +directory. + +```console +$ which -a coder +/usr/local/bin/coder +/opt/homebrew/bin/coder +``` + +Whichever binary comes first in this list will be used when running `coder` commands. + +### Reordering your `PATH` + +If you use bash or zsh, you can update your `PATH` like this: + +```shell +# You might want to add this line to the end of your ~/.bashrc or ~/.zshrc file! +export PATH="/opt/homebrew/bin:$PATH" +``` + +If you use fish, you can update your `PATH` like this: + +```shell +# You might want to add this line to the end of your ~/.config/fish/config.fish file! +fish_add_path "/opt/homebrew/bin" +``` + +> ℹ If you ran install.sh with a `--prefix` flag, you can replace `/opt/homebrew` +> with whatever value you used there. Make sure to leave the `/bin` at the end! + +Now we can observe that the order has changed: + +```console +$ which -a coder +/opt/homebrew/bin/coder +/usr/local/bin/coder +``` + +### Removing unneeded binaries + +If you want to uninstall a version of `coder` that you installed with a package manager, +you can run whichever one of these commands applies: + +```shell +# On macOS, with Homebrew installed +brew uninstall coder +``` + +```shell +# On Debian/Ubuntu based systems +sudo dpkg -r coder +``` + +```shell +# On Fedora/RHEL-like systems +sudo rpm -e coder +``` + +```shell +# On Alpine +sudo apk del coder +``` + +If the conflicting binary is not installed by your system package manager, +you can just delete it. + +```shell +# You might not need `sudo`, depending on the location +sudo rm /usr/local/bin/coder +``` + ## Next steps - [Configuring Coder](../admin/configure.md) diff --git a/install.sh b/install.sh index af754dd4a44a3..49f09a7ad1789 100755 --- a/install.sh +++ b/install.sh @@ -175,7 +175,6 @@ To run a Coder server: # Or just run the server directly $ coder server - Default URL: http://127.0.0.1:3000 Configuring Coder: https://coder.com/docs/v2/latest/admin/configure To connect to a Coder deployment: @@ -196,13 +195,13 @@ EOF echo_path_conflict() { cath < Date: Wed, 6 Sep 2023 18:10:44 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=A7=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/install/install.sh.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/install/install.sh.md b/docs/install/install.sh.md index 4ae89e26257a3..9eb253f35839f 100644 --- a/docs/install/install.sh.md +++ b/docs/install/install.sh.md @@ -36,16 +36,14 @@ By default, the Coder server runs on `http://127.0.0.1:3000` and uses a ## `PATH` conflicts -It's possible to end up in situations where you have multiple `coder` -binaries in your `PATH`, and your system may use a version that you don't -intend. Your `PATH` is a variable that tells your shell where to look for -programs to run. +It's possible to end up in situations where you have multiple `coder` binaries +in your `PATH`, and your system may use a version that you don't intend. Your +`PATH` is a variable that tells your shell where to look for programs to run. You can check where all of the versions are by running `which -a coder`. -For example, a common conflict on macOS might be between a version -installed by Homebrew, and a version installed manually to the /usr/local/bin -directory. +For example, a common conflict on macOS might be between a version installed by +Homebrew, and a version installed manually to the /usr/local/bin directory. ```console $ which -a coder @@ -53,7 +51,8 @@ $ which -a coder /opt/homebrew/bin/coder ``` -Whichever binary comes first in this list will be used when running `coder` commands. +Whichever binary comes first in this list will be used when running `coder` +commands. ### Reordering your `PATH` @@ -71,8 +70,9 @@ If you use fish, you can update your `PATH` like this: fish_add_path "/opt/homebrew/bin" ``` -> ℹ If you ran install.sh with a `--prefix` flag, you can replace `/opt/homebrew` -> with whatever value you used there. Make sure to leave the `/bin` at the end! +> ℹ If you ran install.sh with a `--prefix` flag, you can replace +> `/opt/homebrew` with whatever value you used there. Make sure to leave the +> `/bin` at the end! Now we can observe that the order has changed: @@ -84,8 +84,8 @@ $ which -a coder ### Removing unneeded binaries -If you want to uninstall a version of `coder` that you installed with a package manager, -you can run whichever one of these commands applies: +If you want to uninstall a version of `coder` that you installed with a package +manager, you can run whichever one of these commands applies: ```shell # On macOS, with Homebrew installed @@ -107,8 +107,8 @@ sudo rpm -e coder sudo apk del coder ``` -If the conflicting binary is not installed by your system package manager, -you can just delete it. +If the conflicting binary is not installed by your system package manager, you +can just delete it. ```shell # You might not need `sudo`, depending on the location