github.com/kjdelisle/consul@v1.4.5/build-support/scripts/publish.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 will "publish" a Consul release. It expects a prebuilt release in 
    22     pkg/dist matching the version in the repo and a clean git status. It will 
    23     prompt you to confirm the consul version and git changes you are going to 
    24     publish prior to pushing to git and to releases.hashicorp.com.
    25  
    26  Options:                       
    27     -s | --source     DIR         Path to source to build.
    28                                   Defaults to "${SOURCE_DIR}"
    29                                   
    30     -w | --website                Publish to releases.hashicorp.com
    31     
    32     -g | --git                    Push release commit and tag to Git
    33     
    34     -h | --help                   Print this help text.
    35  EOF
    36  }
    37  
    38  function err_usage {
    39     err "$1"
    40     err ""
    41     err "$(usage)"
    42  }
    43  
    44  function main {
    45     declare    sdir="${SOURCE_DIR}"
    46     declare -i website=0
    47     declare -i git_push=0
    48     
    49     while test $# -gt 0
    50     do
    51        case "$1" in
    52           -h | --help )
    53              usage
    54              return 0
    55              ;;
    56           -s | --source )
    57              if test -z "$2"
    58              then
    59                 err_usage "ERROR: option -s/--source requires an argument"
    60                 return 1
    61              fi
    62              
    63              if ! test -d "$2"
    64              then
    65                 err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source"
    66                 return 1
    67              fi
    68              
    69              sdir="$2"
    70              shift 2
    71              ;;
    72          -w | --website )
    73              website=1
    74              shift
    75              ;;
    76           -g | --git )
    77              git_push=1
    78              shift
    79              ;;
    80           *)
    81              err_usage "ERROR: Unknown argument: '$1'"
    82              return 1
    83              ;;
    84        esac
    85     done
    86     
    87     publish_release "${sdir}" "${git_push}" "${website}" || return 1
    88     
    89     return 0
    90  }
    91  
    92  main "$@"
    93  exit $?
    94