@@ -104,18 +104,29 @@ Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/bin/$STAND
104
104
105
105
EOF
106
106
107
- if [ " $STANDALONE_INSTALL_PREFIX " != /usr/local ]; then
107
+ CODER_COMMAND=" $( command -v " $STANDALONE_BINARY_NAME " ) "
108
+
109
+ if [ ! " $CODER_COMMAND " ]; then
108
110
cath << EOF
109
111
Extend your path to use Coder:
110
- PATH="$STANDALONE_INSTALL_PREFIX /bin:\$ PATH"
112
+
113
+ $ PATH="$STANDALONE_INSTALL_PREFIX /bin:\$ PATH"
111
114
112
115
EOF
113
- fi
114
- cath << EOF
115
- Run Coder:
116
- $STANDALONE_BINARY_NAME server
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>
117
127
118
128
EOF
129
+ fi
119
130
}
120
131
121
132
echo_brew_postinstall () {
@@ -124,8 +135,15 @@ echo_brew_postinstall() {
124
135
return
125
136
fi
126
137
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
+
127
145
cath << EOF
128
- brew formula has been installed.
146
+ Homebrew formula has been installed.
129
147
130
148
To run a Coder server:
131
149
@@ -157,7 +175,6 @@ To run a Coder server:
157
175
# Or just run the server directly
158
176
$ coder server
159
177
160
- Default URL: http://127.0.0.1:3000
161
178
Configuring Coder: https://coder.com/docs/v2/latest/admin/configure
162
179
163
180
To connect to a Coder deployment:
@@ -169,28 +186,45 @@ EOF
169
186
170
187
echo_dryrun_postinstall () {
171
188
cath << EOF
172
-
173
189
Dry-run complete.
174
190
175
191
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
+
176
206
EOF
177
207
}
178
208
179
209
main () {
180
210
TERRAFORM_VERSION=" 1.3.4"
211
+
181
212
if [ " ${TRACE-} " ]; then
182
213
set -x
183
214
fi
215
+
184
216
unset \
185
217
DRY_RUN \
186
218
METHOD \
187
219
OPTIONAL \
188
220
ALL_FLAGS \
189
221
RSH_ARGS \
190
222
EDGE \
191
- RSH
223
+ RSH \
224
+ WITH_TERRAFORM
192
225
193
226
ALL_FLAGS=" "
227
+
194
228
while [ " $# " -gt 0 ]; do
195
229
case " $1 " in
196
230
-* )
@@ -245,7 +279,7 @@ main() {
245
279
exit 0
246
280
;;
247
281
--with-terraform)
248
- METHOD=with_terraform
282
+ WITH_TERRAFORM=1
249
283
;;
250
284
--)
251
285
shift
@@ -275,8 +309,29 @@ main() {
275
309
return
276
310
fi
277
311
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
+
278
333
METHOD=" ${METHOD-detect} "
279
- if [ " $METHOD " != detect ] && [ " $METHOD " != with_terraform ] && [ " $METHOD " != standalone ]; then
334
+ if [ " $METHOD " != detect ] && [ " $METHOD " != standalone ]; then
280
335
echoerr " Unknown install method \" $METHOD \" "
281
336
echoerr " Run with --help to see usage."
282
337
exit 1
@@ -285,15 +340,10 @@ main() {
285
340
# These are used by the various install_* functions that make use of GitHub
286
341
# releases in order to download and unpack the right release.
287
342
CACHE_DIR=$( echo_cache_dir)
288
- STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-/ usr/ local}
289
343
TERRAFORM_INSTALL_PREFIX=${TERRAFORM_INSTALL_PREFIX:-/ usr/ local}
344
+ STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-/ usr/ local}
290
345
STANDALONE_BINARY_NAME=${STANDALONE_BINARY_NAME:- coder}
291
346
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)}
297
347
298
348
distro_name
299
349
@@ -302,6 +352,11 @@ main() {
302
352
echoh
303
353
fi
304
354
355
+ # Start by installing Terraform, if requested
356
+ if [ " ${WITH_TERRAFORM-} " = 1 ]; then
357
+ with_terraform
358
+ fi
359
+
305
360
# Standalone installs by pulling pre-built releases from GitHub.
306
361
if [ " $METHOD " = standalone ]; then
307
362
if has_standalone; then
@@ -313,10 +368,6 @@ main() {
313
368
exit 1
314
369
fi
315
370
fi
316
- if [ " $METHOD " = with_terraform ]; then
317
- # Install terraform then continue the script
318
- with_terraform
319
- fi
320
371
321
372
# DISTRO can be overridden for testing but shouldn't normally be used as it
322
373
# can result in a broken coder.
@@ -429,7 +480,7 @@ with_terraform() {
429
480
install_macos () {
430
481
# If there is no `brew` binary available, just default to installing standalone
431
482
if command_exists brew; then
432
- echoh " Installing v $VERSION of the coder formula from coder/coder."
483
+ echoh " Installing coder with Homebrew from the coder/coder tap ."
433
484
echoh
434
485
435
486
sh_c brew install coder/coder/coder
@@ -505,16 +556,16 @@ install_standalone() {
505
556
" $sh_c " unzip -d " $CACHE_DIR " -o " $CACHE_DIR /coder_${VERSION} _${OS} _${ARCH} .zip"
506
557
fi
507
558
508
- COPY_LOCATION =" $STANDALONE_INSTALL_PREFIX /bin/$STANDALONE_BINARY_NAME "
559
+ STANDALONE_BINARY_LOCATION =" $STANDALONE_INSTALL_PREFIX /bin/$STANDALONE_BINARY_NAME "
509
560
510
561
# Remove the file if it already exists to
511
562
# avoid https://github.com/coder/coder/issues/2086
512
- if [ -f " $COPY_LOCATION " ]; then
513
- " $sh_c " rm " $COPY_LOCATION "
563
+ if [ -f " $STANDALONE_BINARY_LOCATION " ]; then
564
+ " $sh_c " rm " $STANDALONE_BINARY_LOCATION "
514
565
fi
515
566
516
567
# Copy the binary to the correct location.
517
- " $sh_c " cp " $CACHE_DIR /coder" " $COPY_LOCATION "
568
+ " $sh_c " cp " $CACHE_DIR /coder" " $STANDALONE_BINARY_LOCATION "
518
569
519
570
echo_standalone_postinstall
520
571
}
0 commit comments