github.com/jojicluka/consul-api@v1.4.5/build-support/scripts/version.sh (about)

     1  #!/bin/bash
     2  SCRIPT_NAME="$(basename ${BASH_SOURCE[0]})"
     3  pushd $(dirname ${BASH_SOURCE[0]}) > /dev/null
     4  SCRIPT_DIR=$(pwd)
     5  pushd ../.. > /dev/null
     6  SOURCE_DIR=$(pwd)
     7  popd > /dev/null
     8  pushd ../functions > /dev/null
     9  FN_DIR=$(pwd)
    10  popd > /dev/null
    11  popd > /dev/null
    12  
    13  source "${SCRIPT_DIR}/functions.sh"
    14  
    15  function usage {
    16  cat <<-EOF
    17  Usage: ${SCRIPT_NAME}  [<options ...>]
    18  
    19  Description:
    20  
    21     This script is just a convenience around discover what the Consul
    22     version would be if you were to build it. 
    23  
    24  Options:                       
    25     -s | --source     DIR         Path to source to build.
    26                                   Defaults to "${SOURCE_DIR}"
    27                                   
    28     -r | --release                Include the release in the version
    29     
    30     -g | --git                    Take git variables into account
    31     
    32     -h | --help                   Print this help text.
    33  EOF
    34  }
    35  
    36  function err_usage {
    37     err "$1"
    38     err ""
    39     err "$(usage)"
    40  }
    41  
    42  function main {
    43     declare    sdir="${SOURCE_DIR}"
    44     declare -i release=0
    45     declare -i git_info=0
    46     
    47     while test $# -gt 0
    48     do
    49        case "$1" in
    50           -h | --help )
    51              usage
    52              return 0
    53              ;;
    54           -s | --source )
    55              if test -z "$2"
    56              then
    57                 err_usage "ERROR: option -s/--source requires an argument"
    58                 return 1
    59              fi
    60              
    61              if ! test -d "$2"
    62              then
    63                 err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source"
    64                 return 1
    65              fi
    66              
    67              sdir="$2"
    68              shift 2
    69              ;;
    70           -r | --release )
    71              release=1
    72              shift
    73              ;;
    74           -g | --git )
    75              git_info=1
    76              shift
    77              ;;
    78           *)
    79              err_usage "ERROR: Unknown argument: '$1'"
    80              return 1
    81              ;;
    82        esac
    83     done
    84     
    85     parse_version "${sdir}" "${release}" "${git_info}" || return 1
    86     
    87     return 0
    88  }
    89  
    90  main "$@"
    91  exit $?
    92