Skip to content

Commit

Permalink
feat(install): Add posix shell check (starship#3474)
Browse files Browse the repository at this point in the history
* feat(install): Add posix shell check

* Change function name
  • Loading branch information
chipbuster authored Jan 21, 2022
1 parent 4f46411 commit a84a3af
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ has() {
command -v "$1" 1>/dev/null 2>&1
}

# Make sure user is not using zsh or non-POSIX-mode bash, which can cause issues
verify_shell_is_posix_or_exit() {
if [ -n "${ZSH_VERSION+x}" ]; then
error "Running installation script with \`zsh\` is known to cause errors."
error "Please use \`sh\` instead."
exit 1
elif [ -n "${BASH_VERSION+x}" ] && [ -z "${POSIXLY_CORRECT+x}" ]; then
error "Running installation script with non-POSIX \`bash\` may cause errors."
error "Please use \`sh\` instead."
exit 1
else
true # No-op: no issues detected
fi
}

# Gets path to a temporary file, even if
get_tmpfile() {
suffix="$1"
Expand Down Expand Up @@ -355,7 +370,6 @@ print_install() {
printf "\n"
}


is_build_available() {
arch="$1"
platform="$2"
Expand Down Expand Up @@ -399,6 +413,9 @@ if [ -z "${BASE_URL-}" ]; then
BASE_URL="https://github.com/starship/starship/releases"
fi

# Non-POSIX shells can break once executing code due to semantic differences
verify_shell_is_posix_or_exit

# parse argv variables
while [ "$#" -gt 0 ]; do
case "$1" in
Expand Down

0 comments on commit a84a3af

Please sign in to comment.