install: warn and stop if old stack shadows installed one; clearer output
[ci skip]
This commit is contained in:
		
							parent
							
								
									273f744718
								
							
						
					
					
						commit
						08e02024b2
					
				| @ -50,7 +50,7 @@ HERE | |||||||
| HLEDGER_INSTALL_TOOL=hledger-install.sh | HLEDGER_INSTALL_TOOL=hledger-install.sh | ||||||
| 
 | 
 | ||||||
| # this script's version | # this script's version | ||||||
| HLEDGER_INSTALL_VERSION=20181001 | HLEDGER_INSTALL_VERSION=20181005 | ||||||
| 
 | 
 | ||||||
| # stackage version to install from when using stack | # stackage version to install from when using stack | ||||||
| # You can specify a different stackage version here, or comment out | # You can specify a different stackage version here, or comment out | ||||||
| @ -806,13 +806,20 @@ cmpver () { | |||||||
| 
 | 
 | ||||||
| # install stack or a newer version of stack if needed,  | # install stack or a newer version of stack if needed,  | ||||||
| # or always with --force-install-stack,  | # or always with --force-install-stack,  | ||||||
| # in $HOME/.local/bin | # in $HOME/.local/bin. | ||||||
|  | # After installing, check that a new-enough stack is now the first in $PATH, | ||||||
|  | # and if it's not, exit with a warning advising the user to remove the old one.  | ||||||
| ensure_stack() { | ensure_stack() { | ||||||
|   if ! has_good_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 | ||||||
|  |     if ! has_good_stack ; then | ||||||
|  |       echo "Error: an older stack ($(cmd_version stack)) is first in \$PATH, shadowing the new version." | ||||||
|  |       echo "Please delete or rename $(which stack) and run hledger-install again." | ||||||
|  |       exit 1 | ||||||
|  |     fi | ||||||
|   fi |   fi | ||||||
|   echo "using stack $(stack --version)" |   echo "Using stack $(stack --version)" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| # get a sed command that supports EREs | # get a sed command that supports EREs | ||||||
| @ -827,10 +834,10 @@ cmd_location() { | |||||||
|   command -v "$1" |   command -v "$1" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| # Get the given command's version, ie the first number in its --version output, | # Get the given command's version, ie the first number in the first line of its --version output, | ||||||
| # or empty string if there's a problem. | # or empty string if there's a problem. | ||||||
| cmd_version() { | cmd_version() { | ||||||
|   (command "$1" --version 2>/dev/null | grep -E '[0-9]' | $SED -e 's/[^0-9]*([0-9][0-9.]*).*/\1/') || "" |   (command "$1" --version 2>/dev/null | head -n1 | grep -E '[0-9]' | $SED -e 's/[^0-9]*([0-9][0-9.]*).*/\1/') || "" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| # Check whether the given command exists with given version | # Check whether the given command exists with given version | ||||||
| @ -863,29 +870,21 @@ quietly_run() { | |||||||
|   "$@" 2>/dev/null || true |   "$@" 2>/dev/null || true | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| # Try to install the executables of the given package(s) to $HOME/.local/bin, | # Try to install the executables of the given haskell package(s) and versions,  | ||||||
| # trying several methods, generally from quickest to most reliable, continuing on failure. | # using stack or cabal, logging the commands, continuing on failure. | ||||||
| # Current the installation methods are: | # It's assumed that either a new-enough stack or cabal-install is already installed. | ||||||
| # - if stack is not installed and cabal is, try cabal install | # stack is preferred. | ||||||
| # - otherwise install stack if needed and try stack install with specific resolver and ghc | # For stack, you must specify the package(s) you want to install, plus any additional | ||||||
| # For the stack method, it's necessary to provide not only the package(s) you want to | # dependency packages which are not in the stackage $RESOLVER configured above. | ||||||
| # install but also all dependencies which are not in the specified stackage $RESOLVER. |  | ||||||
| try_install() { | 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 |   if has_cmd stack ; then | ||||||
|    (! has_cmd stack && has_cmd cabal && ( |     try_info stack install --install-ghc $RESOLVER "$@" --verbosity="$STACK_VERBOSITY" | ||||||
|     echo "no stack installed, cabal $(cabal --numeric-version) installed; trying cabal install" &&  # cf cabal update step |   elif has_cmd cabal ; then | ||||||
|     try_info cabal install "$@" --verbose="$CABAL_VERBOSITY" ) |     try_info cabal install "$@" --verbose="$CABAL_VERBOSITY" | ||||||
|     ) || |   else | ||||||
|    # use stack, installing it if missing or too old |     echo "Failed to install $@" | ||||||
|    (ensure_stack && ( |   fi | ||||||
|     #(try_info stack install --install-ghc "$@" --verbosity=$STACK_VERBOSITY ) ||        # existing resolver |  | ||||||
|     (try_info stack install --install-ghc $RESOLVER "$@" --verbosity="$STACK_VERBOSITY" )  # specific resolver |  | ||||||
|     ) |  | ||||||
|    ) || |  | ||||||
|    # or give up |  | ||||||
|    echo "Failed to install $@" |  | ||||||
|   ) |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| # start | # start | ||||||
| @ -948,11 +947,13 @@ fi | |||||||
| echo "hledger-install.sh $HLEDGER_INSTALL_VERSION $(date)" | echo "hledger-install.sh $HLEDGER_INSTALL_VERSION $(date)" | ||||||
| 
 | 
 | ||||||
| # show system info | # show system info | ||||||
|  | echo | ||||||
| echo "System info:" | echo "System info:" | ||||||
| quietly_run uname -rsv | quietly_run uname -rsv | ||||||
| quietly_run lsb_release -a | quietly_run lsb_release -a | ||||||
| 
 | 
 | ||||||
| # show current installed hledger packages | # show current installed hledger packages | ||||||
|  | echo | ||||||
| echo "Install status before:" | echo "Install status before:" | ||||||
| print_installed_versions | print_installed_versions | ||||||
| 
 | 
 | ||||||
| @ -961,22 +962,29 @@ if [[ $STATUSFLAG ]] ; then | |||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # explain the planned install method | # explain the planned install method | ||||||
|  | echo | ||||||
| echo "Install method:" | echo "Install method:" | ||||||
| # if stack is installed, use stack | # if stack is installed, use stack | ||||||
|  | # || [[ "$FORCE_INSTALL_STACK" == "true" ]]  #--force-install-stack | ||||||
| if has_stack ; then | if has_stack ; then | ||||||
|   echo "stack is installed, using stack to install hledger" |   echo "stack $(cmd_version stack) is installed, using stack to install hledger in $HOME/.local/bin" | ||||||
|   # if it's too old, explain that we'll be installing the latest |   # if it's too old, explain that we'll be installing the latest | ||||||
|   if ! has_good_stack ; then |   if ! has_good_stack ; then | ||||||
|     echo "Note: installed stack $(cmd_version stack) is too old, the latest version will be installed" |     echo "Note: stack $(cmd_version stack) is too old, a newer version will be installed" | ||||||
|   fi |   fi | ||||||
|  |   # install stack now (or if new enough, just print its precise version) | ||||||
|  |   ensure_stack | ||||||
| # else if cabal is installed, use cabal | # else if cabal is installed, use cabal | ||||||
| elif has_cmd cabal ; then | elif has_cmd cabal ; then | ||||||
|   echo "no stack installed, cabal $(cabal --numeric-version) installed; using cabal to install hledger" |   echo "no stack installed, cabal $(cabal --numeric-version) installed; using cabal to install hledger in $HOME/.cabal/bin" | ||||||
|  |   echo Using $(cabal --version)  # unquoted to squash cabal version to one line | ||||||
|   # run cabal update to make sure it knows about latest packages |   # run cabal update to make sure it knows about latest packages | ||||||
|   try_info cabal update |   try_info cabal update | ||||||
| # else use stack | # else use stack | ||||||
| else | else | ||||||
|   echo "no stack or cabal installed; stack will be installed and used to install hledger" |   echo "no stack or cabal installed; stack will be installed and used to install hledger in $HOME/.local/bin" | ||||||
|  |     # install stack now | ||||||
|  |   ensure_stack | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # ensure ~/.local/bin/ in PATH | # ensure ~/.local/bin/ in PATH | ||||||
| @ -991,7 +999,8 @@ if ! on_path "$HOME_LOCAL_BIN" ; then | |||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # try installing each package that needs installing, in turn | # try installing each package that needs installing, in turn | ||||||
| echo ---------- | echo | ||||||
|  | echo Installing hledger packages: | ||||||
| 
 | 
 | ||||||
| if [[ $(cmpver "$(cmd_version hledger 2>/dev/null)" $HLEDGER_VERSION) = 2 ]]; then | if [[ $(cmpver "$(cmd_version hledger 2>/dev/null)" $HLEDGER_VERSION) = 2 ]]; then | ||||||
|   echo Installing hledger |   echo Installing hledger | ||||||
| @ -1038,9 +1047,8 @@ if [[ $(cmpver "$(cmd_version hledger-interest 2>/dev/null)" $HLEDGER_INTEREST_V | |||||||
|   echo |   echo | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| echo ---------- |  | ||||||
| 
 |  | ||||||
| # show new installation status | # show new installation status | ||||||
|  | echo | ||||||
| echo "Install status after:" | echo "Install status after:" | ||||||
| print_installed_versions | print_installed_versions | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user