Skip to content

Commit 3ac6e23

Browse files
committed
revert: improve flag interpretation for install.sh
1 parent 2dae600 commit 3ac6e23

File tree

1 file changed

+27
-78
lines changed

1 file changed

+27
-78
lines changed

install.sh

Lines changed: 27 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,18 @@ Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/bin/$STAND
104104
105105
EOF
106106

107-
CODER_COMMAND="$(command -v "$STANDALONE_BINARY_NAME")"
108-
109-
if [ ! "$CODER_COMMAND" ]; then
107+
if [ "$STANDALONE_INSTALL_PREFIX" != /usr/local ]; then
110108
cath <<EOF
111109
Extend your path to use Coder:
112-
113-
$ PATH="$STANDALONE_INSTALL_PREFIX/bin:\$PATH"
110+
PATH="$STANDALONE_INSTALL_PREFIX/bin:\$PATH"
114111
115112
EOF
116-
elif [ "$CODER_COMMAND" != "$STANDALONE_BINARY_LOCATION" ]; then
117-
echo_path_conflict "$CODER_COMMAND" "$STANDALONE_INSTALL_PREFIX"
118-
else
119-
cath <<EOF
120-
To run a Coder server:
121-
122-
$ $STANDALONE_BINARY_NAME server
123-
124-
To connect to a Coder deployment:
125-
126-
$ $STANDALONE_BINARY_NAME login <deployment url>
113+
fi
114+
cath <<EOF
115+
Run Coder:
116+
$STANDALONE_BINARY_NAME server
127117
128118
EOF
129-
fi
130119
}
131120

132121
echo_brew_postinstall() {
@@ -135,15 +124,8 @@ echo_brew_postinstall() {
135124
return
136125
fi
137126

138-
CODER_COMMAND="$(command -v "coder")"
139-
BREW_PREFIX="$(brew --prefix)"
140-
141-
if [ "$CODER_COMMAND" != "$BREW_PREFIX/bin/coder" ]; then
142-
echo_path_conflict "$CODER_COMMAND" "$BREW_PREFIX"
143-
fi
144-
145127
cath <<EOF
146-
Homebrew formula has been installed.
128+
brew formula has been installed.
147129
148130
To run a Coder server:
149131
@@ -175,6 +157,7 @@ To run a Coder server:
175157
# Or just run the server directly
176158
$ coder server
177159
160+
Default URL: http://127.0.0.1:3000
178161
Configuring Coder: https://coder.com/docs/v2/latest/admin/configure
179162
180163
To connect to a Coder deployment:
@@ -186,45 +169,28 @@ EOF
186169

187170
echo_dryrun_postinstall() {
188171
cath <<EOF
172+
189173
Dry-run complete.
190174
191175
To install Coder, re-run this script without the --dry-run flag.
192-
193-
EOF
194-
}
195-
196-
echo_path_conflict() {
197-
cath <<EOF
198-
There is another binary in your PATH that conflicts with the binary we've installed.
199-
200-
$1
201-
202-
This is likely because of an existing installation of Coder. See our documentation for suggests on how to resolve this.
203-
204-
https://coder.com/docs/v2/latest/install/install.sh#path-conflicts
205-
206176
EOF
207177
}
208178

209179
main() {
210180
TERRAFORM_VERSION="1.3.4"
211-
212181
if [ "${TRACE-}" ]; then
213182
set -x
214183
fi
215-
216184
unset \
217185
DRY_RUN \
218186
METHOD \
219187
OPTIONAL \
220188
ALL_FLAGS \
221189
RSH_ARGS \
222190
EDGE \
223-
RSH \
224-
WITH_TERRAFORM
191+
RSH
225192

226193
ALL_FLAGS=""
227-
228194
while [ "$#" -gt 0 ]; do
229195
case "$1" in
230196
-*)
@@ -279,7 +245,7 @@ main() {
279245
exit 0
280246
;;
281247
--with-terraform)
282-
WITH_TERRAFORM=1
248+
METHOD=with_terraform
283249
;;
284250
--)
285251
shift
@@ -309,29 +275,8 @@ main() {
309275
return
310276
fi
311277

312-
# These can be overridden for testing but shouldn't normally be used as it can
313-
# result in a broken coder.
314-
OS=${OS:-$(os)}
315-
ARCH=${ARCH:-$(arch)}
316-
TERRAFORM_ARCH=${TERRAFORM_ARCH:-$(terraform_arch)}
317-
318-
# We can't reasonably support installing specific versions of Coder through
319-
# Homebrew, so if we're on macOS and the `--version` flag was set, we should
320-
# "detect" standalone to be the appropriate installation method. This check
321-
# needs to occur before we set `VERSION` to a default of the latest release.
322-
if [ "$OS" = "darwin" ] && [ "${VERSION-}" ]; then
323-
METHOD=standalone
324-
fi
325-
326-
# If we've been provided a flag which is specific to the standalone installation
327-
# method, we should "detect" standalone to be the appropriate installation method.
328-
# This check needs to occur before we set these variables with defaults.
329-
if [ "${STANDALONE_INSTALL_PREFIX-}" ] || [ "${STANDALONE_BINARY_NAME-}" ]; then
330-
METHOD=standalone
331-
fi
332-
333278
METHOD="${METHOD-detect}"
334-
if [ "$METHOD" != detect ] && [ "$METHOD" != standalone ]; then
279+
if [ "$METHOD" != detect ] && [ "$METHOD" != with_terraform ] && [ "$METHOD" != standalone ]; then
335280
echoerr "Unknown install method \"$METHOD\""
336281
echoerr "Run with --help to see usage."
337282
exit 1
@@ -340,10 +285,15 @@ main() {
340285
# These are used by the various install_* functions that make use of GitHub
341286
# releases in order to download and unpack the right release.
342287
CACHE_DIR=$(echo_cache_dir)
343-
TERRAFORM_INSTALL_PREFIX=${TERRAFORM_INSTALL_PREFIX:-/usr/local}
344288
STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-/usr/local}
289+
TERRAFORM_INSTALL_PREFIX=${TERRAFORM_INSTALL_PREFIX:-/usr/local}
345290
STANDALONE_BINARY_NAME=${STANDALONE_BINARY_NAME:-coder}
346291
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)}
347297

348298
distro_name
349299

@@ -352,11 +302,6 @@ main() {
352302
echoh
353303
fi
354304

355-
# Start by installing Terraform, if requested
356-
if [ "${WITH_TERRAFORM-}" = 1 ]; then
357-
with_terraform
358-
fi
359-
360305
# Standalone installs by pulling pre-built releases from GitHub.
361306
if [ "$METHOD" = standalone ]; then
362307
if has_standalone; then
@@ -368,6 +313,10 @@ main() {
368313
exit 1
369314
fi
370315
fi
316+
if [ "$METHOD" = with_terraform ]; then
317+
# Install terraform then continue the script
318+
with_terraform
319+
fi
371320

372321
# DISTRO can be overridden for testing but shouldn't normally be used as it
373322
# can result in a broken coder.
@@ -480,7 +429,7 @@ with_terraform() {
480429
install_macos() {
481430
# If there is no `brew` binary available, just default to installing standalone
482431
if command_exists brew; then
483-
echoh "Installing coder with Homebrew from the coder/coder tap."
432+
echoh "Installing v$VERSION of the coder formula from coder/coder."
484433
echoh
485434

486435
sh_c brew install coder/coder/coder
@@ -556,16 +505,16 @@ install_standalone() {
556505
"$sh_c" unzip -d "$CACHE_DIR" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip"
557506
fi
558507

559-
STANDALONE_BINARY_LOCATION="$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME"
508+
COPY_LOCATION="$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME"
560509

561510
# Remove the file if it already exists to
562511
# avoid https://github.com/coder/coder/issues/2086
563-
if [ -f "$STANDALONE_BINARY_LOCATION" ]; then
564-
"$sh_c" rm "$STANDALONE_BINARY_LOCATION"
512+
if [ -f "$COPY_LOCATION" ]; then
513+
"$sh_c" rm "$COPY_LOCATION"
565514
fi
566515

567516
# Copy the binary to the correct location.
568-
"$sh_c" cp "$CACHE_DIR/coder" "$STANDALONE_BINARY_LOCATION"
517+
"$sh_c" cp "$CACHE_DIR/coder" "$COPY_LOCATION"
569518

570519
echo_standalone_postinstall
571520
}

0 commit comments

Comments
 (0)