Improve choice messages and loop until proper answer is given

This commit is contained in:
Julian Ospald 2019-10-22 11:44:50 +08:00
parent 5d323c1140
commit b3feba0cd4
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
1 changed files with 24 additions and 32 deletions

View File

@ -96,41 +96,33 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
echo "You may want to source '$GHCUP_INSTALL_BASE_PREFIX/.ghcup/env' in your shell"
echo "configuration to do so (e.g. ~/.bashrc)."
if [ -e "$HOME/.bashrc" ] ; then
printf "\\033[0;35m%s\\033[0m\\n" ""
printf "\\033[0;35m%s\\033[0m\\n" "Detected ~/.bashrc on your system..."
printf "\\033[0;35m%s\\033[0m\\n" "If you want ghcup to automatically fix your ~/.bashrc to include the required PATH variable"
printf "\\033[0;35m%s\\033[0m\\n" "answer with YES and press ENTER."
printf "\\033[0;35m%s\\033[0m\\n" "Otherwise press ctrl-c to abort."
printf "\\033[0;35m%s\\033[0m\\n" ""
if [ -f "$HOME/.bashrc" ] ; then
GHCUP_PROFILE_FILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ] ; then
GHCUP_PROFILE_FILE="$HOME/.bash_profile"
fi
read -r next_answer </dev/tty
if [ -n "${GHCUP_PROFILE_FILE}" ] && [ -f "${GHCUP_PROFILE_FILE}" ] ; then
printf "\\033[0;35m%s\\033[0m\\n" ""
printf "\\033[0;35m%s\\033[0m\\n" "Detected \"${GHCUP_PROFILE_FILE}\" on your system..."
printf "\\033[0;35m%s\\033[0m\\n" "If you want ghcup to automatically fix your \"${GHCUP_PROFILE_FILE}\" to include the required PATH variable"
printf "\\033[0;35m%s\\033[0m\\n" "answer with YES, otherwise with NO and press ENTER."
printf "\\033[0;35m%s\\033[0m\\n" ""
case $next_answer in
[Yy]*)
echo "source $GHCUP_INSTALL_BASE_PREFIX/.ghcup/env" >> "${HOME}/.bashrc"
;;
*)
exit 0;;
esac
elif [ -e "$HOME/.bash_profile" ] ; then
printf "\\033[0;35m%s\\033[0m\\n" ""
printf "\\033[0;35m%s\\033[0m\\n" "Detected ~/.bash_profile on your system..."
printf "\\033[0;35m%s\\033[0m\\n" "If you want ghcup to automatically fix your ~/.bash_profile to include the required PATH variable"
printf "\\033[0;35m%s\\033[0m\\n" "answer with YES and press ENTER."
printf "\\033[0;35m%s\\033[0m\\n" "Otherwise press ctrl-c to abort."
printf "\\033[0;35m%s\\033[0m\\n" ""
while true; do
read -r next_answer </dev/tty
read -r next_answer </dev/tty
case $next_answer in
[Yy]*)
echo "source $GHCUP_INSTALL_BASE_PREFIX/.ghcup/env" >> "${HOME}/.bash_profile"
;;
*)
exit 0;;
esac
fi
case $next_answer in
[Yy]*)
echo "source $GHCUP_INSTALL_BASE_PREFIX/.ghcup/env" >> "${GHCUP_PROFILE_FILE}"
exit 0;;
[Nn]*)
exit 0;;
*)
echo "Please type YES or NO and press enter.";;
esac
done
fi
fi
)