mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-21 18:58:03 +00:00
Refactoring install plugin script (#427)
* Refactor: Improve functionality and efficiency of installation script * Refactor: Improve functionality and efficiency of installation script * fixed the spacing error and also added the helm debug logic
This commit is contained in:
@@ -1,53 +1,90 @@
|
|||||||
#!/bin/sh -e
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
# Copied w/ love from the chartmuseum/helm-push :)
|
|
||||||
|
|
||||||
[ ! -z "$HELM_DEBUG" ] && set -x
|
[ ! -z "$HELM_DEBUG" ] && set -x
|
||||||
|
|
||||||
|
|
||||||
|
# Function to print error message and exit
|
||||||
|
error_exit() {
|
||||||
|
echo "$1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to validate command availability
|
||||||
|
validate_command() {
|
||||||
|
command -v "$1" >/dev/null 2>&1 || error_exit "Required command '$1' not found. Please install it."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to detect the latest version from GitHub API
|
||||||
|
get_latest_version() {
|
||||||
|
local latest_version
|
||||||
|
latest_version="$(curl -s "${api_repo}" | grep -oE '"name": "v[^"]+' | cut -d 'v' -f 2)"
|
||||||
|
echo "$latest_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to download and install the plugin
|
||||||
|
install_plugin() {
|
||||||
|
local plugin_version="$1"
|
||||||
|
local plugin_url="$2"
|
||||||
|
local plugin_filename="$3"
|
||||||
|
local plugin_directory="$4"
|
||||||
|
|
||||||
|
# Download the plugin archive
|
||||||
|
if validate_command "curl"; then
|
||||||
|
curl --fail -sSL "${plugin_url}" -o "${plugin_filename}"
|
||||||
|
elif validate_command "wget"; then
|
||||||
|
wget -q "${plugin_url}" -O "${plugin_filename}"
|
||||||
|
else
|
||||||
|
error_exit "Both 'curl' and 'wget' commands not found. Please install either one."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract and install the plugin
|
||||||
|
tar xzf "${plugin_filename}" -C "${plugin_directory}"
|
||||||
|
mv "${plugin_directory}/${name}" "bin/${name}" || mv "${plugin_directory}/${name}.exe" "bin/${name}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main script
|
||||||
name="helm-dashboard"
|
name="helm-dashboard"
|
||||||
repo="https://github.com/komodorio/${name}"
|
repo="https://github.com/komodorio/${name}"
|
||||||
api_repo="https://api.github.com/repos/komodorio/${name}/releases/latest"
|
api_repo="https://api.github.com/repos/komodorio/${name}/releases/latest"
|
||||||
|
HELM_PUSH_PLUGIN_NO_INSTALL_HOOK="${HELM_PUSH_PLUGIN_NO_INSTALL_HOOK:-}"
|
||||||
|
|
||||||
if [ -n "${HELM_PUSH_PLUGIN_NO_INSTALL_HOOK}" ]; then
|
# Check if in development mode
|
||||||
|
if [ -n "$HELM_PUSH_PLUGIN_NO_INSTALL_HOOK" ]; then
|
||||||
echo "Development mode: not downloading versioned release."
|
echo "Development mode: not downloading versioned release."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
version="$(curl -s ${api_repo} | grep '\"name\": "v.*\"' | cut -d 'v' -f 2 | cut -d '"' -f 1)"
|
# Autodetect the latest version
|
||||||
echo Tried to autodetect latest version: $version
|
version=$(get_latest_version)
|
||||||
|
echo "Tried to autodetect latest version: $version"
|
||||||
[ -z "$version" ] && {
|
[ -z "$version" ] && {
|
||||||
version="$(cat plugin.yaml | grep "version" | cut -d '"' -f 2)"
|
version="$(awk -F '"' '/version/ {print $2}' plugin.yaml)"
|
||||||
echo Defaulted to version: $version
|
echo "Defaulted to version: $version"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Downloading and installing ${name} v${version} ..."
|
echo "Downloading and installing ${name} v${version} ..."
|
||||||
|
|
||||||
url=""
|
# Convert architecture of the target system to a compatible GOARCH value
|
||||||
|
|
||||||
# convert architecture of the target system to a compatible GOARCH value.
|
|
||||||
# Otherwise failes to download of the plugin from github, because the provided
|
|
||||||
# architecture by `uname -m` is not part of the github release.
|
|
||||||
arch=""
|
|
||||||
case $(uname -m) in
|
case $(uname -m) in
|
||||||
x86_64)
|
x86_64)
|
||||||
arch="x86_64"
|
arch="x86_64"
|
||||||
;;
|
;;
|
||||||
armv6*)
|
armv6*)
|
||||||
arch="armv6"
|
arch="armv6"
|
||||||
;;
|
;;
|
||||||
# match every arm processor version like armv7h, armv7l and so on.
|
armv7*)
|
||||||
armv7*)
|
arch="armv7"
|
||||||
arch="armv7"
|
;;
|
||||||
;;
|
aarch64 | arm64)
|
||||||
aarch64 | arm64)
|
arch="arm64"
|
||||||
arch="arm64"
|
;;
|
||||||
;;
|
*)
|
||||||
*)
|
error_exit "Failed to detect target architecture"
|
||||||
echo "Failed to detect target architecture"
|
;;
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Construct the plugin download URL
|
||||||
if [ "$(uname)" = "Darwin" ]; then
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
url="${repo}/releases/download/v${version}/${name}_${version}_Darwin_${arch}.tar.gz"
|
url="${repo}/releases/download/v${version}/${name}_${version}_Darwin_${arch}.tar.gz"
|
||||||
elif [ "$(uname)" = "Linux" ] ; then
|
elif [ "$(uname)" = "Linux" ] ; then
|
||||||
@@ -56,22 +93,14 @@ else
|
|||||||
url="${repo}/releases/download/v${version}/${name}_${version}_windows_${arch}.tar.gz"
|
url="${repo}/releases/download/v${version}/${name}_${version}_windows_${arch}.tar.gz"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo $url
|
echo "$url"
|
||||||
|
|
||||||
mkdir -p "bin"
|
mkdir -p "bin"
|
||||||
mkdir -p "releases/v${version}"
|
mkdir -p "releases/v${version}"
|
||||||
|
|
||||||
# Download with curl if possible.
|
install_plugin "$version" "$url" "releases/v${version}.tar.gz" "releases/v${version}"
|
||||||
if [ -x "$(which curl 2>/dev/null)" ]; then
|
|
||||||
curl --fail -sSL "${url}" -o "releases/v${version}.tar.gz"
|
|
||||||
else
|
|
||||||
wget -q "${url}" -O "releases/v${version}.tar.gz"
|
|
||||||
fi
|
|
||||||
tar xzf "releases/v${version}.tar.gz" -C "releases/v${version}"
|
|
||||||
mv "releases/v${version}/${name}" "bin/${name}" || \
|
|
||||||
mv "releases/v${version}/${name}.exe" "bin/${name}"
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Helm Dashboard is installed, to start it, run in your terminal:"
|
echo "Helm Dashboard is installed. To start it, run the following command:"
|
||||||
echo " helm dashboard"
|
echo "helm dashboard"
|
||||||
echo
|
|
||||||
|
|||||||
Reference in New Issue
Block a user