mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-05 12:57:50 +00:00
style: address shellcheck issues in install.sh (#1305)
Fixes some shellcheck issues in the install script. Also normalizes formatting with `shfmt` program.
This commit is contained in:
parent
525dfef9a7
commit
30ff5913be
@ -34,27 +34,27 @@ MAGENTA="$(tput setaf 5 2>/dev/null || echo '')"
|
|||||||
NO_COLOR="$(tput sgr0 2>/dev/null || echo '')"
|
NO_COLOR="$(tput sgr0 2>/dev/null || echo '')"
|
||||||
|
|
||||||
info() {
|
info() {
|
||||||
printf "${BOLD}${GREY}>${NO_COLOR} $@\n"
|
printf "%s\n" "${BOLD}${GREY}>${NO_COLOR} $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
printf "${YELLOW}! $@${NO_COLOR}\n"
|
printf "%s\n" "${YELLOW}! $*${NO_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
error() {
|
error() {
|
||||||
printf "${RED}x $@${NO_COLOR}\n" >&2
|
printf "%s\n" "${RED}x $*${NO_COLOR}" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
complete() {
|
complete() {
|
||||||
printf "${GREEN}✓${NO_COLOR} $@\n"
|
printf "%s\n" "${GREEN}✓${NO_COLOR} $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Gets path to a temporary file, even if
|
# Gets path to a temporary file, even if
|
||||||
get_tmpfile(){
|
get_tmpfile() {
|
||||||
local suffix
|
local suffix
|
||||||
suffix="$1"
|
suffix="$1"
|
||||||
if hash mktemp; then
|
if hash mktemp; then
|
||||||
printf "$(mktemp).${suffix}"
|
printf "%s.%s" "$(mktemp)" "${suffix}"
|
||||||
else
|
else
|
||||||
# No really good options here--let's pick a default + hope
|
# No really good options here--let's pick a default + hope
|
||||||
printf "/tmp/starship.%s" "${suffix}"
|
printf "/tmp/starship.%s" "${suffix}"
|
||||||
@ -63,10 +63,10 @@ get_tmpfile(){
|
|||||||
|
|
||||||
# Test if a location is writeable by trying to write to it. Windows does not let
|
# Test if a location is writeable by trying to write to it. Windows does not let
|
||||||
# you test writeability other than by writing: https://stackoverflow.com/q/1999988
|
# you test writeability other than by writing: https://stackoverflow.com/q/1999988
|
||||||
test_writeable(){
|
test_writeable() {
|
||||||
local path
|
local path
|
||||||
path="${1:-}/test.txt"
|
path="${1:-}/test.txt"
|
||||||
if touch "${path}" 2> /dev/null; then
|
if touch "${path}" 2>/dev/null; then
|
||||||
rm "${path}"
|
rm "${path}"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@ -107,19 +107,19 @@ fetch() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_and_unpack(){
|
fetch_and_unpack() {
|
||||||
local sudo
|
local sudo
|
||||||
local tmpfile
|
local tmpfile
|
||||||
sudo="$1"
|
sudo="$1"
|
||||||
# I'd like to separate this into a fetch() and unpack() function, but I can't
|
# I'd like to separate this into a fetch() and unpack() function, but I can't
|
||||||
# figure out how to get bash functions to read STDIN/STDOUT from pipes
|
# figure out how to get bash functions to read STDIN/STDOUT from pipes
|
||||||
if [ "${EXT}" = "tar.gz" ]; then
|
if [ "${EXT}" = "tar.gz" ]; then
|
||||||
fetch "${URL}" | ${sudo} tar xzf${VERBOSE} - -C "${BIN_DIR}"
|
fetch "${URL}" | ${sudo} tar xzf "${VERBOSE}" - -C "${BIN_DIR}"
|
||||||
elif [ "${EXT}" = "zip" ]; then
|
elif [ "${EXT}" = "zip" ]; then
|
||||||
# According to https://unix.stackexchange.com/q/2690, zip files cannot be read
|
# According to https://unix.stackexchange.com/q/2690, zip files cannot be read
|
||||||
# through a pipe. We'll have to do our own file-based setup.
|
# through a pipe. We'll have to do our own file-based setup.
|
||||||
tmpfile="$(get_tmpfile "${EXT}")"
|
tmpfile="$(get_tmpfile "${EXT}")"
|
||||||
fetch "${URL}" > "${tmpfile}"
|
fetch "${URL}" >"${tmpfile}"
|
||||||
${sudo} unzip "${tmpfile}" -d "${BIN_DIR}"
|
${sudo} unzip "${tmpfile}" -d "${BIN_DIR}"
|
||||||
rm "${tmpfile}"
|
rm "${tmpfile}"
|
||||||
else
|
else
|
||||||
@ -130,9 +130,9 @@ fetch_and_unpack(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
elevate_priv(){
|
elevate_priv() {
|
||||||
if ! hash sudo 2>/dev/null; then
|
if ! hash sudo 2>/dev/null; then
|
||||||
error "Could not find the command \"sudo\", needed to get permissions for install."
|
error 'Could not find the command "sudo", needed to get permissions for install.'
|
||||||
info "If you are on Windows, please run your shell as an administrator, then"
|
info "If you are on Windows, please run your shell as an administrator, then"
|
||||||
info "rerun this script. Otherwise, please run this script as root, or install"
|
info "rerun this script. Otherwise, please run this script as root, or install"
|
||||||
info "sudo."
|
info "sudo."
|
||||||
@ -148,7 +148,7 @@ install() {
|
|||||||
local msg
|
local msg
|
||||||
local sudo
|
local sudo
|
||||||
|
|
||||||
if test_writeable "${BIN_DIR}" ; then
|
if test_writeable "${BIN_DIR}"; then
|
||||||
sudo=""
|
sudo=""
|
||||||
msg="Installing Starship, please wait…"
|
msg="Installing Starship, please wait…"
|
||||||
else
|
else
|
||||||
@ -210,17 +210,17 @@ detect_arch() {
|
|||||||
|
|
||||||
confirm() {
|
confirm() {
|
||||||
if [ -z "${FORCE-}" ]; then
|
if [ -z "${FORCE-}" ]; then
|
||||||
printf "${MAGENTA}?${NO_COLOR} $@ ${BOLD}[y/N]${NO_COLOR} "
|
printf "%s " "${MAGENTA}?${NO_COLOR} $* ${BOLD}[y/N]${NO_COLOR}"
|
||||||
set +e
|
set +e
|
||||||
read -r yn < /dev/tty
|
read -r yn </dev/tty
|
||||||
rc=$?
|
rc=$?
|
||||||
set -e
|
set -e
|
||||||
if [ $rc -ne 0 ]; then
|
if [ $rc -ne 0 ]; then
|
||||||
error "Error reading from prompt (please re-run with the \`--yes\` option)"
|
error 'Error reading from prompt (please re-run with the `--yes` option)'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ "$yn" != "y" ] && [ "$yn" != "yes" ]; then
|
if [ "$yn" != "y" ] && [ "$yn" != "yes" ]; then
|
||||||
error "Aborting (please answer \"yes\" to continue)"
|
error 'Aborting (please answer "yes" to continue)'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -237,7 +237,8 @@ check_bin_dir() {
|
|||||||
|
|
||||||
# https://stackoverflow.com/a/11655875
|
# https://stackoverflow.com/a/11655875
|
||||||
local good
|
local good
|
||||||
good=$( IFS=:
|
good=$(
|
||||||
|
IFS=:
|
||||||
for path in $PATH; do
|
for path in $PATH; do
|
||||||
if [ "${path}" = "${bin_dir}" ]; then
|
if [ "${path}" = "${bin_dir}" ]; then
|
||||||
echo 1
|
echo 1
|
||||||
@ -271,22 +272,61 @@ fi
|
|||||||
# parse argv variables
|
# parse argv variables
|
||||||
while [ "$#" -gt 0 ]; do
|
while [ "$#" -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-p|--platform) PLATFORM="$2"; shift 2;;
|
-p | --platform)
|
||||||
-b|--bin-dir) BIN_DIR="$2"; shift 2;;
|
PLATFORM="$2"
|
||||||
-a|--arch) ARCH="$2"; shift 2;;
|
shift 2
|
||||||
-B|--base-url) BASE_URL="$2"; shift 2;;
|
;;
|
||||||
|
-b | --bin-dir)
|
||||||
|
BIN_DIR="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-a | --arch)
|
||||||
|
ARCH="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-B | --base-url)
|
||||||
|
BASE_URL="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
|
||||||
-V|--verbose) VERBOSE=1; shift 1;;
|
-V | --verbose)
|
||||||
-f|-y|--force|--yes) FORCE=1; shift 1;;
|
VERBOSE=1
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-f | -y | --force | --yes)
|
||||||
|
FORCE=1
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
|
||||||
-p=*|--platform=*) PLATFORM="${1#*=}"; shift 1;;
|
-p=* | --platform=*)
|
||||||
-b=*|--bin-dir=*) BIN_DIR="${1#*=}"; shift 1;;
|
PLATFORM="${1#*=}"
|
||||||
-a=*|--arch=*) ARCH="${1#*=}"; shift 1;;
|
shift 1
|
||||||
-B=*|--base-url=*) BASE_URL="${1#*=}"; shift 1;;
|
;;
|
||||||
-V=*|--verbose=*) VERBOSE="${1#*=}"; shift 1;;
|
-b=* | --bin-dir=*)
|
||||||
-f=*|-y=*|--force=*|--yes=*) FORCE="${1#*=}"; shift 1;;
|
BIN_DIR="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-a=* | --arch=*)
|
||||||
|
ARCH="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-B=* | --base-url=*)
|
||||||
|
BASE_URL="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-V=* | --verbose=*)
|
||||||
|
VERBOSE="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-f=* | -y=* | --force=* | --yes=*)
|
||||||
|
FORCE="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
|
||||||
*) error "Unknown option: $1"; exit 1;;
|
*)
|
||||||
|
error "Unknown option: $1"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -298,7 +338,7 @@ if [ "${ARCH}" = "i386" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf " ${UNDERLINE}Configuration${NO_COLOR}\n"
|
printf " %s\n" "${UNDERLINE}Configuration${NO_COLOR}"
|
||||||
info "${BOLD}Bin directory${NO_COLOR}: ${GREEN}${BIN_DIR}${NO_COLOR}"
|
info "${BOLD}Bin directory${NO_COLOR}: ${GREEN}${BIN_DIR}${NO_COLOR}"
|
||||||
info "${BOLD}Platform${NO_COLOR}: ${GREEN}${PLATFORM}${NO_COLOR}"
|
info "${BOLD}Platform${NO_COLOR}: ${GREEN}${PLATFORM}${NO_COLOR}"
|
||||||
info "${BOLD}Arch${NO_COLOR}: ${GREEN}${ARCH}${NO_COLOR}"
|
info "${BOLD}Arch${NO_COLOR}: ${GREEN}${ARCH}${NO_COLOR}"
|
||||||
|
Loading…
Reference in New Issue
Block a user