Skip to content

refactor: improve flag interpretation for install.sh #9554

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 5 commits into from
Sep 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
refactor: improve installation method detection
  • Loading branch information
aslilac committed Sep 6, 2023
commit 0cf437e542bc9e674052da002e4a3e5ed1be5cf5
38 changes: 26 additions & 12 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,23 @@ EOF

main() {
TERRAFORM_VERSION="1.3.4"

if [ "${TRACE-}" ]; then
set -x
fi

unset \
DRY_RUN \
METHOD \
OPTIONAL \
ALL_FLAGS \
RSH_ARGS \
EDGE \
RSH
RSH \
WITH_TERRAFORM

ALL_FLAGS=""

while [ "$#" -gt 0 ]; do
case "$1" in
-*)
Expand Down Expand Up @@ -245,7 +249,7 @@ main() {
exit 0
;;
--with-terraform)
METHOD=with_terraform
WITH_TERRAFORM=1
;;
--)
shift
Expand Down Expand Up @@ -275,8 +279,22 @@ main() {
return
fi

# 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)}
TERRAFORM_ARCH=${TERRAFORM_ARCH:-$(terraform_arch)}

# We can't reasonably support installing specific versions of Coder through
# Homebrew, so if we're on macOS and the `--version` flag was set, we should
# "detect" the best installation strategy to be standalone. This check needs
# to occur before we default `VERSION` to the latest release.
if [ "$OS" = "darwin" ] && [ "${VERSION-}" ]; then
METHOD=standalone
fi

METHOD="${METHOD-detect}"
if [ "$METHOD" != detect ] && [ "$METHOD" != with_terraform ] && [ "$METHOD" != standalone ]; then
if [ "$METHOD" != detect ] && [ "$METHOD" != standalone ]; then
echoerr "Unknown install method \"$METHOD\""
echoerr "Run with --help to see usage."
exit 1
Expand All @@ -289,11 +307,6 @@ main() {
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)}
TERRAFORM_ARCH=${TERRAFORM_ARCH:-$(terraform_arch)}

distro_name

Expand All @@ -302,6 +315,11 @@ main() {
echoh
fi

# Start by installing Terraform, if requested
if [ "${WITH_TERRAFORM-}" = 1 ]; then
with_terraform
fi

# Standalone installs by pulling pre-built releases from GitHub.
if [ "$METHOD" = standalone ]; then
if has_standalone; then
Expand All @@ -313,10 +331,6 @@ main() {
exit 1
fi
fi
if [ "$METHOD" = with_terraform ]; then
# Install terraform then continue the script
with_terraform
fi

# DISTRO can be overridden for testing but shouldn't normally be used as it
# can result in a broken coder.
Expand Down