diff --git a/static/scripts/install.sh b/static/scripts/install.sh index 1b080ad5..927996ce 100755 --- a/static/scripts/install.sh +++ b/static/scripts/install.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # ------------------------------------------------------------ # Copyright 2022 The KusionStack Authors @@ -17,7 +17,6 @@ set -o errexit set -o nounset -set -o pipefail # Sudo is required to copy binary to KUSION_HOME_DIR USE_SUDO=${USE_SUDO:-"false"} @@ -25,6 +24,9 @@ USE_SUDO=${USE_SUDO:-"false"} # Specified profile PROFILE=${PROFILE:-""} +# SHELL +SHELL=${SHELL:-""} + # specifed Kusion version to install KUSION_VERSION=${1:-""} @@ -72,7 +74,7 @@ error() { runAsRoot() { local CMD="$*" - if [ $EUID -ne 0 ] && [ $USE_SUDO = "true" ]; then + if [ $USE_SUDO = "true" ]; then CMD="sudo $CMD" fi @@ -95,18 +97,18 @@ getSystemInfo() { } verifySupported() { - local supported=(darwin-amd64 linux-amd64 darwin-arm64) local current_os_arch="${OS}-${ARCH}" - for osarch in "${supported[@]}"; do - if [ "$osarch" == "$current_os_arch" ]; then - info "Your system is ${OS}_${ARCH}." - return - fi - done - - error "No prebuilt installation package for ${current_os_arch}" - exit 1 + if [ "${current_os_arch}" = "darwin-amd64" ]; then + info "Your system is ${current_os_arch}." + elif [ "${current_os_arch}" = "darwin-arm64" ]; then + info "Your system is ${current_os_arch}." + elif [ "${current_os_arch}" = "linux-amd64" ]; then + info "Your system is ${current_os_arch}." + else + error "No prebuilt installation package for ${current_os_arch}" + exit 1 + fi } checkHttpRequestCLI() { @@ -133,13 +135,13 @@ getLatestReleaseVersion() { local KusionReleaseURL="${RELEASE_URL}" local latest_release="" - if [ "$KUSION_HTTP_REQUEST_CLI" == "curl" ]; then - latest_release=$(runAsRoot curl -s $KusionReleaseURL | grep \"tag_name\" | awk '{print $2}' | sed -n 's/\"\(.*\)\",/\1/p' | grep -o '^v[0-9]\+\.[0-9]\+\.[0-9]\+$' | head -n 1) + if [ "$KUSION_HTTP_REQUEST_CLI" = "curl" ]; then + latest_release=$(runAsRoot curl -s $KusionReleaseURL | grep \"tag_name\" | awk '{print $2}' | sed -n 's/\"\(.*\)\",/\1/p' | awk '/^v[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}$/{print $0}' | head -1) else - latest_release=$(runAsRoot wget -q --header="Accept: application/json" -O - $KusionReleaseURL | grep \"tag_name\" | awk '{print $2}' | sed -n 's/\"\(.*\)\",/\1/p' | grep -o '^v[0-9]\+\.[0-9]\+\.[0-9]\+$' | head -n 1) + latest_release=$(runAsRoot wget -q --header="Accept: application/json" -O - $KusionReleaseURL | grep \"tag_name\" | awk '{print $2}' | sed -n 's/\"\(.*\)\",/\1/p' | awk '/^v[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}$/{print $0}' | head -1) fi - echo "${latest_release:1}" + echo "$latest_release" | cut -c2- } download() { @@ -153,7 +155,7 @@ download() { ARTIFACT_TMP_FILE="$KUSION_TMP_ROOT/$KUSION_CLI_ARTIFACT" info "Downloading installation package from $DOWNLOAD_URL..." - if [ "$KUSION_HTTP_REQUEST_CLI" == "curl" ]; then + if [ "$KUSION_HTTP_REQUEST_CLI" = "curl" ]; then runAsRoot curl -SL "$DOWNLOAD_URL" -o "$ARTIFACT_TMP_FILE" else runAsRoot wget -O "$ARTIFACT_TMP_FILE" "$DOWNLOAD_URL" @@ -189,7 +191,7 @@ install() { # detect profile detected_profile=$(detectProfile "$(basename $SHELL)" "$(uname -s)") if [ -z "${detected_profile-}" ]; then - error "No supported user profile found. Already tried \$PROFILE ($PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, ~/.profile, and ~/.config/fish/config.fish." + error "No supported user profile found. Already tried \$PROFILE, ~/.bashrc, ~/.bash_profile, ~/.zshrc, ~/.profile, and ~/.config/fish/config.fish." return 1 fi @@ -257,25 +259,42 @@ detectProfile() { *) # Fall back to checking for profile file existence. Once again, the order # differs between macOS and everything else. - local profiles case $uname in Darwin) - profiles=(.profile .bash_profile .bashrc .zshrc .config/fish/config.fish) + if [ -f "$HOME/.profile" ]; then + echo "$HOME/.profile" + elif [ -f "$HOME/.bash_profile" ]; then + echo "$HOME/.bash_profile" + elif [ -f "$HOME/.bashrc" ]; then + echo "$HOME/.bashrc" + elif [ -f "$HOME/.zshrc" ]; then + echo "$HOME/.zshrc" + elif [ -f "$HOME/.config/fish/config.fish" ]; then + echo "$HOME/.config/fish/config.fish" + fi ;; *) - profiles=(.profile .bashrc .bash_profile .zshrc .config/fish/config.fish) + if [ -f "$HOME/.profile" ]; then + echo "$HOME/.profile" + elif [ -f "$HOME/.bashrc" ]; then + echo "$HOME/.bashrc" + elif [ -f "$HOME/.bash_profile" ]; then + echo "$HOME/.bash_profile" + elif [ -f "$HOME/.zshrc" ]; then + echo "$HOME/.zshrc" + elif [ -f "$HOME/.config/fish/config.fish" ]; then + echo "$HOME/.config/fish/config.fish" + fi ;; esac - - for profile in "${profiles[@]}"; do - echoFexists "$HOME/$profile" && break - done ;; esac } + + buildEnvFile() { - local profile="$1" + local profile="$1" local install_dir="$2" local env_file_path="$3" @@ -288,7 +307,7 @@ buildEnvContent() { local profile="$1" local install_dir="$2" - if [[ $profile =~ \.fish$ ]]; then + if [ $profile = "$HOME/.config/fish/config.fish" ]; then # fish uses a little different syntax to modify the PATH cat <