diff options
| author | Wesley Hearn <wesley.s.hearn@gmail.com> | 2015-05-06 10:27:44 -0400 | 
|---|---|---|
| committer | Wesley Hearn <wesley.s.hearn@gmail.com> | 2015-05-06 10:27:44 -0400 | 
| commit | 803b9191f1a3a2bffe94528a8a5cd82adf6f3a42 (patch) | |
| tree | 8f3370fd2d9537a568d97e48ece9e18f3d0032bb /bin/opscp | |
| parent | 519e097df31e2148ac520ab273d0bd2fb2f7bb43 (diff) | |
| parent | e0b2d98a6cac21cfa555afe4d660cb62c1180856 (diff) | |
| download | openshift-803b9191f1a3a2bffe94528a8a5cd82adf6f3a42.tar.gz openshift-803b9191f1a3a2bffe94528a8a5cd82adf6f3a42.tar.bz2 openshift-803b9191f1a3a2bffe94528a8a5cd82adf6f3a42.tar.xz openshift-803b9191f1a3a2bffe94528a8a5cd82adf6f3a42.zip  | |
Merge pull request #209 from openshift/master
Merge Master Into Stage
Diffstat (limited to 'bin/opscp')
| -rwxr-xr-x | bin/opscp | 131 | 
1 files changed, 131 insertions, 0 deletions
diff --git a/bin/opscp b/bin/opscp new file mode 100755 index 000000000..391cb6696 --- /dev/null +++ b/bin/opscp @@ -0,0 +1,131 @@ +#!/bin/bash +# vim: expandtab:tabstop=4:shiftwidth=4 + + +function usage() { +    cat << EOF +Usage: opscp [OPTIONS] local remote + +Options: +  --version             show program's version number and exit +  --help                show this help message and exit +  -l USER, --user=USER  username (OPTIONAL) +  -p PAR, --par=PAR     max number of parallel threads (OPTIONAL) +  --outdir=OUTDIR       output directory for stdout files (OPTIONAL) +  --errdir=ERRDIR       output directory for stderr files (OPTIONAL) +  -e ENV, --env ENV     which environment to use +  -t HOST_TYPE, --host-type HOST_TYPE +                        which host type to use +  --list-host-types     list all of the host types +  --timeout=TIMEOUT     timeout (secs) (0 = no timeout) per host (OPTIONAL) +  -O OPTION, --option=OPTION +                        SSH option (OPTIONAL) +  -v, --verbose         turn on warning and diagnostic messages (OPTIONAL) +  -A, --askpass         Ask for a password (OPTIONAL) +  -x ARGS, --extra-args=ARGS +                        Extra command-line arguments, with processing for +                        spaces, quotes, and backslashes +  -X ARG, --extra-arg=ARG +                        Extra command-line argument +  -r, --recursive       recusively copy directories (OPTIONAL) + +Example: opscp -t ex-srv -e stg -l irb2 foo.txt /home/irb2/foo.txt + +EOF +} + +if [ $# -eq 0 ] || [ "$1" == "--help" ] +then +    usage +    exit 1 +fi + +# See if ohi is installed +if ! which ohi &>/dev/null ; then +    echo "ERROR: can't find ohi (OpenShift Host Inventory) on your system, please either install the openshift-ansible-bin package, or add openshift-ansible/bin to your path." + +    exit 10 +fi + +PAR=200 +USER=root +TIMEOUT=0 +ENV="" +HOST_TYPE="" + +while [ $# -gt 0 ] ; do +    case $1 in +        -t|--host-type) +            shift # get past the option +            HOST_TYPE=$1 +            shift # get past the value of the option +            ;; + +        -e) +            shift # get past the option +            ENV=$1 +            shift # get past the value of the option +            ;; + +        --timeout) +            shift # get past the option +            TIMEOUT=$1 +            shift # get past the value of the option +            ;; + +        -p|--par) +            shift # get past the option +            PAR=$1 +            shift # get past the value of the option +            ;; + +        -l|--user) +            shift # get past the option +            USER=$1 +            shift # get past the value of the option +            ;; + +        --list-host-types) +            ohi --list-host-types +            exit 0 +            ;; + +        -h|--hosts|-H|--host|-o) +            echo "ERROR: unknown option $1" +            exit 20 +            ;; + +        *) +            args+=("$1") +            shift +            ;; +    esac +done + +# Get host list from ohi +if [ -n "$ENV" -a -n "$HOST_TYPE" ] ; then +    HOSTS="$(ohi -t "$HOST_TYPE" -e "$ENV" 2>/dev/null)" +    OHI_ECODE=$? +elif [ -n "$ENV" ] ; then +    HOSTS="$(ohi -e "$ENV" 2>/dev/null)" +    OHI_ECODE=$? +elif [ -n "$HOST_TYPE" ] ; then +    HOSTS="$(ohi -t "$HOST_TYPE" 2>/dev/null)" +    OHI_ECODE=$? +else +    echo +    echo "Error: either -e or -t must be specified" +    echo +    exit 10 +fi + +if [ $OHI_ECODE -ne 0 ] ; then +    echo +    echo "ERROR: ohi failed with exit code $OHI_ECODE" +    echo +    echo "This is usually caused by a bad value passed for host-type or environment." +    echo +    exit 25 +fi + +exec pscp.pssh -t $TIMEOUT -p $PAR -l $USER -h <(echo "$HOSTS") "${args[@]}"  | 
