Add install-cabal subcommand, fixes #3

This commit is contained in:
Julian Ospald 2018-09-30 16:46:50 +08:00
parent 894a279a2d
commit ea2d5c20d9
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
3 changed files with 96 additions and 7 deletions

View File

@ -19,14 +19,13 @@ set -e
./ghcup -v set 8.2.2
# install cabal-install
wget https://www.haskell.org/cabal/release/cabal-install-2.2.0.0/cabal-install-2.2.0.0-x86_64-unknown-linux.tar.gz
tar -xzf cabal-install-2.2.0.0-x86_64-unknown-linux.tar.gz
./ghcup -v install-cabal
export PATH="$HOME/.ghcup/bin:$PATH"
export PATH="$HOME/.cabal/bin:$HOME/.ghcup/bin:$PATH"
# install shellcheck
./cabal update
./cabal install ShellCheck
cabal update
cabal install ShellCheck
# check our script for errors
~/.cabal/bin/shellcheck ghcup
shellcheck ghcup

View File

@ -55,7 +55,7 @@ See `ghcup --help`.
## Feature considerations
- [ ] Allow to compile from source ([#2](https://github.com/hasufell/ghcup/issues/2))
- [ ] Allow to install cabal-install as well ([#3](https://github.com/hasufell/ghcup/issues/3))
- [x] Allow to install cabal-install as well ([#3](https://github.com/hasufell/ghcup/issues/3))
## Known problems

90
ghcup
View File

@ -90,6 +90,11 @@ SCRIPT_UPDATE_URL="https://raw.githubusercontent.com/hasufell/ghcup/master/ghcup
# Base URL for all GHC tarballs.
GHC_DOWNLOAD_BASEURL="https://downloads.haskell.org/~ghc"
# @VARIABLE: KNOWN_GOOD_CABAL
# @DESCRIPTION:
# The latests known good cabal-install version for
# which a pre-built binary exists.
KNOWN_GOOD_CABAL="2.2.0.0"
####################
@ -119,6 +124,7 @@ SUBCOMMANDS:
set Set currently active GHC version
self-update Update this script in-place
rm Remove an already installed GHC
install-cabal Install cabal-install
DISCUSSION:
ghcup installs the Glasgow Haskell Compiler from the official
@ -237,6 +243,33 @@ ARGS:
exit 1
}
# @FUNCTION: install_cabal_usage
# @DESCRIPTION:
# Print the help message for 'ghcup install-cabal' to STDERR
# and exit the script with status code 1.
install_cabal_usage() {
(>&2 echo "ghcup-install-cabal
Install the specified or a default cabal version
USAGE:
${SCRIPT} install-cabal [FLAGS] [VERSION]
FLAGS:
-h, --help Prints help information
-f, --force Overwrite already existing installation
ARGS:
<VERSION> E.g. \"2.4.0.0\"
DISCUSSION:
Installs the specified cabal-install version (or the default ${KNOWN_GOOD_CABAL})
into the global \"~/.cabal/bin\" directory, so it can be overwritten
by later \"cabal new-install cabal-install\".
")
exit 1
}
###########################
@ -720,6 +753,46 @@ rm_ghc() {
unset myghcver inst_location f
}
############################
#--[ Subcommand install ]--#
############################
# @FUNCTION: install_cabal
# @USAGE: <cabalversion>
# @DESCRIPTION:
# Installs the given cabal version.
install_cabal() {
[ -z "$1" ] && die "Internal error: no argument given to install_cabal"
mycabalver=$1
myarch=$(get_arch)
inst_location=$HOME/.cabal/bin
if [ -e "${inst_location}"/cabal ] && ! ${FORCE} ; then
die "\"${inst_location}/cabal\" already exist, use --force to overwrite"
fi
[ -e "${inst_location}" ] || {
edo mkdir "$HOME"/.cabal
edo mkdir "$HOME"/.cabal/bin
}
(
edo cd "$(mktemp -d)"
edo download "https://www.haskell.org/cabal/release/cabal-install-${mycabalver}/cabal-install-${mycabalver}-${myarch}-unknown-linux.tar.gz"
edo tar -xzf "cabal-install-${mycabalver}-${myarch}-unknown-linux.tar.gz"
edo mv cabal "${inst_location}"/cabal
) || die "Failed to install cabal-install"
status_message "Successfully installed cabal-install, you may want to run the following"
status_message "to get the really latest version:"
status_message " cabal new-install cabal-install"
unset mycabalver myarch inst_location
}
#######################
@ -825,6 +898,23 @@ while [ $# -gt 0 ] ; do
[ "${GHC_VER}" ] || rm_usage
rm_ghc "${GHC_VER}"
break;;
install-cabal)
shift 1
while [ $# -gt 0 ] ; do
case $1 in
-h|--help) install_cabal_usage;;
-f|--force) FORCE=true
shift 1;;
*) CABAL_VER=$1
break;;
esac
done
if [ "${CABAL_VER}" ] ; then
install_cabal "${CABAL_VER}"
else
install_cabal "${KNOWN_GOOD_CABAL}"
fi
break;;
*) usage;;
esac
break;;