|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +die() { |
| 4 | + (>&2 printf "\\033[0;31m%s\\033[0m\\n" "$1") |
| 5 | + exit 2 |
| 6 | +} |
| 7 | + |
| 8 | +edo() |
| 9 | +{ |
| 10 | + printf "\\033[0;35m%s\\033[0m\\n" "$*" |
| 11 | + "$@" || exit 2 |
| 12 | +} |
| 13 | + |
| 14 | +echo |
| 15 | +echo "Welcome to Haskell!" |
| 16 | +echo |
| 17 | +echo "This will download and install the Glasgow Haskell Compiler (GHC) for " |
| 18 | +echo "the Haskell programming language, and the Cabal build tool." |
| 19 | +echo |
| 20 | +echo "It will add the 'cabal', 'ghc', and 'ghcup' executables to bin directory " |
| 21 | +echo "located at: " |
| 22 | +echo |
| 23 | +echo " $HOME/.ghcup/bin" |
| 24 | +echo |
| 25 | +echo "and create the environment file $HOME/.ghcup/env" |
| 26 | +echo "which you should source in your ~/.bashrc or similar to get the required" |
| 27 | +echo "PATH components." |
| 28 | +echo |
| 29 | + |
| 30 | +if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then |
| 31 | + echo "To proceed with the installation press enter, to cancel press ctrl-c." |
| 32 | + echo "Note that this script can be re-run at any given time." |
| 33 | + echo |
| 34 | + |
| 35 | + # Wait for user input to continue. |
| 36 | + # shellcheck disable=SC2034 |
| 37 | + read -r answer </dev/tty |
| 38 | +fi |
| 39 | + |
| 40 | +edo mkdir -p "${HOME}"/.ghcup/bin |
| 41 | + |
| 42 | +if command -V "ghcup" >/dev/null 2>&1 ; then |
| 43 | + if [ -z "${BOOTSTRAP_HASKELL_NO_UPGRADE}" ] ; then |
| 44 | + edo ghcup upgrade |
| 45 | + fi |
| 46 | +else |
| 47 | + edo curl https://raw.githubusercontent.com/haskell/ghcup/master/ghcup > "${HOME}"/.ghcup/bin/ghcup |
| 48 | + edo chmod +x "${HOME}"/.ghcup/bin/ghcup |
| 49 | + |
| 50 | + cat <<-EOF > "${HOME}"/.ghcup/env || die "Failed to create env file" |
| 51 | + export PATH="\$HOME/.cabal/bin:\$HOME/.ghcup/bin:\$PATH" |
| 52 | + EOF |
| 53 | + # shellcheck disable=SC1090 |
| 54 | + edo . "${HOME}"/.ghcup/env |
| 55 | +fi |
| 56 | + |
| 57 | +edo ghcup install |
| 58 | + |
| 59 | +edo ghcup set |
| 60 | +edo ghcup install-cabal |
| 61 | + |
| 62 | +edo cabal new-update |
| 63 | +edo cabal new-install --symlink-bindir="$HOME/.cabal/bin" cabal-install |
| 64 | + |
| 65 | +printf "\\033[0;35m%s\\033[0m\\n" "" |
| 66 | +printf "\\033[0;35m%s\\033[0m\\n" "Installation done!" |
| 67 | +printf "\\033[0;35m%s\\033[0m\\n" "" |
| 68 | +printf "\\033[0;35m%s\\033[0m\\n" "Don't forget to source $HOME/.ghcup/env in your ~/.bashrc or similar." |
| 69 | +printf "\\033[0;35m%s\\033[0m\\n" "" |
0 commit comments