Skip to content

Commit

Permalink
refactor install script
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonah Dissen authored and hypnoglow committed Oct 23, 2023
1 parent dec1481 commit c9b4241
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions hack/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

PROJECT_NAME="helm-s3"
PROJECT_GH="hypnoglow/$PROJECT_NAME"

set \
-o errexit \
Expand All @@ -18,41 +21,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 +99,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 c9b4241

Please sign in to comment.