github.com/jojicluka/consul-api@v1.4.5/build-support/scripts/dev.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 put the source back into dev mode after a release.
    22  
    23  Options:
    24                         
    25     -s | --source     DIR         Path to source to build.
    26                                   Defaults to "${SOURCE_DIR}"
    27                                   
    28     --no-git                      Do not commit or attempt to push
    29                                   the changes back to the upstream.
    30                                   
    31     -h | --help                   Print this help text.
    32  EOF
    33  }
    34  
    35  function err_usage {
    36     err "$1"
    37     err ""
    38     err "$(usage)"
    39  }
    40  
    41  function main {
    42     declare    sdir="${SOURCE_DIR}"
    43     declare    build_os=""
    44     declare    build_arch=""
    45     declare -i do_git=1
    46     declare -i do_push=1
    47     
    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           --no-git )
    73              do_git=0
    74              shift
    75              ;;
    76           --no-push )
    77              do_push=0
    78              shift
    79              ;;
    80           * )
    81              err_usage "ERROR: Unknown argument: '$1'"
    82              return 1
    83              ;;
    84        esac
    85     done
    86     
    87     set_dev_mode "${sdir}" || return 1
    88     
    89     if is_set "${do_git}"
    90     then
    91        status_stage "==> Commiting Dev Mode Changes"
    92        commit_dev_mode "${sdir}" || return 1
    93        
    94        if is_set "${do_push}"
    95        then
    96           status_stage "==> Confirming Git Changes"
    97           confirm_git_push_changes "${sdir}" || return 1
    98           
    99           status_stage "==> Pushing to Git"
   100           git_push_ref "${sdir}" || return 1
   101        fi
   102     fi
   103     
   104     return 0
   105  }
   106  
   107  main "$@"
   108  exit $?