Skip to content

Commit

Permalink
chore: use sh not bash
Browse files Browse the repository at this point in the history
  • Loading branch information
healthjyk committed Dec 27, 2023
1 parent 238b1f6 commit 6c7bc8a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
75 changes: 47 additions & 28 deletions static/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

# ------------------------------------------------------------
# Copyright 2022 The KusionStack Authors
Expand All @@ -17,14 +17,16 @@

set -o errexit
set -o nounset
set -o pipefail

# Sudo is required to copy binary to KUSION_HOME_DIR
USE_SUDO=${USE_SUDO:-"false"}

# Specified profile
PROFILE=${PROFILE:-""}

# SHELL
SHELL=${SHELL}

# specifed Kusion version to install
KUSION_VERSION=${1:-""}

Expand Down Expand Up @@ -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

Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"

Expand All @@ -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 <<END_FISH_SCRIPT
set -gx KUSION_HOME "$install_dir"
Expand Down
3 changes: 1 addition & 2 deletions static/scripts/uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

# ------------------------------------------------------------
# Copyright 2022 The KusionStack Authors
Expand All @@ -15,7 +15,6 @@

set -o errexit
set -o nounset
set -o pipefail

# Sudo is required to delete binary from KUSION_HOME_DIR
USE_SUDO=${USE_SUDO:-"false"}
Expand Down

0 comments on commit 6c7bc8a

Please sign in to comment.