45
45
Sets the prefix used by standalone release archives. Defaults to /usr/local
46
46
and the binary is copied into /usr/local/bin
47
47
To install in \$ HOME, pass ---prefix=\$ HOME/.local
48
-
48
+
49
49
--binary-name <name>
50
50
Sets the name for the CLI in standalone release archives. Defaults to "coder"
51
51
To use the CLI as coder2, pass --binary-name=coder2
@@ -54,6 +54,15 @@ Usage:
54
54
--rsh <bin>
55
55
Specifies the remote shell for remote installation. Defaults to ssh.
56
56
57
+ --with-terraform
58
+ Installs Terraform binary from https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION} / source
59
+ alongside coder.
60
+ This is great for if you are having issues with Coder installing terraform, or if you
61
+ just want it on your base system aswell.
62
+ This supports most systems, however if you are unsure yours is supported you can check
63
+ the link above.
64
+
65
+
57
66
The detection method works as follows:
58
67
- Debian, Ubuntu, Raspbian: install the deb package from GitHub.
59
68
- Fedora, CentOS, RHEL, openSUSE: install the rpm package from GitHub.
@@ -145,10 +154,10 @@ EOF
145
154
}
146
155
147
156
main () {
157
+ TERRAFORM_VERSION=" 1.3.4"
148
158
if [ " ${TRACE-} " ]; then
149
159
set -x
150
160
fi
151
-
152
161
unset \
153
162
DRY_RUN \
154
163
METHOD \
@@ -212,6 +221,9 @@ main() {
212
221
usage
213
222
exit 0
214
223
;;
224
+ --with-terraform)
225
+ METHOD=with_terraform
226
+ ;;
215
227
--)
216
228
shift
217
229
# We remove the -- added above.
@@ -241,7 +253,7 @@ main() {
241
253
fi
242
254
243
255
METHOD=" ${METHOD-detect} "
244
- if [ " $METHOD " != detect ] && [ " $METHOD " != standalone ]; then
256
+ if [ " $METHOD " != detect ] && [ " $METHOD " != with_terraform ] && [ " $METHOD " != standalone ]; then
245
257
echoerr " Unknown install method \" $METHOD \" "
246
258
echoerr " Run with --help to see usage."
247
259
exit 1
@@ -251,12 +263,14 @@ main() {
251
263
# releases in order to download and unpack the right release.
252
264
CACHE_DIR=$( echo_cache_dir)
253
265
STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-/ usr/ local}
266
+ TERRAFORM_INSTALL_PREFIX=${TERRAFORM_INSTALL_PREFIX:-/ usr/ local}
254
267
STANDALONE_BINARY_NAME=${STANDALONE_BINARY_NAME:- coder}
255
268
VERSION=${VERSION:- $(echo_latest_version)}
256
269
# These can be overridden for testing but shouldn't normally be used as it can
257
270
# result in a broken coder.
258
271
OS=${OS:- $(os)}
259
272
ARCH=${ARCH:- $(arch)}
273
+ TERRAFORM_ARCH=${TERRAFORM_ARCH:- $(terraform_arch)}
260
274
261
275
distro_name
262
276
@@ -276,6 +290,10 @@ main() {
276
290
exit 1
277
291
fi
278
292
fi
293
+ if [ " $METHOD " = with_terraform ]; then
294
+ # Install terraform then continue the script
295
+ with_terraform
296
+ fi
279
297
280
298
# DISTRO can be overridden for testing but shouldn't normally be used as it
281
299
# can result in a broken coder.
@@ -351,6 +369,42 @@ fetch() {
351
369
sh_c mv " $FILE .incomplete" " $FILE "
352
370
}
353
371
372
+ with_terraform () {
373
+ # Check if the unzip package is installed. If not error peacefully.
374
+ if ! (command_exists unzip); then
375
+ echoh
376
+ echoerr " This script needs the unzip package to run."
377
+ echoerr " Please install unzip to use this function"
378
+ exit 1
379
+ fi
380
+ echoh " Installing Terraform version $TERRAFORM_VERSION $TERRAFORM_ARCH from the HashiCorp release repository."
381
+ echoh
382
+
383
+ # Download from official source and save it to cache
384
+ fetch " https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _${OS} _${TERRAFORM_ARCH} .zip" \
385
+ " $CACHE_DIR /terraform_${TERRAFORM_VERSION} _${OS} _${TERRAFORM_ARCH} .zip"
386
+
387
+ sh_c mkdir -p " $TERRAFORM_INSTALL_PREFIX " 2> /dev/null || true
388
+
389
+ sh_c=" sh_c"
390
+ if [ ! -w " $TERRAFORM_INSTALL_PREFIX " ]; then
391
+ sh_c=" sudo_sh_c"
392
+ fi
393
+ # Prepare /usr/local/bin/ and the binary for copying
394
+ " $sh_c " mkdir -p " $TERRAFORM_INSTALL_PREFIX /bin"
395
+ " $sh_c " unzip -d " $CACHE_DIR " -o " $CACHE_DIR /terraform_${TERRAFORM_VERSION} _${OS} _${ARCH} .zip"
396
+ COPY_LOCATION=" $TERRAFORM_INSTALL_PREFIX /bin/terraform"
397
+
398
+ # Remove the file if it already exists to
399
+ # avoid https://github.com/coder/coder/issues/2086
400
+ if [ -f " $COPY_LOCATION " ]; then
401
+ " $sh_c " rm " $COPY_LOCATION "
402
+ fi
403
+
404
+ # Copy the binary to the correct location.
405
+ " $sh_c " cp " $CACHE_DIR /terraform" " $COPY_LOCATION "
406
+ }
407
+
354
408
install_deb () {
355
409
echoh " Installing v$VERSION of the $ARCH deb package from GitHub."
356
410
echoh
@@ -431,7 +485,7 @@ install_standalone() {
431
485
has_standalone () {
432
486
case $ARCH in
433
487
amd64) return 0 ;;
434
- ard64 ) return 0 ;;
488
+ arm64 ) return 0 ;;
435
489
armv7)
436
490
[ " $( distro) " != darwin ]
437
491
return
@@ -516,6 +570,18 @@ arch() {
516
570
esac
517
571
}
518
572
573
+ # The following is to change the naming, that way people with armv7 won't receive a error
574
+ # List of binaries can be found here: https://releases.hashicorp.com/terraform/
575
+ terraform_arch () {
576
+ uname_m=$( uname -m)
577
+ case $uname_m in
578
+ aarch64) echo arm64 ;;
579
+ x86_64) echo amd64 ;;
580
+ armv7l) echo arm ;;
581
+ * ) echo " $uname_m " ;;
582
+ esac
583
+ }
584
+
519
585
command_exists () {
520
586
if [ ! " $1 " ]; then return 1; fi
521
587
command -v " $@ " > /dev/null
0 commit comments