Skip to content

Commit 8421f56

Browse files
authored
refactor: bring back updated install.sh with patches (#9583)
1 parent ccda1c5 commit 8421f56

File tree

3 files changed

+184
-51
lines changed

3 files changed

+184
-51
lines changed

docs/install/install.sh.md

+81
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,87 @@ manually via `coder server` or as a system package.
2727
By default, the Coder server runs on `http://127.0.0.1:3000` and uses a
2828
[public tunnel](../admin/configure.md#tunnel) for workspace connections.
2929

30+
## PATH conflicts
31+
32+
It's possible to end up in situations where you have multiple `coder` binaries
33+
in your `PATH`, and your system may use a version that you don't intend. Your
34+
`PATH` is a variable that tells your shell where to look for programs to run.
35+
36+
You can check where all of the versions are by running `which -a coder`.
37+
38+
For example, a common conflict on macOS might be between a version installed by
39+
Homebrew, and a version installed manually to the /usr/local/bin directory.
40+
41+
```console
42+
$ which -a coder
43+
/usr/local/bin/coder
44+
/opt/homebrew/bin/coder
45+
```
46+
47+
Whichever binary comes first in this list will be used when running `coder`
48+
commands.
49+
50+
### Reordering your PATH
51+
52+
If you use bash or zsh, you can update your `PATH` like this:
53+
54+
```shell
55+
# You might want to add this line to the end of your ~/.bashrc or ~/.zshrc file!
56+
export PATH="/opt/homebrew/bin:$PATH"
57+
```
58+
59+
If you use fish, you can update your `PATH` like this:
60+
61+
```shell
62+
# You might want to add this line to the end of your ~/.config/fish/config.fish file!
63+
fish_add_path "/opt/homebrew/bin"
64+
```
65+
66+
> ℹ If you ran install.sh with a `--prefix` flag, you can replace
67+
> `/opt/homebrew` with whatever value you used there. Make sure to leave the
68+
> `/bin` at the end!
69+
70+
Now we can observe that the order has changed:
71+
72+
```console
73+
$ which -a coder
74+
/opt/homebrew/bin/coder
75+
/usr/local/bin/coder
76+
```
77+
78+
### Removing unneeded binaries
79+
80+
If you want to uninstall a version of `coder` that you installed with a package
81+
manager, you can run whichever one of these commands applies:
82+
83+
```shell
84+
# On macOS, with Homebrew installed
85+
brew uninstall coder
86+
```
87+
88+
```shell
89+
# On Debian/Ubuntu based systems
90+
sudo dpkg -r coder
91+
```
92+
93+
```shell
94+
# On Fedora/RHEL-like systems
95+
sudo rpm -e coder
96+
```
97+
98+
```shell
99+
# On Alpine
100+
sudo apk del coder
101+
```
102+
103+
If the conflicting binary is not installed by your system package manager, you
104+
can just delete it.
105+
106+
```shell
107+
# You might not need `sudo`, depending on the location
108+
sudo rm /usr/local/bin/coder
109+
```
110+
30111
## Next steps
31112

32113
- [Configuring Coder](../admin/configure.md)

install.sh

+88-28
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,35 @@ echo_standalone_postinstall() {
100100

101101
cath <<EOF
102102
103-
Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME
103+
Coder has been installed to
104+
105+
$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME
104106
105107
EOF
106108

107-
if [ "$STANDALONE_INSTALL_PREFIX" != /usr/local ]; then
109+
CODER_COMMAND="$(command -v "$STANDALONE_BINARY_NAME" || true)"
110+
111+
if [ -z "${CODER_COMMAND}" ]; then
108112
cath <<EOF
109113
Extend your path to use Coder:
110-
PATH="$STANDALONE_INSTALL_PREFIX/bin:\$PATH"
114+
115+
$ PATH="$STANDALONE_INSTALL_PREFIX/bin:\$PATH"
111116
112117
EOF
113-
fi
114-
cath <<EOF
115-
Run Coder:
116-
$STANDALONE_BINARY_NAME server
118+
elif [ "$CODER_COMMAND" != "$STANDALONE_BINARY_LOCATION" ]; then
119+
echo_path_conflict "$CODER_COMMAND"
120+
else
121+
cath <<EOF
122+
To run a Coder server:
123+
124+
$ $STANDALONE_BINARY_NAME server
125+
126+
To connect to a Coder deployment:
127+
128+
$ $STANDALONE_BINARY_NAME login <deployment url>
117129
118130
EOF
131+
fi
119132
}
120133

121134
echo_brew_postinstall() {
@@ -124,9 +137,23 @@ echo_brew_postinstall() {
124137
return
125138
fi
126139

140+
BREW_PREFIX="$(brew --prefix)"
141+
127142
cath <<EOF
128-
brew formula has been installed.
129143
144+
Coder has been installed to
145+
146+
$BREW_PREFIX/bin/coder
147+
148+
EOF
149+
150+
CODER_COMMAND="$(command -v "coder" || true)"
151+
152+
if [ "$CODER_COMMAND" != "$BREW_PREFIX/bin/coder" ]; then
153+
echo_path_conflict "$CODER_COMMAND"
154+
fi
155+
156+
cath <<EOF
130157
To run a Coder server:
131158
132159
$ coder server
@@ -157,7 +184,6 @@ To run a Coder server:
157184
# Or just run the server directly
158185
$ coder server
159186
160-
Default URL: http://127.0.0.1:3000
161187
Configuring Coder: https://coder.com/docs/v2/latest/admin/configure
162188
163189
To connect to a Coder deployment:
@@ -169,28 +195,45 @@ EOF
169195

170196
echo_dryrun_postinstall() {
171197
cath <<EOF
172-
173198
Dry-run complete.
174199
175200
To install Coder, re-run this script without the --dry-run flag.
201+
202+
EOF
203+
}
204+
205+
echo_path_conflict() {
206+
cath <<EOF
207+
There is another binary in your PATH that conflicts with the binary we've installed.
208+
209+
$1
210+
211+
This is likely because of an existing installation of Coder. See our documentation for suggestions on how to resolve this.
212+
213+
https://coder.com/docs/v2/latest/install/install.sh#path-conflicts
214+
176215
EOF
177216
}
178217

179218
main() {
180219
TERRAFORM_VERSION="1.3.4"
220+
181221
if [ "${TRACE-}" ]; then
182222
set -x
183223
fi
224+
184225
unset \
185226
DRY_RUN \
186227
METHOD \
187228
OPTIONAL \
188229
ALL_FLAGS \
189230
RSH_ARGS \
190231
EDGE \
191-
RSH
232+
RSH \
233+
WITH_TERRAFORM
192234

193235
ALL_FLAGS=""
236+
194237
while [ "$#" -gt 0 ]; do
195238
case "$1" in
196239
-*)
@@ -245,7 +288,7 @@ main() {
245288
exit 0
246289
;;
247290
--with-terraform)
248-
METHOD=with_terraform
291+
WITH_TERRAFORM=1
249292
;;
250293
--)
251294
shift
@@ -275,8 +318,29 @@ main() {
275318
return
276319
fi
277320

321+
# These can be overridden for testing but shouldn't normally be used as it can
322+
# result in a broken coder.
323+
OS=${OS:-$(os)}
324+
ARCH=${ARCH:-$(arch)}
325+
TERRAFORM_ARCH=${TERRAFORM_ARCH:-$(terraform_arch)}
326+
327+
# We can't reasonably support installing specific versions of Coder through
328+
# Homebrew, so if we're on macOS and the `--version` flag was set, we should
329+
# "detect" standalone to be the appropriate installation method. This check
330+
# needs to occur before we set `VERSION` to a default of the latest release.
331+
if [ "$OS" = "darwin" ] && [ "${VERSION-}" ]; then
332+
METHOD=standalone
333+
fi
334+
335+
# If we've been provided a flag which is specific to the standalone installation
336+
# method, we should "detect" standalone to be the appropriate installation method.
337+
# This check needs to occur before we set these variables with defaults.
338+
if [ "${STANDALONE_INSTALL_PREFIX-}" ] || [ "${STANDALONE_BINARY_NAME-}" ]; then
339+
METHOD=standalone
340+
fi
341+
278342
METHOD="${METHOD-detect}"
279-
if [ "$METHOD" != detect ] && [ "$METHOD" != with_terraform ] && [ "$METHOD" != standalone ]; then
343+
if [ "$METHOD" != detect ] && [ "$METHOD" != standalone ]; then
280344
echoerr "Unknown install method \"$METHOD\""
281345
echoerr "Run with --help to see usage."
282346
exit 1
@@ -285,15 +349,10 @@ main() {
285349
# These are used by the various install_* functions that make use of GitHub
286350
# releases in order to download and unpack the right release.
287351
CACHE_DIR=$(echo_cache_dir)
288-
STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-/usr/local}
289352
TERRAFORM_INSTALL_PREFIX=${TERRAFORM_INSTALL_PREFIX:-/usr/local}
353+
STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-/usr/local}
290354
STANDALONE_BINARY_NAME=${STANDALONE_BINARY_NAME:-coder}
291355
VERSION=${VERSION:-$(echo_latest_version)}
292-
# These can be overridden for testing but shouldn't normally be used as it can
293-
# result in a broken coder.
294-
OS=${OS:-$(os)}
295-
ARCH=${ARCH:-$(arch)}
296-
TERRAFORM_ARCH=${TERRAFORM_ARCH:-$(terraform_arch)}
297356

298357
distro_name
299358

@@ -302,6 +361,11 @@ main() {
302361
echoh
303362
fi
304363

364+
# Start by installing Terraform, if requested
365+
if [ "${WITH_TERRAFORM-}" = 1 ]; then
366+
with_terraform
367+
fi
368+
305369
# Standalone installs by pulling pre-built releases from GitHub.
306370
if [ "$METHOD" = standalone ]; then
307371
if has_standalone; then
@@ -313,10 +377,6 @@ main() {
313377
exit 1
314378
fi
315379
fi
316-
if [ "$METHOD" = with_terraform ]; then
317-
# Install terraform then continue the script
318-
with_terraform
319-
fi
320380

321381
# DISTRO can be overridden for testing but shouldn't normally be used as it
322382
# can result in a broken coder.
@@ -429,7 +489,7 @@ with_terraform() {
429489
install_macos() {
430490
# If there is no `brew` binary available, just default to installing standalone
431491
if command_exists brew; then
432-
echoh "Installing v$VERSION of the coder formula from coder/coder."
492+
echoh "Installing coder with Homebrew from the coder/coder tap."
433493
echoh
434494

435495
sh_c brew install coder/coder/coder
@@ -505,16 +565,16 @@ install_standalone() {
505565
"$sh_c" unzip -d "$CACHE_DIR" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip"
506566
fi
507567

508-
COPY_LOCATION="$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME"
568+
STANDALONE_BINARY_LOCATION="$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME"
509569

510570
# Remove the file if it already exists to
511571
# avoid https://github.com/coder/coder/issues/2086
512-
if [ -f "$COPY_LOCATION" ]; then
513-
"$sh_c" rm "$COPY_LOCATION"
572+
if [ -f "$STANDALONE_BINARY_LOCATION" ]; then
573+
"$sh_c" rm "$STANDALONE_BINARY_LOCATION"
514574
fi
515575

516576
# Copy the binary to the correct location.
517-
"$sh_c" cp "$CACHE_DIR/coder" "$COPY_LOCATION"
577+
"$sh_c" cp "$CACHE_DIR/coder" "$STANDALONE_BINARY_LOCATION"
518578

519579
echo_standalone_postinstall
520580
}

site/e2e/helpers.ts

+15-23
Original file line numberDiff line numberDiff line change
@@ -263,45 +263,37 @@ export const downloadCoderVersion = async (
263263
return binaryPath;
264264
}
265265

266-
// Runs our public install script using our options to
267-
// install the binary!
266+
// Run our official install script to install the binary
268267
await new Promise<void>((resolve, reject) => {
269268
const cp = spawn(
270-
"sh",
269+
path.join(__dirname, "../../install.sh"),
271270
[
272-
"-c",
273-
[
274-
"curl",
275-
"-L",
276-
"https://coder.com/install.sh",
277-
"|",
278-
"sh",
279-
"-s",
280-
"--",
281-
"--version",
282-
version,
283-
"--method",
284-
"standalone",
285-
"--prefix",
286-
tempDir,
287-
"--binary-name",
288-
binaryName,
289-
].join(" "),
271+
"--version",
272+
version,
273+
"--method",
274+
"standalone",
275+
"--prefix",
276+
tempDir,
277+
"--binary-name",
278+
binaryName,
290279
],
291280
{
292281
env: {
293282
...process.env,
294283
XDG_CACHE_HOME: "/tmp/coder-e2e-cache",
284+
TRACE: "1", // tells install.sh to `set -x`, helpful if something goes wrong
295285
},
296286
},
297287
);
298288
// eslint-disable-next-line no-console -- Needed for debugging
299-
cp.stderr.on("data", (data) => console.log(data.toString()));
289+
cp.stderr.on("data", (data) => console.error(data.toString()));
290+
// eslint-disable-next-line no-console -- Needed for debugging
291+
cp.stdout.on("data", (data) => console.log(data.toString()));
300292
cp.on("close", (code) => {
301293
if (code === 0) {
302294
resolve();
303295
} else {
304-
reject(new Error("curl failed with code " + code));
296+
reject(new Error("install.sh failed with code " + code));
305297
}
306298
});
307299
});

0 commit comments

Comments
 (0)