-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
install-binary.sh
executable file
·123 lines (100 loc) · 3.07 KB
/
install-binary.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#! /bin/bash -e
function verlte() {
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
}
function verlt() {
[ "$1" = "$2" ] && return 1 || verlte $1 $2
}
function isOld() {
verlte $1 $2 && echo "yes" || echo "no"
}
function exit_trap() {
result=$?
if [ "$result" != "0" ]; then
printf "Failed to install helm images\n"
fi
exit $result
}
function setOSArch() {
arch=$1
case "$arch" in
"aarch64")
echo "arm64"
;;
*)
echo $arch
;;
esac
}
function download_plugin() {
osName=$(uname -s)
osArch=$(uname -m)
osArch=$(setOSArch $osArch)
OUTPUT_BASENAME=helm-images
version=$(grep version "$HELM_PLUGIN_DIR/plugin.yaml" | cut -d'"' -f2)
old=$(isOld "$version" "0.0.5")
if [ "$old" == "yes" ]; then
DOWNLOAD_URL="https://github.com/nikhilsbhat/helm-images/releases/download/v$version/helm-images_${version}_${osName}_${osArch}.zip"
OUTPUT_BASENAME_WITH_POSTFIX="$HELM_PLUGIN_DIR/$OUTPUT_BASENAME.zip"
else
DOWNLOAD_URL="https://github.com/nikhilsbhat/helm-images/releases/download/v$version/helm-images_${version}_${osName}_${osArch}.tar.gz"
OUTPUT_BASENAME_WITH_POSTFIX="$HELM_PLUGIN_DIR/$OUTPUT_BASENAME.tar.gz"
fi
echo -e "download url set to ${DOWNLOAD_URL}\n"
echo -e "artifact name with path ${OUTPUT_BASENAME_WITH_POSTFIX}\n"
echo -e "downloading ${DOWNLOAD_URL} to ${HELM_PLUGIN_DIR}\n"
if [ -z "${DOWNLOAD_URL}" ]; then
echo -e "Unsupported OS / architecture: ${osName}/${osArch}\n"
exit 1
fi
if [[ -n $(command -v curl) ]]; then
if curl --fail -L "${DOWNLOAD_URL}" -o "${OUTPUT_BASENAME_WITH_POSTFIX}"; then
echo -e "successfully download the archive proceeding to install\n"
else
echo -e "failed while downloading helm archive\n"
exit 1
fi
else
echo "Need curl"
exit -1
fi
}
function install_plugin() {
local HELM_PLUGIN_ARTIFACT_PATH=${OUTPUT_BASENAME_WITH_POSTFIX}
local PROJECT_NAME="helm-images"
local HELM_PLUGIN_TEMP_PATH="/tmp/$PROJECT_NAME"
echo -n "HELM_PLUGIN_ARTIFACT_PATH: ${HELM_PLUGIN_ARTIFACT_PATH}"
rm -rf "${HELM_PLUGIN_TEMP_PATH}"
echo -e "Preparing to install into ${HELM_PLUGIN_DIR}\n"
mkdir -p "${HELM_PLUGIN_TEMP_PATH}"
tar -xvf "${HELM_PLUGIN_ARTIFACT_PATH}" -C "${HELM_PLUGIN_TEMP_PATH}"
mkdir -p "$HELM_PLUGIN_DIR/bin"
mv "${HELM_PLUGIN_TEMP_PATH}"/helm-images "${HELM_PLUGIN_DIR}/bin/helm-images"
rm -rf "${HELM_PLUGIN_TEMP_PATH}"
rm -rf "${HELM_PLUGIN_ARTIFACT_PATH}"
}
function install() {
echo "Installing helm-images..."
download_plugin
status=$?
if [ $status -ne 0 ]; then
echo -e "downloading plugin failed\n"
exit 1
fi
set +e
install_plugin
local INSTALL_PLUGIN_STAT=$?
set -e
if [ "$INSTALL_PLUGIN_STAT" != "0" ]; then
echo "installing helm plugin helm-images failed with error code: ${INSTALL_PLUGIN_STAT}"
exit 1
fi
echo
echo "helm-images is installed."
echo
"${HELM_PLUGIN_DIR}"/bin/helm-images -h
echo
echo "See https://github.com/nikhilsbhat/helm-images#readme for more information on getting started."
}
trap "exit_trap" EXIT
install "$@"