diff --git a/bootstrap-haskell b/bootstrap-haskell index 86dc0c6..d959b80 100755 --- a/bootstrap-haskell +++ b/bootstrap-haskell @@ -5,8 +5,12 @@ # * BOOTSTRAP_HASKELL_NO_UPGRADE - any nonzero value to not trigger the upgrade # * GHCUP_USE_XDG_DIRS - any nonzero value to respect The XDG Base Directory Specification # * BOOTSTRAP_HASKELL_VERBOSE - any nonzero value for more verbose installation -# * BOOTSTRAP_HASKELL_GHC_VERSION -# * BOOTSTRAP_HASKELL_CABAL_VERSION +# * BOOTSTRAP_HASKELL_GHC_VERSION - the ghc version to install +# * BOOTSTRAP_HASKELL_CABAL_VERSION - the cabal version to install +# * BOOTSTRAP_HASKELL_INSTALL_STACK - whether to install latest stack +# * BOOTSTRAP_HASKELL_INSTALL_HLS - whether to install latest hls +# * BOOTSTRAP_HASKELL_ADJUST_BASHRC - whether to adjust PATH in bashrc (prepend) +# * BOOTSTRAP_HASKELL_ADJUST_CABAL_CONFIG - whether to adjust mingw paths in cabal.config on windows # License: LGPL-3.0 @@ -19,6 +23,8 @@ arch=$(uname -m) ghver="0.1.15.2" base_url="https://downloads.haskell.org/~ghcup" +export GHCUP_SKIP_UPDATE_CHECK=yes + case "${plat}" in MSYS*|MINGW*) : "${GHCUP_INSTALL_BASE_PREFIX:=/c}" @@ -60,6 +66,28 @@ warn() { esac } +yellow() { + case "${plat}" in + MSYS*|MINGW*) + echo -e "\\033[0;33m$1\\033[0m" + ;; + *) + printf "\\033[0;33m%s\\033[0m\\n" "$1" + ;; + esac +} + +green() { + case "${plat}" in + MSYS*|MINGW*) + echo -e "\\033[0;32m$1\\033[0m" + ;; + *) + printf "\\033[0;32m%s\\033[0m\\n" "$1" + ;; + esac +} + edo() { "$@" || die "\"$*\" failed!" } @@ -80,40 +108,42 @@ _eghcup() { } _done() { + echo + echo "===============================================================================" case "${plat}" in MSYS*|MINGW*) - echo - echo "All done!" - echo - echo "In a new powershell or cmd.exe session, now you can..." - echo - echo "Start a simple repl via:" - echo " ghci" - echo - echo "Start a new haskell project in the current directory via:" - echo " cabal init --interactive" - echo - echo "Install other GHC versions and tools via:" - echo " ghcup list" - echo " ghcup install " - echo - echo "To install system libraries and update msys2/mingw64," - echo "open the \"Mingw haskell shell\"" - echo "and the \"Mingw package management docs\"" - echo "desktop shortcuts." + green + green "All done!" + green + green "In a new powershell or cmd.exe session, now you can..." + green + green "Start a simple repl via:" + green " ghci" + green + green "Start a new haskell project in the current directory via:" + green " cabal init --interactive" + green + green "Install other GHC versions and tools via:" + green " ghcup list" + green " ghcup install " + green + green "To install system libraries and update msys2/mingw64," + green "open the \"Mingw haskell shell\"" + green "and the \"Mingw package management docs\"" + green "desktop shortcuts." ;; *) - echo - echo "All done!" - echo - echo "To start a simple repl, run:" - echo " ghci" - echo - echo "To start a new haskell project in the current directory, run:" - echo " cabal init --interactive" - echo - echo "To install other GHC versions and tools, run:" - echo " ghcup tui" + green + green "All done!" + green + green "To start a simple repl, run:" + green " ghci" + green + green "To start a new haskell project in the current directory, run:" + green " cabal init --interactive" + green + green "To install other GHC versions and tools, run:" + green " ghcup tui" ;; esac @@ -213,7 +243,9 @@ download_ghcup() { eghcup upgrade } -adjust_bashrc() { +# Figures out the users login shell and sets +# GHCUP_PROFILE_FILE and MY_SHELL variables. +find_shell() { case $SHELL in */zsh) # login shell is zsh GHCUP_PROFILE_FILE="$HOME/.zshrc" @@ -237,75 +269,38 @@ adjust_bashrc() { MY_SHELL="fish" ;; *) return ;; esac +} - - warn "" - warn "Detected ${MY_SHELL} shell on your system..." - warn "Do you want ghcup to automatically add the required PATH variable to \"${GHCUP_PROFILE_FILE}\"?" - warn "" - warn "[P] Yes, prepend [A] Yes, append [N] No [?] Help (default is \"P\")." - warn "" +# Ask user if they want to adjust the bashrc. +ask_bashrc() { + if [ -n "${BOOTSTRAP_HASKELL_ADJUST_BASHRC}" ] ; then + return 1 + fi while true; do if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then - read -r next_answer "${GHCUP_DIR}"/env || die "Failed to create env file" - export PATH="\$HOME/.cabal/bin:${GHCUP_BIN}:\$PATH" - EOF + return 1 ;; [Aa]*) - cat <<-EOF > "${GHCUP_DIR}"/env || die "Failed to create env file" - export PATH="\$HOME/.cabal/bin:\$PATH:${GHCUP_BIN}" - EOF + return 2 ;; - *) ;; - esac - - case $next_answer in [Nn]*) - return ;; - [Pp]* | [Aa]* | "") - case $MY_SHELL in - "") break ;; - fish) - mkdir -p "${GHCUP_PROFILE_FILE%/*}" - sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}" - case $next_answer in - [Pp]* | "") - echo "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME ; set -gx PATH \$HOME/.cabal/bin $GHCUP_BIN \$PATH # ghcup-env" >> "${GHCUP_PROFILE_FILE}" - ;; - [Aa]*) - echo "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME ; set -gx PATH \$HOME/.cabal/bin \$PATH $GHCUP_BIN # ghcup-env" >> "${GHCUP_PROFILE_FILE}" - ;; - esac - break ;; - bash) - sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}" - echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}" - case "${plat}" in - "Darwin"|"darwin") - if ! grep -q "ghcup-env" "${HOME}/.bash_profile" ; then - echo "[[ -f ~/.bashrc ]] && source ~/.bashrc # ghcup-env" >> "${HOME}/.bash_profile" - fi - ;; - esac - break ;; - - zsh) - sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}" - echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}" - break ;; - esac - warn "OK! ${GHCUP_PROFILE_FILE} has been modified. Restart your terminal for the changes to take effect," - warn "or type \"source ${GHCUP_DIR}/env\" to apply them in your current terminal session." - return - ;; + return 0;; *) echo "Possible choices are:" echo @@ -317,8 +312,216 @@ adjust_bashrc() { ;; esac done + + unset bashrc_answer } +# Needs 'find_shell' to be called beforehand. +adjust_bashrc() { + case $1 in + 1) + cat <<-EOF > "${GHCUP_DIR}"/env || die "Failed to create env file" + export PATH="\$HOME/.cabal/bin:${GHCUP_BIN}:\$PATH" + EOF + ;; + 2) + cat <<-EOF > "${GHCUP_DIR}"/env || die "Failed to create env file" + export PATH="\$HOME/.cabal/bin:\$PATH:${GHCUP_BIN}" + EOF + ;; + *) ;; + esac + + case $1 in + 1 | 2) + case $MY_SHELL in + "") break ;; + fish) + mkdir -p "${GHCUP_PROFILE_FILE%/*}" + sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}" + case $1 in + 1) + echo "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME ; set -gx PATH \$HOME/.cabal/bin $GHCUP_BIN \$PATH # ghcup-env" >> "${GHCUP_PROFILE_FILE}" + ;; + 2) + echo "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME ; set -gx PATH \$HOME/.cabal/bin \$PATH $GHCUP_BIN # ghcup-env" >> "${GHCUP_PROFILE_FILE}" + ;; + esac + break ;; + bash) + sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}" + echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}" + case "${plat}" in + "Darwin"|"darwin") + if ! grep -q "ghcup-env" "${HOME}/.bash_profile" ; then + echo "[[ -f ~/.bashrc ]] && source ~/.bashrc # ghcup-env" >> "${HOME}/.bash_profile" + fi + ;; + esac + break ;; + + zsh) + sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}" + echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}" + break ;; + esac + warn "OK! ${GHCUP_PROFILE_FILE} has been modified. Restart your terminal for the changes to take effect," + warn "or type \"source ${GHCUP_DIR}/env\" to apply them in your current terminal session." + return + ;; + *) + ;; + esac +} + +adjust_cabal_config() { + edo cabal user-config -a "extra-prog-path: $(cygpath -w "$GHCUP_BIN"), $(cygpath -w "$HOME"/AppData/Roaming/cabal/bin), $(cygpath -w "$GHCUP_MSYS2"/usr/bin), $(cygpath -w "$GHCUP_MSYS2"/mingw64/bin)" -a "extra-include-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/include)" -a "extra-lib-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/lib)" -f init +} + +ask_cabal_config_init() { + case "${plat}" in + MSYS*|MINGW*) + if [ -n "${BOOTSTRAP_HASKELL_ADJUST_CABAL_CONFIG}" ] ; then + return 1 + fi + + if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then + echo "-------------------------------------------------------------------------------" + warn "Create an initial cabal.config including relevant msys2 paths (recommended)?" + warn "[Y] Yes [N] No [?] Help (default is \"Y\")." + echo + while true; do + read -r mingw_answer /dev/null 2>&1 ; then @@ -385,118 +596,52 @@ eghcup --cache install ghc "${BOOTSTRAP_HASKELL_GHC_VERSION}" eghcup set ghc "${BOOTSTRAP_HASKELL_GHC_VERSION}" eghcup --cache install cabal "${BOOTSTRAP_HASKELL_CABAL_VERSION}" -adjust_cabal_config() { - edo cabal user-config -a "extra-prog-path: $(cygpath -w "$GHCUP_BIN"), $(cygpath -w "$HOME"/AppData/Roaming/cabal/bin), $(cygpath -w "$GHCUP_MSYS2"/usr/bin), $(cygpath -w "$GHCUP_MSYS2"/mingw64/bin)" -a "extra-include-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/include)" -a "extra-lib-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/lib)" -f init -} - -case "${plat}" in - MSYS*|MINGW*) - if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then - warn "Create an initial cabal.config including relevant msys2 paths (recommended)?" - warn "[Y] Yes [N] No [?] Help (default is \"Y\")." - echo - while true; do - read -r mingw_answer