From d1a5c67562bd7aaeccc2daf301a9e04157e630a8 Mon Sep 17 00:00:00 2001 From: Kayla Washburn Date: Wed, 6 Sep 2023 12:57:28 -0600 Subject: [PATCH 1/5] refactor: improve flag interpretation for install.sh (#9554) --- docs/install/install.sh.md | 81 ++++++++++++++++++++++++++++ install.sh | 105 +++++++++++++++++++++++++++---------- 2 files changed, 159 insertions(+), 27 deletions(-) diff --git a/docs/install/install.sh.md b/docs/install/install.sh.md index 7b278676a9fae..a6afafdc5a41d 100644 --- a/docs/install/install.sh.md +++ b/docs/install/install.sh.md @@ -27,6 +27,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 9831e0177545a..49f09a7ad1789 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() { @@ -124,8 +135,15 @@ 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: Thu, 7 Sep 2023 18:16:27 +0000 Subject: [PATCH 2/5] fix bug in install.sh, clean up output a bit more --- install.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index 49f09a7ad1789..732bc92da11c2 100755 --- a/install.sh +++ b/install.sh @@ -100,13 +100,15 @@ echo_standalone_postinstall() { cath < Date: Thu, 7 Sep 2023 18:16:46 +0000 Subject: [PATCH 3/5] use local version of install.sh in e2e tests --- site/e2e/helpers.ts | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/site/e2e/helpers.ts b/site/e2e/helpers.ts index 04bb326183db2..f7e20e68f18bc 100644 --- a/site/e2e/helpers.ts +++ b/site/e2e/helpers.ts @@ -263,45 +263,37 @@ export const downloadCoderVersion = async ( return binaryPath; } - // Runs our public install script using our options to - // install the binary! + // Run our official install script to install the binary await new Promise((resolve, reject) => { const cp = spawn( - "sh", + path.join(__dirname, "../../install.sh"), [ - "-c", - [ - "curl", - "-L", - "https://coder.com/install.sh", - "|", - "sh", - "-s", - "--", - "--version", - version, - "--method", - "standalone", - "--prefix", - tempDir, - "--binary-name", - binaryName, - ].join(" "), + "--version", + version, + "--method", + "standalone", + "--prefix", + tempDir, + "--binary-name", + binaryName, ], { env: { ...process.env, XDG_CACHE_HOME: "/tmp/coder-e2e-cache", + TRACE: "1", // tells install.sh to `set -x`, helpful if something goes wrong }, }, ); // eslint-disable-next-line no-console -- Needed for debugging - cp.stderr.on("data", (data) => console.log(data.toString())); + cp.stderr.on("data", (data) => console.error(data.toString())); + // eslint-disable-next-line no-console -- Needed for debugging + cp.stdout.on("data", (data) => console.log(data.toString())); cp.on("close", (code) => { if (code === 0) { resolve(); } else { - reject(new Error("curl failed with code " + code)); + reject(new Error("install.sh failed with code " + code)); } }); }); From e2f037200b2d49ca5eac430d4df97d5f634e3e7a Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Thu, 7 Sep 2023 18:17:10 +0000 Subject: [PATCH 4/5] fix doc titles --- docs/install/install.sh.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/install/install.sh.md b/docs/install/install.sh.md index a6afafdc5a41d..ab23cec5731c6 100644 --- a/docs/install/install.sh.md +++ b/docs/install/install.sh.md @@ -27,7 +27,7 @@ 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 +## 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 @@ -47,7 +47,7 @@ $ which -a coder Whichever binary comes first in this list will be used when running `coder` commands. -### Reordering your `PATH` +### Reordering your PATH If you use bash or zsh, you can update your `PATH` like this: From 003126657eb9f71d39ff3174c8f4625aa16e6091 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Thu, 7 Sep 2023 18:29:29 +0000 Subject: [PATCH 5/5] fix typo --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 732bc92da11c2..ba75e358f71c5 100755 --- a/install.sh +++ b/install.sh @@ -208,7 +208,7 @@ There is another binary in your PATH that conflicts with the binary we've instal $1 -This is likely because of an existing installation of Coder. See our documentation for suggests on how to resolve this. +This is likely because of an existing installation of Coder. See our documentation for suggestions on how to resolve this. https://coder.com/docs/v2/latest/install/install.sh#path-conflicts