2020-04-11 19:40:01 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# safety subshell to avoid executing anything in case this script is not downloaded properly
|
|
|
|
(
|
|
|
|
|
|
|
|
: "${GHCUP_INSTALL_BASE_PREFIX:=$HOME}"
|
2020-06-13 21:39:45 +00:00
|
|
|
: "${BOOTSTRAP_HASKELL_GHC_VERSION:=recommended}"
|
|
|
|
: "${BOOTSTRAP_HASKELL_CABAL_VERSION:=recommended}"
|
2020-04-11 19:40:01 +00:00
|
|
|
|
|
|
|
die() {
|
|
|
|
(>&2 printf "\\033[0;31m%s\\033[0m\\n" "$1")
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
edo()
|
|
|
|
{
|
|
|
|
"$@" || die "\"$*\" failed!"
|
|
|
|
}
|
|
|
|
|
|
|
|
eghcup() {
|
|
|
|
if [ -z "${BOOTSTRAP_HASKELL_VERBOSE}" ] ; then
|
|
|
|
edo ghcup "$@"
|
|
|
|
else
|
|
|
|
edo ghcup --verbose "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
download_ghcup() {
|
|
|
|
_plat="$(uname -s)"
|
|
|
|
_arch=$(uname -m)
|
2020-07-13 20:15:39 +00:00
|
|
|
_ghver="0.1.6"
|
2020-04-11 19:40:01 +00:00
|
|
|
|
|
|
|
case "${_plat}" in
|
|
|
|
"linux"|"Linux")
|
2020-04-13 13:22:16 +00:00
|
|
|
case "${_arch}" in
|
|
|
|
x86_64|amd64)
|
2020-05-01 14:27:41 +00:00
|
|
|
_url=https://downloads.haskell.org/~ghcup/${_ghver}/x86_64-linux-ghcup-${_ghver}
|
2020-04-13 13:22:16 +00:00
|
|
|
;;
|
|
|
|
i*86)
|
2020-05-01 14:27:41 +00:00
|
|
|
_url=https://downloads.haskell.org/~ghcup/${_ghver}/i386-linux-ghcup-${_ghver}
|
2020-04-13 13:22:16 +00:00
|
|
|
;;
|
|
|
|
*) die "Unknown architecture: ${_arch}"
|
|
|
|
;;
|
|
|
|
esac
|
2020-04-11 19:40:01 +00:00
|
|
|
;;
|
|
|
|
"FreeBSD"|"freebsd")
|
2020-04-13 13:22:16 +00:00
|
|
|
case "${_arch}" in
|
|
|
|
x86_64|amd64)
|
|
|
|
;;
|
|
|
|
i*86)
|
|
|
|
die "i386 currently not supported!"
|
|
|
|
;;
|
|
|
|
*) die "Unknown architecture: ${_arch}"
|
|
|
|
;;
|
|
|
|
esac
|
2020-05-01 14:27:41 +00:00
|
|
|
_url=https://downloads.haskell.org/~ghcup/${_ghver}/x86_64-portbld-freebsd-ghcup-${_ghver}
|
2020-04-11 19:40:01 +00:00
|
|
|
;;
|
|
|
|
"Darwin"|"darwin")
|
2020-04-13 13:22:16 +00:00
|
|
|
case "${_arch}" in
|
|
|
|
x86_64|amd64)
|
|
|
|
;;
|
|
|
|
i*86)
|
|
|
|
die "i386 currently not supported!"
|
|
|
|
;;
|
|
|
|
*) die "Unknown architecture: ${_arch}"
|
|
|
|
;;
|
|
|
|
esac
|
2020-07-13 20:15:39 +00:00
|
|
|
_url=https://downloads.haskell.org/~ghcup/${_ghver}/x86_64-apple-darwin-ghcup-${_ghver} ;;
|
2020-04-11 19:40:01 +00:00
|
|
|
*) die "Unknown platform: ${_plat}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-04-12 16:31:07 +00:00
|
|
|
edo curl -Lf "${_url}" > "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/ghcup
|
|
|
|
|
2020-05-01 14:27:41 +00:00
|
|
|
unset _plat _arch _url _ghver
|
2020-04-11 19:40:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Welcome to Haskell!"
|
|
|
|
echo
|
2020-05-06 20:33:52 +00:00
|
|
|
echo "This script will download and install the following binaries:"
|
|
|
|
echo " * ghcup - The Haskell toolchain installer (for managing GHC/cabal versions)"
|
|
|
|
echo " * ghc - The Glasgow Haskell Compiler"
|
|
|
|
echo " * cabal - The Cabal build tool"
|
2020-04-11 19:40:01 +00:00
|
|
|
echo
|
|
|
|
echo "ghcup installs only into the following directory, which can be removed anytime:"
|
|
|
|
echo " $GHCUP_INSTALL_BASE_PREFIX/.ghcup"
|
|
|
|
echo
|
|
|
|
|
|
|
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
2020-05-06 20:33:52 +00:00
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "Press ENTER to proceed or ctrl-c to abort."
|
2020-04-11 19:40:01 +00:00
|
|
|
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
|
|
|
|
fi
|
|
|
|
|
|
|
|
edo mkdir -p "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin
|
|
|
|
|
|
|
|
if command -V "ghcup" >/dev/null 2>&1 ; then
|
|
|
|
if [ -z "${BOOTSTRAP_HASKELL_NO_UPGRADE}" ] ; then
|
|
|
|
eghcup upgrade
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
download_ghcup
|
|
|
|
edo chmod +x "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/ghcup
|
|
|
|
|
|
|
|
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"
|
|
|
|
EOF
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
edo . "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/env
|
2020-04-15 17:53:26 +00:00
|
|
|
eghcup upgrade
|
2020-04-11 19:40:01 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "$(ghcup tool-requirements)"
|
|
|
|
echo
|
|
|
|
|
|
|
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
2020-05-06 20:33:52 +00:00
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "Press ENTER to proceed or ctrl-c to abort."
|
2020-04-11 19:40:01 +00:00
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "Installation may take a while."
|
|
|
|
echo
|
|
|
|
|
|
|
|
# Wait for user input to continue.
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
read -r answer </dev/tty
|
|
|
|
fi
|
|
|
|
|
2020-06-13 21:39:45 +00:00
|
|
|
eghcup --cache install "${BOOTSTRAP_HASKELL_GHC_VERSION}"
|
2020-04-11 19:40:01 +00:00
|
|
|
|
2020-06-13 21:39:45 +00:00
|
|
|
eghcup set "${BOOTSTRAP_HASKELL_GHC_VERSION}"
|
|
|
|
eghcup --cache install-cabal "${BOOTSTRAP_HASKELL_CABAL_VERSION}"
|
2020-04-11 19:40:01 +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" ""
|
|
|
|
|
|
|
|
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)."
|
|
|
|
|
|
|
|
case $SHELL in
|
|
|
|
*/zsh) # login shell is zsh
|
|
|
|
GHCUP_PROFILE_FILE="$HOME/.zshrc"
|
|
|
|
MY_SHELL="zsh" ;;
|
|
|
|
*/bash) # login shell is bash
|
2020-05-02 21:50:09 +00:00
|
|
|
GHCUP_PROFILE_FILE="$HOME/.bashrc"
|
2020-04-11 19:40:01 +00:00
|
|
|
MY_SHELL="bash" ;;
|
|
|
|
*/sh) # login shell is sh, but might be a symlink to bash or zsh
|
|
|
|
if [ -n "${BASH}" ] ; then
|
2020-05-02 21:50:09 +00:00
|
|
|
GHCUP_PROFILE_FILE="$HOME/.bashrc"
|
2020-04-11 19:40:01 +00:00
|
|
|
MY_SHELL="bash"
|
|
|
|
elif [ -n "${ZSH_VERSION}" ] ; then
|
|
|
|
GHCUP_PROFILE_FILE="$HOME/.zshrc"
|
|
|
|
MY_SHELL="zsh"
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*) exit 0 ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" ""
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "Detected ${MY_SHELL} shell on your system..."
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "If you want ghcup to automatically add the required PATH variable to \"${GHCUP_PROFILE_FILE}\""
|
|
|
|
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" ""
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
read -r next_answer </dev/tty
|
|
|
|
|
|
|
|
case $next_answer in
|
|
|
|
[Yy]*)
|
|
|
|
echo "[ -f \"\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/env\" ] && source \"\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/env\"" >> "${GHCUP_PROFILE_FILE}"
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "OK! ${GHCUP_PROFILE_FILE} has been modified. Restart your terminal for the changes to take effect,"
|
|
|
|
printf "\\033[0;35m%s\\033[0m\\n" "or type \"source ${GHCUP_INSTALL_BASE_PREFIX}/.ghcup/env\" to apply them in your current terminal session."
|
|
|
|
exit 0;;
|
|
|
|
[Nn]*)
|
|
|
|
exit 0;;
|
|
|
|
*)
|
|
|
|
echo "Please type YES or NO and press enter.";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
|
|
|
|
# vim: tabstop=4 shiftwidth=4 expandtab
|
|
|
|
|