Skip to content
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

Refactor install script #262

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Changes from all commits
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
74 changes: 42 additions & 32 deletions hack/install.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

set \
-o errexit \
-o nounset \
-o pipefail
PROJECT_NAME="helm-s3"
PROJECT_GH="hypnoglow/$PROJECT_NAME"

set -e
set -u

if [ -n "${HELM_S3_PLUGIN_NO_INSTALL_HOOK:-}" ]; then
echo "Development mode: not downloading versioned release."
Expand All @@ -18,41 +19,50 @@ validate_checksum() {
echo "Checksum is valid."
}

initArch() {
arch=$(uname -m)
case $arch in
x86_64|amd64) arch="amd64" ;;
aarch64|arm64) arch="arm64" ;;
*)
echo "Arch '$(uname -m)' not supported!" >&2
exit 1
;;
esac

}

initOS() {
os=$(uname -s)
case "$(uname)" in
Darwin) os="darwin" ;;
Linux) os="linux" ;;
CYGWIN*|MINGW*|MSYS_NT*) os="windows" ;;
*)
echo "OS '$(uname)' not supported!" >&2
exit 1
;;
esac
}

on_exit() {
exit_code=$?
if [ ${exit_code} -ne 0 ]; then
echo "helm-s3 install hook failed. Please remove the plugin using 'helm plugin remove s3' and install again." > /dev/stderr
echo "${PROJECT_NAME} install hook failed. Please remove the plugin using 'helm plugin remove s3' and install again." > /dev/stderr
fi
exit ${exit_code}
}
trap on_exit EXIT

version="$(cat plugin.yaml | grep "version" | cut -d '"' -f 2)"
echo "Downloading and installing helm-s3 v${version} ..."

arch=""
case "$(uname -m)" in
x86_64|amd64) arch="amd64" ;;
aarch64|arm64) arch="arm64" ;;
*)
echo "Arch '$(uname -m)' not supported!" >&2
exit 1
;;
esac

os=""
case "$(uname)" in
Darwin) os="darwin" ;;
Linux) os="linux" ;;
CYGWIN*|MINGW*|MSYS_NT*) os="windows" ;;
*)
echo "OS '$(uname)' not supported!" >&2
exit 1
;;
esac

binary_url="https://github.com/hypnoglow/helm-s3/releases/download/v${version}/helm-s3_${version}_${os}_${arch}.tar.gz"
checksum_url="https://github.com/hypnoglow/helm-s3/releases/download/v${version}/helm-s3_${version}_checksums.txt"
echo "Downloading and installing ${PROJECT_NAME} v${version} ..."

initArch

initOS

binary_url="https://github.com/${PROJECT_GH}/releases/download/v${version}/${PROJECT_NAME}_${version}_${os}_${arch}.tar.gz"
checksum_url="https://github.com/${PROJECT_GH}/releases/download/v${version}/${PROJECT_NAME}_${version}_checksums.txt"

mkdir -p "bin"
mkdir -p "releases/v${version}"
Expand Down Expand Up @@ -87,5 +97,5 @@ checksums_filename="releases/v${version}_checksums.txt"

# Unpack the binary.
tar xzf "${binary_filename}" -C "releases/v${version}"
mv "releases/v${version}/bin/helm-s3" "bin/helm-s3"
mv "releases/v${version}/bin/${PROJECT_NAME}" "bin/${PROJECT_NAME}"
exit 0