2018-12-01 05:15:57 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# safety subshell to avoid executing anything in case this script is not downloaded properly
|
|
|
|
(
|
|
|
|
|
2019-01-24 13:36:44 +00:00
|
|
|
: "${GHCUP_INSTALL_BASE_PREFIX:=$HOME}"
|
|
|
|
|
2018-12-01 05:15:57 +00:00
|
|
|
die() {
|
|
|
|
(>&2 printf "\\033[0;31m%s\\033[0m\\n" "$1")
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
edo()
|
|
|
|
{
|
2019-04-11 02:42:29 +00:00
|
|
|
"$@" || die "\"$*\" failed!"
|
2018-12-01 05:15:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-21 07:40:11 +00:00
|
|
|
eghcup() {
|
2019-11-05 04:04:30 +00:00
|
|
|
if [ -z "${BOOTSTRAP_HASKELL_VERBOSE}" ] ; then
|
|
|
|
edo ghcup "$@"
|
|
|
|
else
|
|
|
|
edo ghcup --verbose "$@"
|
|
|
|
fi
|
2019-10-21 07:40:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-01 05:15:57 +00:00
|
|
|
echo
|
|
|
|
echo "Welcome to Haskell!"
|
|
|
|
echo
|
|
|
|
echo "This will download and install the Glasgow Haskell Compiler (GHC) for "
|
|
|
|
echo "the Haskell programming language, and the Cabal build tool."
|
|
|
|
echo
|
|
|
|
echo "It will add the 'cabal', 'ghc', and 'ghcup' executables to bin directory "
|
|
|
|
echo "located at: "
|
|
|
|
echo
|
2019-01-24 13:36:44 +00:00
|
|
|
echo " $GHCUP_INSTALL_BASE_PREFIX/.ghcup/bin"
|
2018-12-01 05:15:57 +00:00
|
|
|
echo
|
2019-01-24 13:36:44 +00:00
|
|
|
echo "and create the environment file $GHCUP_INSTALL_BASE_PREFIX/.ghcup/env"
|
2018-12-01 05:15:57 +00:00
|
|
|
echo "which you should source in your ~/.bashrc or similar to get the required"
|
|
|
|
echo "PATH components."
|
|
|
|
echo
|
|
|
|
|
|
|
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
2019-11-05 04:04:30 +00:00
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "To proceed with the ghcup installation press ENTER, to cancel press ctrl-c."
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "Note that this script can be re-run at any given time."
|
|
|
|
echo
|
|
|
|
# Wait for user input to continue.
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
read -r answer </dev/tty
|
2018-12-01 05:15:57 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-24 13:36:44 +00:00
|
|
|
edo mkdir -p "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin
|
2018-12-01 05:15:57 +00:00
|
|
|
|
|
|
|
if command -V "ghcup" >/dev/null 2>&1 ; then
|
2019-11-05 04:04:30 +00:00
|
|
|
if [ -z "${BOOTSTRAP_HASKELL_NO_UPGRADE}" ] ; then
|
|
|
|
eghcup upgrade
|
|
|
|
fi
|
2018-12-01 05:15:57 +00:00
|
|
|
else
|
2019-11-05 04:04:30 +00:00
|
|
|
edo curl --silent https://gitlab.haskell.org/haskell/ghcup/raw/master/ghcup > "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/ghcup
|
|
|
|
edo chmod +x "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/ghcup
|
2018-12-01 05:15:57 +00:00
|
|
|
|
2019-01-24 13:36:44 +00:00
|
|
|
cat <<-EOF > "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/env || die "Failed to create env file"
|
|
|
|
export PATH="\$HOME/.cabal/bin:\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/bin:\$PATH"
|
2018-12-01 05:15:57 +00:00
|
|
|
EOF
|
|
|
|
# shellcheck disable=SC1090
|
2019-11-05 04:04:30 +00:00
|
|
|
edo . "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/env
|
2018-12-01 05:15:57 +00:00
|
|
|
fi
|
|
|
|
|
2019-04-02 03:39:21 +00:00
|
|
|
echo
|
2019-08-21 14:14:37 +00:00
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "To install and run GHC you need the following dependencies:"
|
2019-04-02 03:39:21 +00:00
|
|
|
echo " $(ghcup print-system-reqs)"
|
|
|
|
echo
|
|
|
|
|
|
|
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
2019-11-05 04:04:30 +00:00
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "You may want to install these now, then press ENTER to proceed"
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "or press ctrl-c to abort. Installation may take a while."
|
|
|
|
echo
|
2019-04-02 03:39:21 +00:00
|
|
|
|
2019-11-05 04:04:30 +00:00
|
|
|
# Wait for user input to continue.
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
read -r answer </dev/tty
|
2019-04-02 03:39:21 +00:00
|
|
|
fi
|
|
|
|
|
2019-10-21 07:40:11 +00:00
|
|
|
eghcup --cache install
|
2018-12-01 05:15:57 +00:00
|
|
|
|
2019-10-21 07:40:11 +00:00
|
|
|
eghcup set
|
|
|
|
eghcup --cache install-cabal
|
2018-12-01 05:15:57 +00:00
|
|
|
|
|
|
|
edo cabal new-update
|
|
|
|
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" ""
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "Installation done!"
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" ""
|
|
|
|
|
2019-10-15 21:24:15 +00:00
|
|
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|
|
|
echo "In order to run ghc and cabal, you need to adjust your PATH variable."
|
|
|
|
echo "You may want to source '$GHCUP_INSTALL_BASE_PREFIX/.ghcup/env' in your shell"
|
|
|
|
echo "configuration to do so (e.g. ~/.bashrc)."
|
|
|
|
|
2019-10-22 03:44:50 +00:00
|
|
|
if [ -f "$HOME/.bashrc" ] ; then
|
2019-11-05 04:04:30 +00:00
|
|
|
GHCUP_PROFILE_FILE="$HOME/.bashrc"
|
2019-10-22 03:44:50 +00:00
|
|
|
elif [ -f "$HOME/.bash_profile" ] ; then
|
2019-11-05 04:04:30 +00:00
|
|
|
GHCUP_PROFILE_FILE="$HOME/.bash_profile"
|
|
|
|
else
|
|
|
|
# most complaints we get are from mac users who
|
|
|
|
# need assistance of setting up their shell, so suggest
|
|
|
|
# to create .bash_profile, which is a good guess
|
|
|
|
GHCUP_PROFILE_FILE="$HOME/.bash_profile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -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" ""
|
|
|
|
elif [ -n "${BASH}" ] ; then # only suggest to create .bash_profile if we are in a bash shell
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" ""
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "Detected bash shell on your system..."
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "If you want ghcup to automatically create \"${GHCUP_PROFILE_FILE}\" and 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" ""
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
read -r next_answer </dev/tty
|
|
|
|
|
|
|
|
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
|
2019-10-15 21:24:15 +00:00
|
|
|
fi
|
2018-12-01 05:15:57 +00:00
|
|
|
)
|
2019-04-02 03:39:21 +00:00
|
|
|
|
|
|
|
# vim: tabstop=4 shiftwidth=4 expandtab
|
|
|
|
|