Skip to content

Commit

Permalink
Merge pull request #262 from yonahd/master
Browse files Browse the repository at this point in the history
Refactor install script
  • Loading branch information
hypnoglow authored Oct 25, 2023
2 parents dec1481 + 00b0e68 commit 00344c1
Showing 1 changed file with 42 additions and 32 deletions.
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

0 comments on commit 00344c1

Please sign in to comment.