feat(installer): Ask for permission escalation during installation, if needed (#914)

This commit is contained in:
Diego Jornada 2020-02-12 23:13:21 -03:00 committed by GitHub
parent 0312c7b91e
commit b1bc2a04a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 6 deletions

View File

@ -82,6 +82,24 @@ fetch() {
fi fi
} }
install() {
local sudo
local msg
if [ -w "$BIN_DIR" ]; then
sudo=""
msg="Installing Starship, please wait…"
else
warn "Escalated permission are required to install to ${BIN_DIR}"
sudo -v || (error "Aborting installation (Please provide root password)";exit 1)
sudo="sudo"
msg="Installing Starship as root, please wait…"
fi
info "$msg"
fetch "${URL}" \
| ${sudo} tar xzf${VERBOSE} - \
-C "${BIN_DIR}"
}
# Currently supporting: # Currently supporting:
# - win (Git Bash) # - win (Git Bash)
# - darwin # - darwin
@ -238,13 +256,9 @@ info "Tarball URL: ${UNDERLINE}${BLUE}${URL}${NO_COLOR}"
check_bin_dir "${BIN_DIR}" check_bin_dir "${BIN_DIR}"
confirm "Install Starship ${GREEN}latest${NO_COLOR} to ${BOLD}${GREEN}${BIN_DIR}${NO_COLOR}?" confirm "Install Starship ${GREEN}latest${NO_COLOR} to ${BOLD}${GREEN}${BIN_DIR}${NO_COLOR}?"
info "Installing Starship, please wait…" install
fetch "${URL}" \
| tar xzf${VERBOSE} - \
-C "${BIN_DIR}"
complete "Starship installed" complete "Starship installed"
echo echo
info "Please follow the steps for your shell to complete the installation: info "Please follow the steps for your shell to complete the installation: