Merge branch 'bootstrap'
This commit is contained in:
commit
225d2d2be4
18
README.md
18
README.md
@ -19,6 +19,24 @@ Similar in scope to [rustup](https://github.com/rust-lang-nursery/rustup.rs), [p
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
### Simple bootstrap of ghcup, GHC and cabal-install
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# complete bootstrap
|
||||||
|
curl https://raw.githubusercontent.com/haskell/ghcup/master/bootstrap-haskell -sSf | sh
|
||||||
|
|
||||||
|
# prepare your environment
|
||||||
|
. "$HOME/.ghcup/env"
|
||||||
|
echo '. $HOME/.ghcup/env' >> "$HOME/.bashrc" # or similar
|
||||||
|
|
||||||
|
# now create a project, such as:
|
||||||
|
mkdir myproject && cd myproject
|
||||||
|
cabal init -n --is-executable
|
||||||
|
cabal v2-run
|
||||||
|
```
|
||||||
|
|
||||||
|
### Manual install
|
||||||
|
|
||||||
Just place the `ghcup` shell script into your `PATH` anywhere.
|
Just place the `ghcup` shell script into your `PATH` anywhere.
|
||||||
|
|
||||||
E.g.:
|
E.g.:
|
||||||
|
75
bootstrap-haskell
Executable file
75
bootstrap-haskell
Executable file
@ -0,0 +1,75 @@
|
|||||||
|
#!/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()
|
||||||
|
{
|
||||||
|
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
|
||||||
|
edo cabal new-install --symlink-bindir="$HOME/.cabal/bin" 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" ""
|
||||||
|
|
||||||
|
|
||||||
|
)
|
64
ghcup
64
ghcup
@ -239,13 +239,15 @@ set_usage() {
|
|||||||
Set the currently active GHC to the specified version
|
Set the currently active GHC to the specified version
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
${SCRIPT} set [FLAGS] <VERSION>
|
${SCRIPT} set [FLAGS] [VERSION|TAG]
|
||||||
|
|
||||||
FLAGS:
|
FLAGS:
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
|
|
||||||
ARGS:
|
ARGS:
|
||||||
<VERSION> E.g. \"8.4.3\" or \"8.6.1\"
|
[VERSION|TAG] E.g. \"8.4.3\" or \"8.6.3\" or
|
||||||
|
a tag like \"recommended\" or \"latest\"
|
||||||
|
(default: discovers recommended version)
|
||||||
|
|
||||||
DISCUSSION:
|
DISCUSSION:
|
||||||
Sets the the current GHC version by creating non-versioned
|
Sets the the current GHC version by creating non-versioned
|
||||||
@ -1004,34 +1006,6 @@ posix_realpath() {
|
|||||||
unset mysource mydir posix_realpath_error
|
unset mysource mydir posix_realpath_error
|
||||||
}
|
}
|
||||||
|
|
||||||
# @FUNCTION: is_sourced
|
|
||||||
# @DESCRIPTION:
|
|
||||||
# Tries to figure out if we are being sourced. Based on
|
|
||||||
# https://stackoverflow.com/a/28776166
|
|
||||||
# @RETURNS: 0 if we are being sourced, 1 otherwise
|
|
||||||
is_sourced() {
|
|
||||||
if [ -n "$ZSH_EVAL_CONTEXT" ]; then
|
|
||||||
case $ZSH_EVAL_CONTEXT in
|
|
||||||
*:file)
|
|
||||||
return 0 ;;
|
|
||||||
esac
|
|
||||||
elif [ -n "$KSH_VERSION" ]; then
|
|
||||||
# shellcheck disable=SC2154
|
|
||||||
[ "$(cd "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")" != "$(cd "$(dirname -- "${.sh.file}")" && pwd -P)/$(basename -- "${.sh.file}")" ] && return 0
|
|
||||||
elif [ -n "$BASH_VERSION" ]; then
|
|
||||||
# shellcheck disable=SC2128
|
|
||||||
[ "$0" != "$BASH_SOURCE" ] && return 0
|
|
||||||
else # All other shells: examine $0 for known shell binary filenames
|
|
||||||
# Detects `sh` and `dash`; add additional shell filenames as needed.
|
|
||||||
case ${0##*/} in
|
|
||||||
sh|dash)
|
|
||||||
return 0 ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# assume we are not sourced, if our above checks didn't find it
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# @FUNCTION: get_meta_version_file
|
# @FUNCTION: get_meta_version_file
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
@ -1188,7 +1162,8 @@ install_ghc() {
|
|||||||
if ${FORCE} ; then
|
if ${FORCE} ; then
|
||||||
echo "GHC already installed in ${inst_location}, overwriting!"
|
echo "GHC already installed in ${inst_location}, overwriting!"
|
||||||
else
|
else
|
||||||
die "GHC already installed in ${inst_location}, use --force to overwrite"
|
warning_message "GHC already installed in ${inst_location}, use --force to overwrite"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
first_install=false
|
first_install=false
|
||||||
fi
|
fi
|
||||||
@ -1693,11 +1668,9 @@ fi
|
|||||||
#--[ Command line parsing and entry point ]--#
|
#--[ Command line parsing and entry point ]--#
|
||||||
##############################################
|
##############################################
|
||||||
|
|
||||||
if ! is_sourced ; then
|
[ $# -lt 1 ] && usage
|
||||||
|
|
||||||
[ $# -lt 1 ] && usage
|
while [ $# -gt 0 ] ; do
|
||||||
|
|
||||||
while [ $# -gt 0 ] ; do
|
|
||||||
case $1 in
|
case $1 in
|
||||||
-v|--verbose)
|
-v|--verbose)
|
||||||
VERBOSE=true
|
VERBOSE=true
|
||||||
@ -1784,8 +1757,24 @@ if ! is_sourced ; then
|
|||||||
break;;
|
break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
[ -n "${GHC_VER}" ] || set_usage
|
|
||||||
|
if [ -z "${GHC_VER}" ] ; then
|
||||||
|
_tool_ver="$(get_tool_ver_from_tag "ghc" "recommended")"
|
||||||
|
if [ -z "${_tool_ver}" ] ; then
|
||||||
|
die "Could not find a recommended GHC version, please report a bug at ${BUG_URL}!"
|
||||||
|
fi
|
||||||
|
set_ghc "${_tool_ver}"
|
||||||
|
else
|
||||||
|
# could be a version or a tag, let's check
|
||||||
|
if array_contains "${GHC_VER}" "$(known_tool_versions "ghc")" ; then
|
||||||
set_ghc "${GHC_VER}"
|
set_ghc "${GHC_VER}"
|
||||||
|
elif array_contains "${GHC_VER}" "$(known_tool_tags "ghc")" ; then
|
||||||
|
set_ghc "$(get_tool_ver_from_tag "ghc" "${GHC_VER}")"
|
||||||
|
else
|
||||||
|
die "\"${GHC_VER}\" is not a known version or tag!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
break;;
|
break;;
|
||||||
upgrade)
|
upgrade)
|
||||||
shift 1
|
shift 1
|
||||||
@ -1907,8 +1896,7 @@ if ! is_sourced ; then
|
|||||||
esac
|
esac
|
||||||
break;;
|
break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
fi # is_sourced
|
|
||||||
|
|
||||||
|
|
||||||
# vim: tabstop=4 shiftwidth=4 expandtab
|
# vim: tabstop=4 shiftwidth=4 expandtab
|
||||||
|
Loading…
Reference in New Issue
Block a user