Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Added --with-terraform argument to install coder and terraform together #5586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
- Added a --install-terraform argument
- Added a unzip command check to the standalone function
	- Cleaner error and help redirect the user to a solution
- Added help info for `--install-terraform` argument
- Fixed standalone install typo (ard64 -> arm64)
  • Loading branch information
Admin committed Jan 5, 2023
commit 82d49dbae2a8d7361d80bd1e11f0ab8238562ecb
80 changes: 77 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Usage:
Sets the prefix used by standalone release archives. Defaults to /usr/local
and the binary is copied into /usr/local/bin
To install in \$HOME, pass ---prefix=\$HOME/.local

--binary-name <name>
Sets the name for the CLI in standalone release archives. Defaults to "coder"
To use the CLI as coder2, pass --binary-name=coder2
Expand All @@ -54,6 +54,15 @@ Usage:
--rsh <bin>
Specifies the remote shell for remote installation. Defaults to ssh.

--install-terraform
Installs Terraform binary from https://releases.hashicorp.com/terraform/1.3.4/ source
alongside coder.
This is great for if you are having issues with Coder installing terraform, or if you
just want it on your base system aswell.
This supports most systems, however if you are unsure yours is supported you can check
the link above.


The detection method works as follows:
- Debian, Ubuntu, Raspbian: install the deb package from GitHub.
- Fedora, CentOS, RHEL, openSUSE: install the rpm package from GitHub.
Expand Down Expand Up @@ -212,6 +221,9 @@ main() {
usage
exit 0
;;
--install-terraform)
METHOD=install_terraform
;;
--)
shift
# We remove the -- added above.
Expand Down Expand Up @@ -241,7 +253,7 @@ main() {
fi

METHOD="${METHOD-detect}"
if [ "$METHOD" != detect ] && [ "$METHOD" != standalone ]; then
if [ "$METHOD" != detect ] && [ "$METHOD" != install_terraform ] && [ "$METHOD" != standalone ]; then
echoerr "Unknown install method \"$METHOD\""
echoerr "Run with --help to see usage."
exit 1
Expand All @@ -251,12 +263,14 @@ main() {
# releases in order to download and unpack the right release.
CACHE_DIR=$(echo_cache_dir)
STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-/usr/local}
TERRAFORM_INSTALL_PREFIX=${TERRAFORM_INSTALL_PREFIX:-/usr/local}
STANDALONE_BINARY_NAME=${STANDALONE_BINARY_NAME:-coder}
VERSION=${VERSION:-$(echo_latest_version)}
# These can be overridden for testing but shouldn't normally be used as it can
# result in a broken coder.
OS=${OS:-$(os)}
ARCH=${ARCH:-$(arch)}
TERRA_ARCH=${TERRA_ARCH:-$(terra_arch)}

distro_name

Expand All @@ -276,6 +290,10 @@ main() {
exit 1
fi
fi
if [ "$METHOD" = install_terraform ]; then
# Install terraform then contine the script
install_terraform
fi

# DISTRO can be overridden for testing but shouldn't normally be used as it
# can result in a broken coder.
Expand Down Expand Up @@ -351,6 +369,43 @@ fetch() {
sh_c mv "$FILE.incomplete" "$FILE"
}

install_terraform() {
# Check if the unzip package is installed. If not error peacefully.
if !(command_exists unzip); then
echoh
echoerr "This script needs the unzip package to run."
echoerr "Please install unzip to use this function"
exit 1
fi

echoh "Installing Terraform version 1.3.4 $TERRA_ARCH package from Hashicorp Source."
echoh

# Download from offical source and save it to cache
fetch "https://releases.hashicorp.com/terraform/1.3.4/terraform_1.3.4_${OS}_${TERRA_ARCH}.zip" \
"$CACHE_DIR/terraform_1.3.4_${OS}_${TERRA_ARCH}.zip"

sh_c mkdir -p "$TERRAFORM_INSTALL_PREFIX" 2>/dev/null || true

sh_c="sh_c"
if [ ! -w "$TERRAFORM_INSTALL_PREFIX" ]; then
sh_c="sudo_sh_c"
fi
# Prepare /usr/local/bin/ and the binary for copying
"$sh_c" mkdir -p "$TERRAFORM_INSTALL_PREFIX/bin"
"$sh_c" unzip -d "$CACHE_DIR" -o "$CACHE_DIR/terraform_1.3.4_${OS}_${ARCH}.zip"
COPY_LOCATION="$TERRAFORM_INSTALL_PREFIX/bin/terraform"

# Remove the file if it already exists to
# avoid https://github.com/coder/coder/issues/2086
if [ -f "$COPY_LOCATION" ]; then
"$sh_c" rm "$COPY_LOCATION"
fi

# Copy the binary to the correct location.
"$sh_c" cp "$CACHE_DIR/terraform" "$COPY_LOCATION"
}

install_deb() {
echoh "Installing v$VERSION of the $ARCH deb package from GitHub."
echoh
Expand Down Expand Up @@ -385,6 +440,13 @@ install_apk() {
}

install_standalone() {
# Check if the unzip package is installed. If not error peacefully.
if !(command_exists unzip); then
echoh
echoerr "This script needs the unzip package to run."
echoerr "Please install unzip to use this function"
exit 1
fi
echoh "Installing v$VERSION of the $ARCH release from GitHub."
echoh

Expand Down Expand Up @@ -431,7 +493,7 @@ install_standalone() {
has_standalone() {
case $ARCH in
amd64) return 0 ;;
ard64) return 0 ;;
arm64) return 0 ;;
armv7)
[ "$(distro)" != darwin ]
return
Expand Down Expand Up @@ -516,6 +578,18 @@ arch() {
esac
}

# The following is to change the naming, that way people with armv7 won't recieve a error
# List of binaries can be found here: https://releases.hashicorp.com/terraform/1.3.4/
terra_arch() {
uname_m=$(uname -m)
case $uname_m in
aarch64) echo arm64 ;;
x86_64) echo amd64 ;;
armv7l) echo arm ;;
*) echo "$uname_m" ;;
esac
}

command_exists() {
if [ ! "$1" ]; then return 1; fi
command -v "$@" >/dev/null
Expand Down