diff --git a/install.sh b/install.sh index 92ebfbfa..d7e2f39f 100755 --- a/install.sh +++ b/install.sh @@ -168,6 +168,17 @@ detect_os_and_arch() { echo $os_arch } +move_to_bin_folder() { + DEST=${2:-$PREFERRED_BIN_FOLDER} + echo "Moving $1 to ${DEST}..." + # if the DEST folder is not writable, use sudo to move the file + if [ -w $DEST ]; then + mv $1 $DEST/$1 + else + sudo mv $1 $DEST/$1 + fi +} + install_kubectl() { echo "Installing kubectl..." os_arch=$(detect_os_and_arch) @@ -179,7 +190,7 @@ install_kubectl() { url="https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/${os}/${arch}/kubectl" curl -LO $url chmod +x ./kubectl - sudo mv ./kubectl $PREFERRED_BIN_FOLDER/kubectl + move_to_bin_folder ./kubectl ;; *) echo "Unsupported OS or architecture: $os_arch" @@ -197,7 +208,7 @@ install_kind() { "linux-amd64"|"darwin-amd64"|"darwin-arm64"|"linux-arm64"|"windows-amd64") curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.23.0/kind-$os_arch" chmod +x ./kind - sudo mv ./kind $PREFERRED_BIN_FOLDER/kind + move_to_bin_folder ./kind ;; *) echo "Unsupported OS or architecture: $os_arch" @@ -221,7 +232,7 @@ install_scaf() { if [ -f "$TEMP_DOWNLOAD" ]; then chmod +x $TEMP_DOWNLOAD echo "Moving scaf to $DESTINATION..." - sudo mv $TEMP_DOWNLOAD $DESTINATION + move_to_bin_folder $TEMP_DOWNLOAD $DESTINATION if [ -f "$DESTINATION" ]; then echo "scaf installed successfully at $DESTINATION" else