ghcup/bootstrap-haskell
Julian Ospald 99843f3201
Fix edo in bootstrap-haskell
This seems to have caused occasional weird
side-effects on the following line:

  edo curl https://raw.githubusercontent.com/haskell/ghcup/master/ghcup > "${HOME}"/.ghcup/bin/ghcup
  ...
  edo ghcup install

It would result in:

  ~/.ghcup/bin/ghcup: line 1: $'\E[0': command not found
  ~/.ghcup/bin/ghcup: line 1: 35mcurl: command not found

which seems to be because of printf and the piping command.
It's not entirely clear to me what happens here, but it
seems part of the printf output to stdout where mixed
with the next command.
2019-01-24 14:18:47 +08:00

77 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
# safety subshell to avoid executing anything in case this script is not downloaded properly
(
die() {
(>&2 printf "\\033[0;31m%s\\033[0m\\n" "$1")
exit 2
}
edo()
{
(>&2 printf "\\033[0;35m%s\\033[0m\\n" "$*")
"$@" || exit 2
}
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
echo " $HOME/.ghcup/bin"
echo
echo "and create the environment file $HOME/.ghcup/env"
echo "which you should source in your ~/.bashrc or similar to get the required"
echo "PATH components."
echo
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
echo "To proceed with the installation press enter, to cancel press ctrl-c."
echo "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 "${HOME}"/.ghcup/bin
if command -V "ghcup" >/dev/null 2>&1 ; then
if [ -z "${BOOTSTRAP_HASKELL_NO_UPGRADE}" ] ; then
edo ghcup upgrade
fi
else
edo curl https://raw.githubusercontent.com/haskell/ghcup/master/ghcup > "${HOME}"/.ghcup/bin/ghcup
edo chmod +x "${HOME}"/.ghcup/bin/ghcup
cat <<-EOF > "${HOME}"/.ghcup/env || die "Failed to create env file"
export PATH="\$HOME/.cabal/bin:\$HOME/.ghcup/bin:\$PATH"
EOF
# shellcheck disable=SC1090
edo . "${HOME}"/.ghcup/env
fi
edo ghcup install
edo ghcup set
edo ghcup install-cabal
edo cabal new-update
# 1 job until https://github.com/haskell/cabal/issues/5776 is fixed
edo cabal new-install --symlink-bindir="$HOME/.cabal/bin" --jobs=1 cabal-install
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" ""
printf "\\033[0;35m%s\\033[0m\\n" "Don't forget to source $HOME/.ghcup/env in your ~/.bashrc or similar."
printf "\\033[0;35m%s\\033[0m\\n" ""
)