1- # Copyright Contributors to the Open Cluster Management project
21#! /usr/bin/env bash
2+ # Copyright Contributors to the Open Cluster Management project
3+ #
4+ # Usage: ./install.sh [version]
5+ #
6+ # If no version is provided, the latest version will be installed.
7+ # If a version is provided, it will be installed.
8+ #
9+ # Example: ./install.sh v0.1.0
10+ # Example: ./install.sh latest
311
412# Clusteradm CLI location
5- : ${INSTALL_DIR:= " /usr/local/bin" }
13+ : " ${INSTALL_DIR:=/ usr/ local/ bin} "
614
715# sudo is required to copy binary to INSTALL_DIR for linux
8- : ${USE_SUDO:= " false" }
16+ : " ${USE_SUDO:= false} "
17+
18+ # Target architecture (optional, defaults to auto-detect)
19+ : " ${ARCH:= } "
920
1021# Http request CLI
1122HTTP_REQUEST_CLI=curl
@@ -20,14 +31,16 @@ CLI_FILENAME=clusteradm
2031CLI_FILE=" ${INSTALL_DIR} /${CLI_FILENAME} "
2132
2233getSystemInfo () {
23- ARCH=$( uname -m)
34+ if [ -z " $ARCH " ]; then
35+ ARCH=$( uname -m)
36+ fi
2437 case $ARCH in
2538 armv7* ) ARCH=" arm" ;;
2639 aarch64) ARCH=" arm64" ;;
2740 x86_64) ARCH=" amd64" ;;
2841 esac
2942
30- OS=$( echo ` uname` | tr ' [:upper:]' ' [:lower:]' )
43+ OS=$( uname | tr ' [:upper:]' ' [:lower:]' )
3144
3245 # Most linux distro needs root permission to copy the file to /usr/local/bin
3346 if [[ " $OS " == " linux" || " $OS " == " darwin" ]] && [ " $INSTALL_DIR " == " /usr/local/bin" ]; then
@@ -37,16 +50,16 @@ getSystemInfo() {
3750
3851verifySupported () {
3952 local supported=(darwin-amd64 darwin-arm64 linux-amd64 linux-arm64 windows-amd64)
40- local current_osarch =" ${OS} -${ARCH} "
53+ local target_osarch =" ${OS} -${ARCH} "
4154
4255 for osarch in " ${supported[@]} " ; do
43- if [ " $osarch " == " $current_osarch " ]; then
44- echo " Your system is ${OS} _${ARCH} "
56+ if [ " $osarch " == " $target_osarch " ]; then
57+ echo " Installing clusteradm for ${OS} _${ARCH} "
4558 return
4659 fi
4760 done
4861
49- echo " No prebuilt binary for ${current_osarch } "
62+ echo " No prebuilt binary for ${target_osarch } "
5063 exit 1
5164}
5265
@@ -73,7 +86,7 @@ checkExisting() {
7386runAsRoot () {
7487 local CMD=" $* "
7588
76- if [ $EUID -ne 0 -a $USE_SUDO = " true" ]; then
89+ if [ " $EUID " -ne 0 ] && [ " $USE_SUDO " = " true" ]; then
7790 CMD=" sudo $CMD "
7891 fi
7992
@@ -139,7 +152,7 @@ installFile() {
139152 exit 1
140153 fi
141154
142- chmod o+x $tmp_root_cli
155+ chmod o+x " $tmp_root_cli "
143156 runAsRoot cp " $tmp_root_cli " " $INSTALL_DIR "
144157
145158 if [ -f " $CLI_FILE " ]; then
@@ -181,15 +194,21 @@ checkHttpRequestCLI
181194if [ -z " $1 " ]; then
182195 TARGET_VERSION=" latest"
183196else
184- TARGET_VERSION=v$1
197+ if [ " $1 " = " latest" ]; then
198+ TARGET_VERSION=" latest"
199+ elif [[ " $1 " =~ ^v.* ]]; then
200+ TARGET_VERSION=" $1 "
201+ else
202+ TARGET_VERSION=" v$1 "
203+ fi
185204fi
186205
187206verifySupported
188207checkExisting
189208
190209echo " Installing $TARGET_VERSION OCM clusteradm CLI..."
191210
192- downloadFile $TARGET_VERSION
211+ downloadFile " $TARGET_VERSION "
193212installFile
194213cleanup
195214
0 commit comments