github.com/jojicluka/consul-api@v1.4.5/build-support/scripts/build-local.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     This script will build the Consul binary on the local system.
    21     All the requisite tooling must be installed for this to be
    22     successful.
    23  
    24  Options:
    25                         
    26     -s | --source     DIR         Path to source to build.
    27                                   Defaults to "${SOURCE_DIR}"
    28                                   
    29     -o | --os         OSES        Space separated string of OS
    30                                   platforms to build.
    31                                   
    32     -a | --arch       ARCH        Space separated string of
    33                                   architectures to build.
    34     
    35     -h | --help                   Print this help text.
    36  EOF
    37  }
    38  
    39  function err_usage {
    40     err "$1"
    41     err ""
    42     err "$(usage)"
    43  }
    44  
    45  function main {
    46     declare sdir="${SOURCE_DIR}"
    47     declare build_os=""
    48     declare build_arch=""
    49     
    50     
    51     while test $# -gt 0
    52     do
    53        case "$1" in
    54           -h | --help )
    55              usage
    56              return 0
    57              ;;
    58           -s | --source )
    59              if test -z "$2"
    60              then
    61                 err_usage "ERROR: option -s/--source requires an argument"
    62                 return 1
    63              fi
    64              
    65              if ! test -d "$2"
    66              then
    67                 err_usage "ERROR: '$2' is not a directory and not suitable for the value of -s/--source"
    68                 return 1
    69              fi
    70              
    71              sdir="$2"
    72              shift 2
    73              ;;
    74           -o | --os )
    75              if test -z "$2"
    76              then
    77                 err_usage "ERROR: option -o/--os requires an argument"
    78                 return 1
    79              fi
    80              
    81              build_os="$2"
    82              shift 2
    83              ;;
    84           -a | --arch )
    85              if test -z "$2"
    86              then
    87                 err_usage "ERROR: option -a/--arch requires an argument"
    88                 return 1
    89              fi
    90              
    91              build_arch="$2"
    92              shift 2
    93              ;;
    94           * )
    95              err_usage "ERROR: Unknown argument: '$1'"
    96              return 1
    97              ;;
    98        esac
    99     done
   100     
   101     build_consul_local "${sdir}" "${build_os}" "${build_arch}" || return 1
   102     
   103     return 0
   104  }
   105  
   106  main "$@"
   107  exit $?