You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

157 lines
4.9 KiB

  1. #!/bin/sh
  2. # safety subshell to avoid executing anything in case this script is not downloaded properly
  3. (
  4. : "${GHCUP_INSTALL_BASE_PREFIX:=$HOME}"
  5. die() {
  6. (>&2 printf "\\033[0;31m%s\\033[0m\\n" "$1")
  7. exit 2
  8. }
  9. edo()
  10. {
  11. "$@" || die "\"$*\" failed!"
  12. }
  13. eghcup() {
  14. if [ -z "${BOOTSTRAP_HASKELL_VERBOSE}" ] ; then
  15. edo ghcup "$@"
  16. else
  17. edo ghcup --verbose "$@"
  18. fi
  19. }
  20. echo
  21. echo "Welcome to Haskell!"
  22. echo
  23. echo "This will download and install the Glasgow Haskell Compiler (GHC) for "
  24. echo "the Haskell programming language, and the Cabal build tool."
  25. echo
  26. echo "It will add the 'cabal', 'ghc', and 'ghcup' executables to bin directory "
  27. echo "located at: "
  28. echo
  29. echo " $GHCUP_INSTALL_BASE_PREFIX/.ghcup/bin"
  30. echo
  31. echo "and create the environment file $GHCUP_INSTALL_BASE_PREFIX/.ghcup/env"
  32. echo "which you should source in your ~/.bashrc or similar to get the required"
  33. echo "PATH components."
  34. echo
  35. if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
  36. printf "\\033[0;35m%s\\033[0m\\n" "To proceed with the ghcup installation press ENTER, to cancel press ctrl-c."
  37. printf "\\033[0;35m%s\\033[0m\\n" "Note that this script can be re-run at any given time."
  38. echo
  39. # Wait for user input to continue.
  40. # shellcheck disable=SC2034
  41. read -r answer </dev/tty
  42. fi
  43. edo mkdir -p "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin
  44. if command -V "ghcup" >/dev/null 2>&1 ; then
  45. if [ -z "${BOOTSTRAP_HASKELL_NO_UPGRADE}" ] ; then
  46. eghcup upgrade
  47. fi
  48. else
  49. edo curl --silent https://gitlab.haskell.org/haskell/ghcup/raw/master/ghcup > "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/ghcup
  50. edo chmod +x "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/ghcup
  51. cat <<-EOF > "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/env || die "Failed to create env file"
  52. export PATH="\$HOME/.cabal/bin:\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/bin:\$PATH"
  53. EOF
  54. # shellcheck disable=SC1090
  55. edo . "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/env
  56. fi
  57. echo
  58. printf "\\033[0;35m%s\\033[0m\\n" "To install and run GHC you need the following dependencies:"
  59. echo " $(ghcup print-system-reqs)"
  60. echo
  61. if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
  62. printf "\\033[0;35m%s\\033[0m\\n" "You may want to install these now, then press ENTER to proceed"
  63. printf "\\033[0;35m%s\\033[0m\\n" "or press ctrl-c to abort. Installation may take a while."
  64. echo
  65. # Wait for user input to continue.
  66. # shellcheck disable=SC2034
  67. read -r answer </dev/tty
  68. fi
  69. eghcup --cache install
  70. eghcup set
  71. eghcup --cache install-cabal
  72. edo cabal new-update
  73. printf "\\033[0;35m%s\\033[0m\\n" ""
  74. printf "\\033[0;35m%s\\033[0m\\n" "Installation done!"
  75. printf "\\033[0;35m%s\\033[0m\\n" ""
  76. if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
  77. echo "In order to run ghc and cabal, you need to adjust your PATH variable."
  78. echo "You may want to source '$GHCUP_INSTALL_BASE_PREFIX/.ghcup/env' in your shell"
  79. echo "configuration to do so (e.g. ~/.bashrc)."
  80. case $SHELL in
  81. */zsh) # login shell is zsh
  82. GHCUP_PROFILE_FILE="$HOME/.zshrc"
  83. MY_SHELL="zsh" ;;
  84. */bash) # login shell is bash
  85. if [ -f "$HOME/.bashrc" ] ; then # bashrc is not sourced by default, so assume it isn't if file does not exist
  86. GHCUP_PROFILE_FILE="$HOME/.bashrc"
  87. else
  88. GHCUP_PROFILE_FILE="$HOME/.bash_profile"
  89. fi
  90. MY_SHELL="bash" ;;
  91. */sh) # login shell is sh, but might be a symlink to bash or zsh
  92. if [ -n "${BASH}" ] ; then
  93. if [ -f "$HOME/.bashrc" ] ; then # bashrc is not sourced by default, so assume it isn't if file does not exist
  94. GHCUP_PROFILE_FILE="$HOME/.bashrc"
  95. else
  96. GHCUP_PROFILE_FILE="$HOME/.bash_profile"
  97. fi
  98. MY_SHELL="bash"
  99. elif [ -n "${ZSH_VERSION}" ] ; then
  100. GHCUP_PROFILE_FILE="$HOME/.zshrc"
  101. MY_SHELL="zsh"
  102. else
  103. exit 0
  104. fi
  105. ;;
  106. *) exit 0 ;;
  107. esac
  108. printf "\\033[0;35m%s\\033[0m\\n" ""
  109. printf "\\033[0;35m%s\\033[0m\\n" "Detected ${MY_SHELL} shell on your system..."
  110. printf "\\033[0;35m%s\\033[0m\\n" "If you want ghcup to automatically add the required PATH variable to \"${GHCUP_PROFILE_FILE}\""
  111. printf "\\033[0;35m%s\\033[0m\\n" "answer with YES, otherwise with NO and press ENTER."
  112. printf "\\033[0;35m%s\\033[0m\\n" ""
  113. while true; do
  114. read -r next_answer </dev/tty
  115. case $next_answer in
  116. [Yy]*)
  117. echo "[ -f \"\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/env\" ] && source \"\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/env\"" >> "${GHCUP_PROFILE_FILE}"
  118. printf "\\033[0;35m%s\\033[0m\\n" "OK! ${GHCUP_PROFILE_FILE} has been modified. Restart your terminal for the changes to take effect,"
  119. 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."
  120. exit 0;;
  121. [Nn]*)
  122. exit 0;;
  123. *)
  124. echo "Please type YES or NO and press enter.";;
  125. esac
  126. done
  127. fi
  128. )
  129. # vim: tabstop=4 shiftwidth=4 expandtab