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 ed08b87
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
65 changes: 42 additions & 23 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,11 +17,13 @@

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

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

# EUID is the effective user id
EUID=${EUID}

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

Expand Down Expand Up @@ -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,7 +135,7 @@ getLatestReleaseVersion() {
local KusionReleaseURL="${RELEASE_URL}"
local latest_release=""

if [ "$KUSION_HTTP_REQUEST_CLI" == "curl" ]; then
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)
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)
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 @@ -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 [ "$profile" = ".profile"]; then
echoFexists "$HOME/$profile"
elif [ "$profile" = ".bash_profile"]; then
echoFexists "$HOME/$profile"
elif [ "$profile" = ".bashrc"]; then
echoFexists "$HOME/$profile"
elif [ "$profile" = ".zshrc"]; then
echoFexists "$HOME/$profile"
elif [ "$profile" = ".config/fish/config.fish"]; then
echoFexists "$HOME/$profile"
fi
;;
*)
profiles=(.profile .bashrc .bash_profile .zshrc .config/fish/config.fish)
if [ "$profile" = ".profile"]; then
echoFexists "$HOME/$profile"
elif [ "$profile" = ".bashrc"]; then
echoFexists "$HOME/$profile"
elif [ "$profile" = ".bash_profile"]; then
echoFexists "$HOME/$profile"
elif [ "$profile" = ".zshrc"]; then
echoFexists "$HOME/$profile"
elif [ "$profile" = ".config/fish/config.fish"]; then
echoFexists "$HOME/$profile"
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 =~ \.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 ed08b87

Please sign in to comment.