-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix plugin install script & update goreleaser config
- Loading branch information
1 parent
5c94b31
commit bc91ddc
Showing
3 changed files
with
44 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,53 @@ | ||
#!/usr/bin/env sh | ||
#! /bin/bash -e | ||
|
||
# Shamelessly copied from https://github.com/databus23/helm-diff | ||
function download() { | ||
osName=$(uname -s) | ||
DOWNLOAD_URL=$(curl --silent "https://api.github.com/repos/nikhilsbhat/helm-images/releases/latest" | grep -o "browser_download_url.*\_${osName}_x86_64.tar.gz") | ||
|
||
PROJECT_NAME="helm-images" | ||
PROJECT_GH="nikhilsbhat/$PROJECT_NAME" | ||
export GREP_COLOR="never" | ||
DOWNLOAD_URL=${DOWNLOAD_URL//\"/} | ||
DOWNLOAD_URL=${DOWNLOAD_URL/browser_download_url: /} | ||
|
||
HELM_MAJOR_VERSION=$("${HELM_BIN}" version --client --short | awk -F '.' '{print $1}') | ||
echo "download url: $DOWNLOAD_URL" | ||
OUTPUT_BASENAME=helm-images | ||
OUTPUT_BASENAME_WITH_POSTFIX=$HELM_PLUGIN_DIR/$OUTPUT_BASENAME.tar.gz | ||
|
||
: ${HELM_PLUGIN_DIR:="$("${HELM_BIN}" home --debug=false)/plugins/helm-images"} | ||
|
||
# Convert the HELM_PLUGIN_DIR to unix if cygpath is | ||
# available. This is the case when using MSYS2 or Cygwin | ||
# on Windows where helm returns a Windows path but we | ||
# need a Unix path | ||
|
||
if type cygpath >/dev/null 2>&1; then | ||
HELM_PLUGIN_DIR=$(cygpath -u $HELM_PLUGIN_DIR) | ||
fi | ||
|
||
if [ "$SKIP_BIN_INSTALL" = "1" ]; then | ||
echo "Skipping binary install" | ||
exit | ||
fi | ||
|
||
# initArch discovers the architecture for this system. | ||
initArch() { | ||
ARCH=$(uname -m) | ||
case $ARCH in | ||
armv5*) ARCH="armv5" ;; | ||
armv6*) ARCH="armv6" ;; | ||
armv7*) ARCH="armv7" ;; | ||
aarch64) ARCH="arm64" ;; | ||
x86) ARCH="386" ;; | ||
x86_64) ARCH="amd64" ;; | ||
i686) ARCH="386" ;; | ||
i386) ARCH="386" ;; | ||
esac | ||
} | ||
|
||
# initOS discovers the operating system for this system. | ||
initOS() { | ||
OS=$(uname | tr '[:upper:]' '[:lower:]') | ||
|
||
case "$OS" in | ||
# Msys support | ||
msys*) OS='windows' ;; | ||
# Minimalist GNU for Windows | ||
mingw*) OS='windows' ;; | ||
darwin) OS='macos' ;; | ||
esac | ||
} | ||
|
||
# verifySupported checks that the os/arch combination is supported for | ||
# binary builds. | ||
verifySupported() { | ||
supported="linux-amd64\nfreebsd-amd64\nmacos-amd64\nwindows-amd64" | ||
if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then | ||
echo "No prebuild binary for ${OS}-${ARCH}." | ||
exit 1 | ||
fi | ||
|
||
if ! type "curl" >/dev/null && ! type "wget" >/dev/null; then | ||
echo "Either curl or wget is required" | ||
if [ -z "$DOWNLOAD_URL" ]; then | ||
echo "Unsupported OS / architecture: ${osName}" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# getDownloadURL checks the latest available version. | ||
getDownloadURL() { | ||
version=$(git -C "$HELM_PLUGIN_DIR" describe --tags --exact-match 2>/dev/null || :) | ||
if [ -n "$version" ]; then | ||
DOWNLOAD_URL="https://github.com/$PROJECT_GH/releases/download/$version/helm-images-$OS.tgz" | ||
# echo "$DOWNLOAD_URL" | ||
if [[ -n $(command -v curl) ]]; then | ||
curl -L $DOWNLOAD_URL -o $OUTPUT_BASENAME_WITH_POSTFIX | ||
else | ||
# Use the GitHub API to find the download url for this project. | ||
url="https://api.github.com/repos/$PROJECT_GH/releases/latest" | ||
if type "curl" >/dev/null; then | ||
DOWNLOAD_URL=$(curl -s $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') | ||
elif type "wget" >/dev/null; then | ||
DOWNLOAD_URL=$(wget -q -O - $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') | ||
fi | ||
echo "Need curl" | ||
exit -1 | ||
fi | ||
} | ||
|
||
# downloadFile downloads the latest binary package and also the checksum | ||
# for that binary. | ||
downloadFile() { | ||
PLUGIN_TMP_FILE="/tmp/${PROJECT_NAME}.tgz" | ||
echo "Downloading $DOWNLOAD_URL" | ||
if type "curl" >/dev/null; then | ||
curl -L "$DOWNLOAD_URL" -o "$PLUGIN_TMP_FILE" | ||
elif type "wget" >/dev/null; then | ||
wget -q -O "$PLUGIN_TMP_FILE" "$DOWNLOAD_URL" | ||
fi | ||
echo $OUTPUT_BASENAME_WITH_POSTFIX | ||
} | ||
|
||
# installFile verifies the SHA256 for the file, then unpacks and | ||
# installs it. | ||
installFile() { | ||
function install_plugin() { | ||
HELM_TMP="/tmp/$PROJECT_NAME" | ||
mkdir -p "$HELM_TMP" | ||
tar xf "$PLUGIN_TMP_FILE" -C "$HELM_TMP" | ||
HELM_TMP_BIN="$HELM_TMP/images/bin/images" | ||
HELM_TMP_BIN="$HELM_TMP/diff/bin/diff" | ||
echo "Preparing to install into ${HELM_PLUGIN_DIR}" | ||
mkdir -p "$HELM_PLUGIN_DIR/bin" | ||
cp "$HELM_TMP_BIN" "$HELM_PLUGIN_DIR/bin" | ||
} | ||
|
||
# fail_trap is executed if an error occurs. | ||
fail_trap() { | ||
result=$? | ||
if [ "$result" != "0" ]; then | ||
echo "Failed to install $PROJECT_NAME" | ||
printf '\tFor support, go to https://github.com/nikhilsbhat/helm-images.\n' | ||
fi | ||
exit $result | ||
} | ||
|
||
# testVersion tests the installed client to make sure it is working. | ||
testVersion() { | ||
set +e | ||
echo "$PROJECT_NAME installed into $HELM_PLUGIN_DIR/$PROJECT_NAME" | ||
"${HELM_PLUGIN_DIR}/bin/images" -h | ||
set -e | ||
} | ||
function install() { | ||
echo "Installing helm-images..." | ||
|
||
# Execution | ||
local artifact_path=$(download) | ||
echo "$artifact_path" | ||
# rm -rf bin && mkdir bin && tar -xvf $OUTPUT_BASENAME_WITH_POSTFIX -C bin >/dev/null && rm -f $OUTPUT_BASENAME_WITH_POSTFIX | ||
|
||
echo "helm-images is installed." | ||
echo | ||
echo "See https://github.com/nikhilsbhat/helm-images for help getting started." | ||
} | ||
|
||
#Stop execution on any error | ||
trap "fail_trap" EXIT | ||
set -e | ||
initArch | ||
initOS | ||
verifySupported | ||
getDownloadURL | ||
downloadFile | ||
installFile | ||
testVersion | ||
install "$@" |