@@ -64,9 +64,10 @@ Usage:
64
64
Installs Terraform binary from https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION} / source
65
65
alongside coder.
66
66
This is great for if you are having issues with Coder installing terraform, or if you
67
- just want it on your base system aswell .
67
+ just want it on your base system as well .
68
68
This supports most systems, however if you are unsure yours is supported you can check
69
69
the link above.
70
+
70
71
--net-admin
71
72
Adds \` CAP_NET_ADMIN\` to the installed binary. This allows Coder to
72
73
increase network speeds, but has security implications.
@@ -157,11 +158,11 @@ Coder ${channel}release v${VERSION} installed. ${advisory}See our releases docum
157
158
158
159
The Coder binary has been placed in the following location:
159
160
160
- $STANDALONE_INSTALL_PREFIX /bin/$STANDALONE_BINARY_NAME
161
+ $STANDALONE_INSTALL_PREFIX /bin/$STANDALONE_PLATFORM_BINARY_NAME
161
162
162
163
EOF
163
164
164
- CODER_COMMAND=" $( command -v " $STANDALONE_BINARY_NAME " || true) "
165
+ CODER_COMMAND=" $( command -v " $STANDALONE_PLATFORM_BINARY_NAME " || true) "
165
166
166
167
if [ -z " ${CODER_COMMAND} " ]; then
167
168
cath << EOF
@@ -176,11 +177,11 @@ EOF
176
177
cath << EOF
177
178
To run a Coder server:
178
179
179
- $ $STANDALONE_BINARY_NAME server
180
+ $ $STANDALONE_PLATFORM_BINARY_NAME server
180
181
181
182
To connect to a Coder deployment:
182
183
183
- $ $STANDALONE_BINARY_NAME login <deployment url>
184
+ $ $STANDALONE_PLATFORM_BINARY_NAME login <deployment url>
184
185
185
186
EOF
186
187
fi
@@ -396,6 +397,10 @@ main() {
396
397
ARCH=${ARCH:- $(arch)}
397
398
TERRAFORM_ARCH=${TERRAFORM_ARCH:- $(terraform_arch)}
398
399
400
+ # The above OS detection usually fails on Windows because the OS environment variable
401
+ # is unpredictable. The is_windows function should account for this.
402
+ if is_windows ; then OS=" windows" ; fi
403
+
399
404
# If we've been provided a flag which is specific to the standalone installation
400
405
# method, we should "detect" standalone to be the appropriate installation method.
401
406
# This check needs to occur before we set these variables with defaults.
@@ -424,7 +429,8 @@ main() {
424
429
CACHE_DIR=$( echo_cache_dir)
425
430
TERRAFORM_INSTALL_PREFIX=${TERRAFORM_INSTALL_PREFIX:-/ usr/ local}
426
431
STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-/ usr/ local}
427
- STANDALONE_BINARY_NAME=${STANDALONE_BINARY_NAME:- coder}
432
+ STANDALONE_PLATFORM_BINARY_NAME=$( format_platform_filename " ${STANDALONE_BINARY_NAME:- coder} " )
433
+
428
434
STABLE_VERSION=$( echo_latest_stable_version)
429
435
if [ " ${MAINLINE} " = 1 ]; then
430
436
VERSION=$( echo_latest_mainline_version)
@@ -482,6 +488,7 @@ main() {
482
488
# We don't have GitHub releases that work on Alpine or FreeBSD so we have no
483
489
# choice but to use npm here.
484
490
alpine) install_apk ;;
491
+ windows) install_windows ;;
485
492
# For anything else we'll try to install standalone but fall back to npm if
486
493
# we don't have releases for the architecture.
487
494
* )
@@ -496,6 +503,11 @@ main() {
496
503
fi
497
504
}
498
505
506
+ is_windows () {
507
+ # shellcheck disable=SC3028
508
+ [ " $OSTYPE " = " msys" ] || [ " $OSTYPE " = " cygwin" ] || [ " $OSTYPE " = " win32" ] || [ " $COMSPEC " != " " ]
509
+ }
510
+
499
511
cap_net_admin () {
500
512
if ! command_exists setcap && command_exists capsh; then
501
513
echo " Package 'libcap' not found. See install instructions for your distro: https://command-not-found.com/setcap"
@@ -570,7 +582,7 @@ with_terraform() {
570
582
echoerr " Please install unzip to use this function"
571
583
exit 1
572
584
fi
573
- echoh " Installing Terraform version $TERRAFORM_VERSION $TERRAFORM_ARCH from the HashiCorp release repository."
585
+ echoh " Installing Terraform version $TERRAFORM_VERSION for $OS / $TERRAFORM_ARCH from the HashiCorp release repository."
574
586
echoh
575
587
576
588
# Download from official source and save it to cache
@@ -586,7 +598,8 @@ with_terraform() {
586
598
# Prepare /usr/local/bin/ and the binary for copying
587
599
" $sh_c " mkdir -p " $TERRAFORM_INSTALL_PREFIX /bin"
588
600
" $sh_c " unzip -d " $CACHE_DIR " -o " $CACHE_DIR /terraform_${TERRAFORM_VERSION} _${OS} _${ARCH} .zip"
589
- COPY_LOCATION=" $TERRAFORM_INSTALL_PREFIX /bin/terraform"
601
+ TERRAFORM_PLATFORM_BINARY_NAME=$( format_platform_filename " terraform" )
602
+ COPY_LOCATION=" $TERRAFORM_INSTALL_PREFIX /bin/$TERRAFORM_PLATFORM_BINARY_NAME "
590
603
591
604
# Remove the file if it already exists to
592
605
# avoid https://github.com/coder/coder/issues/2086
@@ -595,9 +608,21 @@ with_terraform() {
595
608
fi
596
609
597
610
# Copy the binary to the correct location.
598
- " $sh_c " cp " $CACHE_DIR /terraform" " $COPY_LOCATION "
611
+ " $sh_c " cp " $CACHE_DIR /${TERRAFORM_PLATFORM_BINARY_NAME} " " $COPY_LOCATION "
612
+ }
613
+
614
+ format_platform_filename () {
615
+ IN_FILENAME=" $1 "
616
+ PLATFORM_SUFFIX=" "
617
+ if is_windows ; then PLATFORM_SUFFIX=" .exe" ; fi
618
+ printf " %s%s" " $IN_FILENAME " " $PLATFORM_SUFFIX "
619
+ }
620
+
621
+ install_windows () {
622
+ install_standalone
599
623
}
600
624
625
+
601
626
install_macos () {
602
627
# If there is no `brew` binary available, just default to installing standalone
603
628
if command_exists brew; then
@@ -649,12 +674,12 @@ install_apk() {
649
674
}
650
675
651
676
install_standalone () {
652
- echoh " Installing v$VERSION of the $ARCH release from GitHub."
677
+ echoh " Installing v$VERSION of the $OS / $ ARCH release from GitHub."
653
678
echoh
654
679
655
680
# macOS releases are packaged as .zip
656
681
case $OS in
657
- darwin) STANDALONE_ARCHIVE_FORMAT=zip ;;
682
+ darwin | windows ) STANDALONE_ARCHIVE_FORMAT=zip ;;
658
683
* ) STANDALONE_ARCHIVE_FORMAT=tar.gz ;;
659
684
esac
660
685
@@ -672,7 +697,7 @@ install_standalone() {
672
697
sh_c unzip -d " $CACHE_DIR /tmp" -o " $CACHE_DIR /coder_${VERSION} _${OS} _${ARCH} .zip"
673
698
fi
674
699
675
- STANDALONE_BINARY_LOCATION =" $STANDALONE_INSTALL_PREFIX /bin/$STANDALONE_BINARY_NAME "
700
+ STANDALONE_PLATFORM_BINARY_LOCATION =" $STANDALONE_INSTALL_PREFIX /bin/$STANDALONE_PLATFORM_BINARY_NAME "
676
701
677
702
sh_c=" sh_c"
678
703
if [ ! -w " $STANDALONE_INSTALL_PREFIX " ]; then
@@ -683,12 +708,14 @@ install_standalone() {
683
708
684
709
# Remove the file if it already exists to
685
710
# avoid https://github.com/coder/coder/issues/2086
686
- if [ -f " $STANDALONE_BINARY_LOCATION " ]; then
687
- " $sh_c " rm " $STANDALONE_BINARY_LOCATION "
711
+ if [ -f " $STANDALONE_PLATFORM_BINARY_LOCATION " ]; then
712
+ " $sh_c " rm " $STANDALONE_PLATFORM_BINARY_LOCATION "
688
713
fi
689
714
715
+ SOURCE_PLATFORM_BINARY_NAME=$( format_platform_filename " coder" )
716
+
690
717
# Copy the binary to the correct location.
691
- " $sh_c " cp " $CACHE_DIR /tmp/coder " " $STANDALONE_BINARY_LOCATION "
718
+ " $sh_c " cp " $CACHE_DIR /tmp/$SOURCE_PLATFORM_BINARY_NAME " " $STANDALONE_PLATFORM_BINARY_LOCATION "
692
719
693
720
# Clean up the extracted files (note, not using sudo: $sh_c -> sh_c).
694
721
sh_c rm -rv " $CACHE_DIR /tmp"
@@ -710,6 +737,7 @@ has_standalone() {
710
737
}
711
738
712
739
os () {
740
+ if is_windows; then echo windows; return ; fi
713
741
uname=" $( uname) "
714
742
case $uname in
715
743
Linux) echo linux ;;
@@ -732,10 +760,12 @@ os() {
732
760
#
733
761
# Inspired by https://github.com/docker/docker-install/blob/26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c/install.sh#L111-L120.
734
762
distro () {
735
- if [ " $OS " = " darwin" ] || [ " $OS " = " freebsd" ]; then
763
+ case " $OS " in
764
+ darwin | freebsd | windows)
736
765
echo " $OS "
737
766
return
738
- fi
767
+ ;;
768
+ esac
739
769
740
770
if [ -f /etc/os-release ]; then
741
771
(
@@ -764,6 +794,11 @@ distro_name() {
764
794
return
765
795
fi
766
796
797
+ if is_windows; then
798
+ echo " Windows"
799
+ return
800
+ fi
801
+
767
802
if [ -f /etc/os-release ]; then
768
803
(
769
804
# shellcheck disable=SC1091
0 commit comments