From aba0db8490899c5ed0b1ac5ef7afc4aa8c31827c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 1 Oct 2018 10:00:46 -1000 Subject: [PATCH] install: ensure a new-enough version of stack; output improvements --- hledger-install/hledger-install.sh | 48 ++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/hledger-install/hledger-install.sh b/hledger-install/hledger-install.sh index 2716e32b2..d3fc2481f 100755 --- a/hledger-install/hledger-install.sh +++ b/hledger-install/hledger-install.sh @@ -61,7 +61,7 @@ HLEDGER_INSTALL_VERSION=20180824 RESOLVER="--resolver=lts-12" #RESOLVER="--resolver=nightly-2018-07-09" -# things to be installed: +# things to be installed HLEDGER_MAIN_TOOLS="\ hledger \ @@ -76,23 +76,28 @@ hledger-iadd \ hledger-interest \ " +# latest hledger package versions, update often: HLEDGER_VERSION=1.11 HLEDGER_LIB_VERSION=$HLEDGER_VERSION HLEDGER_UI_VERSION=$HLEDGER_VERSION HLEDGER_WEB_VERSION=$HLEDGER_VERSION HLEDGER_API_VERSION=$HLEDGER_VERSION - HLEDGER_DIFF_VERSION=0.2.0.14 HLEDGER_IADD_VERSION=1.3.6 HLEDGER_INTEREST_VERSION=1.5.2 -# extra dependencies that aren't in stackage +# extra dependencies that aren't in stackage: EXTRA_DEPS="\ 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 -# CHANGED marks (some of) our customisations +# CHANGED marks a few of our customisations, but not all. HOME_LOCAL_BIN="$HOME/.local/bin" USR_LOCAL_BIN="/usr/local/bin" @@ -653,6 +658,12 @@ has_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 has_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_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: $(stack_location) Use 'stack upgrade' or your OS's package manager to upgrade, @@ -757,9 +768,11 @@ trap cleanup_temp_dir EXIT # 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() { - if ! has_stack || [[ "$FORCE_INSTALL_STACK" == "true" ]] ; then + if ! has_good_stack || [[ "$FORCE_INSTALL_STACK" == "true" ]] ; then echo "Installing stack" do_os fi @@ -794,13 +807,13 @@ print_cmd_version() { if [[ $(cmd_location "$1") ]]; then echo "$1" $(cmd_version "$1") is installed at $(cmd_location "$1") else - echo "$1 not found" + echo "$1 is not found" fi } -# Show the installation status of the $HLEDGER_MAIN_TOOLS and $HLEDGER_OTHER_TOOLS. -print_hledger_versions() { - for cmd in $HLEDGER_MAIN_TOOLS $HLEDGER_OTHER_TOOLS $HLEDGER_INSTALL_TOOL ; do print_cmd_version "$cmd"; done +# Show the current installation status of the hledger packages and install tools. +print_installed_versions() { + 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. @@ -825,7 +838,7 @@ try_install() { (cd # ensure we install at user level, not in some project's stack/cabal setup # cabal and not stack installed ? use 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" ) ) || # use stack, installing it if missing or too old @@ -915,14 +928,17 @@ quietly_run lsb_release -a # show current installed hledger packages echo "Install status before:" -print_hledger_versions +print_installed_versions if [[ $STATUSFLAG ]] ; then exit 0 fi # 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. # 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 echo fi - +exit # Third-party addons. We sometimes build these with an older version # 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 @@ -1012,7 +1028,7 @@ echo ---------- # show new installation status echo "Install status after:" -print_hledger_versions +print_installed_versions # warn if $HOME/.local/bin isn't in $PATH check_home_local_bin_on_path