From a9abcc3646053ca8f2bf2dd3ee39b06ac12d35c6 Mon Sep 17 00:00:00 2001
From: Thomas Wiest <twiest@redhat.com>
Date: Thu, 30 Apr 2015 12:07:03 -0400
Subject: added opscp

---
 bin/opscp | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
 create mode 100755 bin/opscp

(limited to 'bin/opscp')

diff --git a/bin/opscp b/bin/opscp
new file mode 100755
index 000000000..445c838f5
--- /dev/null
+++ b/bin/opscp
@@ -0,0 +1,117 @@
+#!/bin/bash
+
+
+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)
+  --errdir=ERRDIR       output directory for stderr files (OPTIONAL)
+  --outdir=OUTDIR       output directory for stdout files (OPTIONAL)
+  -e ENV, --env ENV     Which environment to use
+  -t HOST_TYPE, --host-type HOST_TYPE
+                        Which host type to use
+  -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
+
+PSCP_PAR=200
+USER=root
+PSCP_OPTIONS=""
+ENV=""
+HOST_TYPE=""
+while [ $# -gt 0 ] ; do
+  if [ "$1" == "-t" -o "$1" == "--host-type" ] ; then
+    shift # get past the option
+    HOST_TYPE=$1
+    shift # get past the value of the option
+
+  elif [ "$1" == "-e" ] ; then
+    shift # get past the option
+    ENV=$1
+    shift # get past the value of the option
+
+  elif [ "$1" == "-p" -o "$1" == "--par" ] ; then
+    shift # get past the option
+    PSCP_PAR=$1
+    shift # get past the value of the option
+
+  elif [ "$1" == "-l" -o "$1" == "--user" ] ; then
+    shift # get past the option
+    USER=$1
+    shift # get past the value of the option
+
+  elif [ "$1" == "-h" -o "$1" == "--hosts" -o "$1" == "-H" -o "$1" == "--host" ] ||
+       [ "$1" == "-o" ] ; then
+    echo "ERROR: unknown option $1"
+    exit 20
+
+  else
+    if [ "${1:0:1}" == "-" ] ; then
+      # It's an option, don't quote
+      PSCP_OPTIONS="$PSCP_OPTIONS $1"
+    else
+      PSCP_OPTIONS="$PSCP_OPTIONS '$1'"
+    fi
+    shift # Get past this option
+  fi
+done
+
+if [ -z "$ENV" ]
+then
+  echo
+  echo "-e is a required paramemeter"
+  echo
+  exit 10
+fi
+
+if [ -z "$HOST_TYPE" ]
+then
+  echo
+  echo "-t is a required paramemeter"
+  echo
+  exit 15
+fi
+
+PSCP_OPTIONS="-t 0 -p $PSCP_PAR -l $USER -h <(ohi -t $HOST_TYPE -e $ENV 2>/dev/null) $PSCP_OPTIONS"
+
+
+# See if the ohi options are valid
+ohi -t $HOST_TYPE -e $ENV &> /dev/null
+ECODE=$?
+if [ $ECODE -ne 0 ] ; then
+  echo
+  echo "ERROR: ohi failed with exit code $ECODE"
+  echo
+  echo "This is usually caused by a bad value passed for host-type or environment."
+  echo
+  exit 25
+fi
+
+echo
+echo "Running: pscp.pssh $PSCP_OPTIONS"
+echo
+
+eval pscp.pssh $PSCP_OPTIONS
-- 
cgit v1.2.3


From 4573aee333eb0a4d2017993a530d19e7e5d7f493 Mon Sep 17 00:00:00 2001
From: Thomas Wiest <twiest@redhat.com>
Date: Thu, 30 Apr 2015 16:18:39 -0400
Subject: added --list-host-types option to opscp

---
 bin/opscp | 5 +++++
 1 file changed, 5 insertions(+)

(limited to 'bin/opscp')

diff --git a/bin/opscp b/bin/opscp
index 445c838f5..d76480253 100755
--- a/bin/opscp
+++ b/bin/opscp
@@ -15,6 +15,7 @@ Options:
   -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
   -O OPTION, --option=OPTION
                         SSH option (OPTIONAL)
   -v, --verbose         turn on warning and diagnostic messages (OPTIONAL)
@@ -63,6 +64,10 @@ while [ $# -gt 0 ] ; do
     USER=$1
     shift # get past the value of the option
 
+  elif [ "$1" == "--list-host-types" ] ; then
+    ohi --list-host-types
+    exit 0
+
   elif [ "$1" == "-h" -o "$1" == "--hosts" -o "$1" == "-H" -o "$1" == "--host" ] ||
        [ "$1" == "-o" ] ; then
     echo "ERROR: unknown option $1"
-- 
cgit v1.2.3


From 734c853474b18564c7252d22314fc729db6207bb Mon Sep 17 00:00:00 2001
From: Thomas Wiest <twiest@redhat.com>
Date: Sat, 2 May 2015 01:24:36 -0400
Subject: changed opssh to a bash script using ohi to make it easier to
 maintain, and to expose all of the pssh features directly.

---
 bin/opscp | 151 +++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 81 insertions(+), 70 deletions(-)

(limited to 'bin/opscp')

diff --git a/bin/opscp b/bin/opscp
index d76480253..32fd341b9 100755
--- a/bin/opscp
+++ b/bin/opscp
@@ -1,8 +1,9 @@
 #!/bin/bash
+# vim: expandtab:tabstop=4:shiftwidth=4
 
 
 function usage() {
-  cat << EOF
+    cat << EOF
 Usage: opscp [OPTIONS] local remote
 
 Options:
@@ -10,12 +11,13 @@ Options:
   --help                show this help message and exit
   -l USER, --user=USER  username (OPTIONAL)
   -p PAR, --par=PAR     max number of parallel threads (OPTIONAL)
-  --errdir=ERRDIR       output directory for stderr files (OPTIONAL)
   --outdir=OUTDIR       output directory for stdout files (OPTIONAL)
-  -e ENV, --env ENV     Which environment to use
+  --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
+                        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)
@@ -34,89 +36,98 @@ EOF
 
 if [ $# -eq 0 ] || [ "$1" == "--help" ]
 then
-  usage
-  exit 1
+    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
 
-PSCP_PAR=200
+PAR=200
 USER=root
-PSCP_OPTIONS=""
+TIMEOUT=0
 ENV=""
 HOST_TYPE=""
+
 while [ $# -gt 0 ] ; do
-  if [ "$1" == "-t" -o "$1" == "--host-type" ] ; then
-    shift # get past the option
-    HOST_TYPE=$1
-    shift # get past the value of the option
-
-  elif [ "$1" == "-e" ] ; then
-    shift # get past the option
-    ENV=$1
-    shift # get past the value of the option
-
-  elif [ "$1" == "-p" -o "$1" == "--par" ] ; then
-    shift # get past the option
-    PSCP_PAR=$1
-    shift # get past the value of the option
-
-  elif [ "$1" == "-l" -o "$1" == "--user" ] ; then
-    shift # get past the option
-    USER=$1
-    shift # get past the value of the option
-
-  elif [ "$1" == "--list-host-types" ] ; then
-    ohi --list-host-types
-    exit 0
-
-  elif [ "$1" == "-h" -o "$1" == "--hosts" -o "$1" == "-H" -o "$1" == "--host" ] ||
-       [ "$1" == "-o" ] ; then
-    echo "ERROR: unknown option $1"
-    exit 20
-
-  else
-    if [ "${1:0:1}" == "-" ] ; then
-      # It's an option, don't quote
-      PSCP_OPTIONS="$PSCP_OPTIONS $1"
-    else
-      PSCP_OPTIONS="$PSCP_OPTIONS '$1'"
-    fi
-    shift # Get past this option
-  fi
+    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
 
 if [ -z "$ENV" ]
 then
-  echo
-  echo "-e is a required paramemeter"
-  echo
-  exit 10
+    echo
+    echo "-e is a required paramemeter"
+    echo
+    exit 10
 fi
 
 if [ -z "$HOST_TYPE" ]
 then
-  echo
-  echo "-t is a required paramemeter"
-  echo
-  exit 15
+    echo
+    echo "-t is a required paramemeter"
+    echo
+    exit 15
 fi
 
-PSCP_OPTIONS="-t 0 -p $PSCP_PAR -l $USER -h <(ohi -t $HOST_TYPE -e $ENV 2>/dev/null) $PSCP_OPTIONS"
-
-
 # See if the ohi options are valid
-ohi -t $HOST_TYPE -e $ENV &> /dev/null
+HOSTS="$(ohi -t "$HOST_TYPE" -e "$ENV" 2>/dev/null)"
 ECODE=$?
 if [ $ECODE -ne 0 ] ; then
-  echo
-  echo "ERROR: ohi failed with exit code $ECODE"
-  echo
-  echo "This is usually caused by a bad value passed for host-type or environment."
-  echo
-  exit 25
+    echo
+    echo "ERROR: ohi failed with exit code $ECODE"
+    echo
+    echo "This is usually caused by a bad value passed for host-type or environment."
+    echo
+    exit 25
 fi
 
-echo
-echo "Running: pscp.pssh $PSCP_OPTIONS"
-echo
-
-eval pscp.pssh $PSCP_OPTIONS
+exec pscp.pssh -t $TIMEOUT -p $PAR -l $USER -h <(echo "$HOSTS") "${args[@]}"
-- 
cgit v1.2.3


From a61078e1411dd5b877b062a632a48d67921a5ada Mon Sep 17 00:00:00 2001
From: Thomas Wiest <twiest@redhat.com>
Date: Tue, 5 May 2015 16:29:56 -0400
Subject: fixed opssh and opscp to allow just environment or just host-type.

---
 bin/opscp | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

(limited to 'bin/opscp')

diff --git a/bin/opscp b/bin/opscp
index 32fd341b9..391cb6696 100755
--- a/bin/opscp
+++ b/bin/opscp
@@ -102,28 +102,26 @@ while [ $# -gt 0 ] ; do
     esac
 done
 
-if [ -z "$ENV" ]
-then
+# 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 "-e is a required paramemeter"
+    echo "Error: either -e or -t must be specified"
     echo
     exit 10
 fi
 
-if [ -z "$HOST_TYPE" ]
-then
-    echo
-    echo "-t is a required paramemeter"
-    echo
-    exit 15
-fi
-
-# See if the ohi options are valid
-HOSTS="$(ohi -t "$HOST_TYPE" -e "$ENV" 2>/dev/null)"
-ECODE=$?
-if [ $ECODE -ne 0 ] ; then
+if [ $OHI_ECODE -ne 0 ] ; then
     echo
-    echo "ERROR: ohi failed with exit code $ECODE"
+    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
-- 
cgit v1.2.3