install: ensure a new-enough version of stack; output improvements

This commit is contained in:
Simon Michael 2018-10-01 10:00:46 -10:00
parent 87e54507e0
commit aba0db8490

View File

@ -61,7 +61,7 @@ HLEDGER_INSTALL_VERSION=20180824
RESOLVER="--resolver=lts-12" RESOLVER="--resolver=lts-12"
#RESOLVER="--resolver=nightly-2018-07-09" #RESOLVER="--resolver=nightly-2018-07-09"
# things to be installed: # things to be installed
HLEDGER_MAIN_TOOLS="\ HLEDGER_MAIN_TOOLS="\
hledger \ hledger \
@ -76,23 +76,28 @@ hledger-iadd \
hledger-interest \ hledger-interest \
" "
# latest hledger package versions, update often:
HLEDGER_VERSION=1.11 HLEDGER_VERSION=1.11
HLEDGER_LIB_VERSION=$HLEDGER_VERSION HLEDGER_LIB_VERSION=$HLEDGER_VERSION
HLEDGER_UI_VERSION=$HLEDGER_VERSION HLEDGER_UI_VERSION=$HLEDGER_VERSION
HLEDGER_WEB_VERSION=$HLEDGER_VERSION HLEDGER_WEB_VERSION=$HLEDGER_VERSION
HLEDGER_API_VERSION=$HLEDGER_VERSION HLEDGER_API_VERSION=$HLEDGER_VERSION
HLEDGER_DIFF_VERSION=0.2.0.14 HLEDGER_DIFF_VERSION=0.2.0.14
HLEDGER_IADD_VERSION=1.3.6 HLEDGER_IADD_VERSION=1.3.6
HLEDGER_INTEREST_VERSION=1.5.2 HLEDGER_INTEREST_VERSION=1.5.2
# extra dependencies that aren't in stackage # extra dependencies that aren't in stackage:
EXTRA_DEPS="\ EXTRA_DEPS="\
cassava-megaparsec-1.0.0 \ cassava-megaparsec-1.0.0 \
" "
# the oldest version of stack that will work:
STACK_VERSION=1.7.1
# start of (most of) get-stack.sh, https://github.com/commercialhaskell/stack/blob/master/etc/scripts/get-stack.sh # start of (most of) get-stack.sh, https://github.com/commercialhaskell/stack/blob/master/etc/scripts/get-stack.sh
# CHANGED marks (some of) our customisations # CHANGED marks a few of our customisations, but not all.
HOME_LOCAL_BIN="$HOME/.local/bin" HOME_LOCAL_BIN="$HOME/.local/bin"
USR_LOCAL_BIN="/usr/local/bin" USR_LOCAL_BIN="/usr/local/bin"
@ -653,6 +658,12 @@ has_stack() {
has_cmd stack has_cmd stack
} }
# Check whether a new enough version of the 'stack' command exists
has_good_stack() {
has_cmd stack &&
[[ ! $(cmpver "$(cmd_version stack 2>/dev/null)" $STACK_VERSION) = 2 ]]
}
# Check whether 'wget' command exists # Check whether 'wget' command exists
has_wget() { has_wget() {
has_cmd wget has_cmd wget
@ -743,7 +754,7 @@ check_usr_local_bin_on_path() {
# Check whether Stack is already installed, and print an error if it is. # Check whether Stack is already installed, and print an error if it is.
check_stack_installed() { check_stack_installed() {
if [ "$FORCE_INSTALL_STACK" != "true" ] && has_stack ; then if [ "$FORCE_INSTALL_STACK" != "true" ] && has_good_stack ; then
die "Stack $(stack_version) already appears to be installed at: die "Stack $(stack_version) already appears to be installed at:
$(stack_location) $(stack_location)
Use 'stack upgrade' or your OS's package manager to upgrade, Use 'stack upgrade' or your OS's package manager to upgrade,
@ -757,9 +768,11 @@ trap cleanup_temp_dir EXIT
# hledger routines # hledger routines
# install stack if needed, or always with --force-install-stack, in $HOME/.local/bin # install stack or a newer version of stack if needed,
# or always with --force-install-stack,
# in $HOME/.local/bin
ensure_stack() { ensure_stack() {
if ! has_stack || [[ "$FORCE_INSTALL_STACK" == "true" ]] ; then if ! has_good_stack || [[ "$FORCE_INSTALL_STACK" == "true" ]] ; then
echo "Installing stack" echo "Installing stack"
do_os do_os
fi fi
@ -794,13 +807,13 @@ print_cmd_version() {
if [[ $(cmd_location "$1") ]]; then if [[ $(cmd_location "$1") ]]; then
echo "$1" $(cmd_version "$1") is installed at $(cmd_location "$1") echo "$1" $(cmd_version "$1") is installed at $(cmd_location "$1")
else else
echo "$1 not found" echo "$1 is not found"
fi fi
} }
# Show the installation status of the $HLEDGER_MAIN_TOOLS and $HLEDGER_OTHER_TOOLS. # Show the current installation status of the hledger packages and install tools.
print_hledger_versions() { print_installed_versions() {
for cmd in $HLEDGER_MAIN_TOOLS $HLEDGER_OTHER_TOOLS $HLEDGER_INSTALL_TOOL ; do print_cmd_version "$cmd"; done for cmd in $HLEDGER_MAIN_TOOLS $HLEDGER_OTHER_TOOLS $HLEDGER_INSTALL_TOOL stack cabal ; do print_cmd_version "$cmd"; done
} }
# Run a command, but first log it with "Trying" prepended. # Run a command, but first log it with "Trying" prepended.
@ -825,7 +838,7 @@ try_install() {
(cd # ensure we install at user level, not in some project's stack/cabal setup (cd # ensure we install at user level, not in some project's stack/cabal setup
# cabal and not stack installed ? use cabal # cabal and not stack installed ? use cabal
(! has_cmd stack && has_cmd cabal && ( (! has_cmd stack && has_cmd cabal && (
echo "no stack installed, $(cabal --version) installed; trying cabal install" && echo "no stack installed, cabal $(cabal --numeric-version) installed; trying cabal install" && # cf cabal update step
try_info cabal install "$@" --verbose="$CABAL_VERBOSITY" ) try_info cabal install "$@" --verbose="$CABAL_VERBOSITY" )
) || ) ||
# use stack, installing it if missing or too old # use stack, installing it if missing or too old
@ -915,14 +928,17 @@ quietly_run lsb_release -a
# show current installed hledger packages # show current installed hledger packages
echo "Install status before:" echo "Install status before:"
print_hledger_versions print_installed_versions
if [[ $STATUSFLAG ]] ; then if [[ $STATUSFLAG ]] ; then
exit 0 exit 0
fi fi
# if we'll be using cabal, run cabal update once at the start # if we'll be using cabal, run cabal update once at the start
(! has_cmd stack && has_cmd cabal && try_info cabal update ) (! has_cmd stack && has_cmd cabal &&
echo "no stack installed, cabal $(cabal --numeric-version) installed; trying cabal update" && # cf try-install()
try_info cabal update
)
# Compare dotted number version strings, based on https://stackoverflow.com/a/4025065/84401. # Compare dotted number version strings, based on https://stackoverflow.com/a/4025065/84401.
# cmpver A B's exit status *and* output is # cmpver A B's exit status *and* output is
@ -987,7 +1003,7 @@ if [[ $(cmpver "$(cmd_version hledger-api 2>/dev/null)" $HLEDGER_API_VERSION) =
try_install hledger-api-$HLEDGER_API_VERSION hledger-$HLEDGER_VERSION hledger-lib-$HLEDGER_LIB_VERSION $EXTRA_DEPS try_install hledger-api-$HLEDGER_API_VERSION hledger-$HLEDGER_VERSION hledger-lib-$HLEDGER_LIB_VERSION $EXTRA_DEPS
echo echo
fi fi
exit
# Third-party addons. We sometimes build these with an older version # Third-party addons. We sometimes build these with an older version
# of hledger[-lib], if their bounds have not been updated yet. # of hledger[-lib], if their bounds have not been updated yet.
if [[ $(cmpver "$(cmd_version hledger-diff 2>/dev/null)" $HLEDGER_DIFF_VERSION) = 2 ]]; then if [[ $(cmpver "$(cmd_version hledger-diff 2>/dev/null)" $HLEDGER_DIFF_VERSION) = 2 ]]; then
@ -1012,7 +1028,7 @@ echo ----------
# show new installation status # show new installation status
echo "Install status after:" echo "Install status after:"
print_hledger_versions print_installed_versions
# warn if $HOME/.local/bin isn't in $PATH # warn if $HOME/.local/bin isn't in $PATH
check_home_local_bin_on_path check_home_local_bin_on_path