deployfile.sh: add option to auto-detect destination path; also optional verbose...
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Tue, 28 May 2013 01:28:28 +0000 (18:28 -0700)
committerJeff Davis <jdavis@sitka.bclibraries.ca>
Tue, 28 May 2013 01:28:28 +0000 (18:28 -0700)
Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
deployment/deployfile.sh

index 0b98e12..d4b674e 100755 (executable)
@@ -7,55 +7,96 @@ usage()
   cat <<EOF
 USAGE:
 ./deployfile.sh -f filename -p /path/to/destination/ [ -u remoteuser ] [ -b ] host1 [ host2 ... ]
+./deployfile.sh -f evergreen.git/Open-ILS/something/something -d [ -u remoteuser ] [ -b ] host1 [ host2 ... ]
 
 OPTIONS:
   -f    Name of file to be deployed
-  -p    Path on remote server where file should be deployed to
+  -p    Path on remote server where file should be deployed to (overrides -d)
+  -d    Determine remote path automatically (experimental; ignored if a path is specified with -p)
   -u    Username to use when logging into remote server; if not provided, defaults to current user
   -b    Backup flag (optional); creates a backup instead of overwriting file on remote server
+  -P    Auto add all production machines to host list
   -h    Print this message and exit
-  -P   auto add all production machines to host list
+  -v    Verbose output - echo parameters to stdout
 EOF
 }
 
-while getopts ":f:p:u:bPh" opt
+while getopts ":f:p:u:bdPvh" opt
 do
   case $opt in
     f ) FILE=$OPTARG;;
     p ) DEST=$OPTARG;;
+    d ) AUTOPATH="d";;
     u ) USER=$OPTARG;;
     b ) BACKUP="-b --suffix=.`date +%Y%m%d%H%M`";;
     P ) PROD="P";;
+    v ) VERBOSE="v";;
     h ) usage && exit 0;;
   esac
 done
 shift $(($OPTIND - 1))
 
-if [[ -z "$FILE" ]] || [[ -z "$DEST" ]] | ([[ $# -lt 1 ]] && [[ -z "$PROD" ]])
+if [[ -z "$FILE" ]] || ([[ -z "$DEST" ]] && [[ -z "$AUTOPATH" ]]) | ([[ $# -lt 1 ]] && [[ -z "$PROD" ]])
 then
   usage
   exit 1
-else
+fi
+
+# attempt to determine the remote destination path automatically
+if [[ -n "$AUTOPATH" ]] && [[ -z "$DEST" ]]
+then
+
+  AUTODEST=$FILE
+
+  # TPAC
+  if [ "$FILE" == "$AUTODEST" ]; then
+    AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/src/templates/\(.*\)$|/srv/openils/var/templates/\1|')
+  fi
+
+  # perl
+  if [ "$FILE" == "$AUTODEST" ]; then
+    AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/src/perlmods/lib/\(.*\)$|/usr/local/share/perl/5.14.2/\1|')
+  fi
 
-  if [[ -z "$BACKUP" ]]
-  then
-    SSH="ssh"
-  else
-    SSH="ssh -l${USER}"
+  # web
+  if [ "$FILE" == "$AUTODEST" ]; then
+    AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/web/\(.*\)$|/srv/openils/var/web/\1|')
   fi
 
-  if [[ -z "$PROD" ]]
-  then
-     _hosts="$@"
-  else
-    echo "adding ${_ProdServers} to hosts"
-    _hosts="$@$_ProdServers"
+  # xul
+  if [ "$FILE" == "$AUTODEST" ]; then
+    AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/xul/staff_client/server/\(.*\)$|/srv/openils/var/web/xul/server/\1|')
   fi
 
-  for HOST in $_hosts
-  do
-    RSYNC_DEST="${HOST}:${DEST}"
-    #echo -e "$HOST:\n\tFILE=$FILE\n\tDEST=$DEST\n\tUSER=$USER\n\tBACKUP=$BACKUP\n\tSSH=$SSH\n\tRSYNC_DEST=$RSYNC_DEST\n"
-    rsync -e"${SSH}" $BACKUP -avz $FILE $RSYNC_DEST
-  done
+  if [ "$FILE" == "$AUTODEST" ]; then
+    echo "Destination path could not be determined.\n"
+    exit 1
+  fi
+
+  DEST=$AUTODEST
+
 fi
+
+if [[ -z "$BACKUP" ]]
+then
+  SSH="ssh"
+else
+  SSH="ssh -l${USER}"
+fi
+
+if [[ -z "$PROD" ]]
+then
+    _hosts="$@"
+else
+  echo "adding ${_ProdServers} to hosts"
+  _hosts="$@$_ProdServers"
+fi
+
+for HOST in $_hosts
+do
+  RSYNC_DEST="${HOST}:${DEST}"
+  if [[ -z "$VERBOSE" ]]; then
+    echo -e "$HOST:\n\tFILE=$FILE\n\tDEST=$DEST\n\tUSER=$USER\n\tBACKUP=$BACKUP\n\tSSH=$SSH\n\tRSYNC_DEST=$RSYNC_DEST\n\tAUTOPATH=$AUTOPATH\n\tAUTODEST=$AUTODEST\n"
+  fi
+  rsync -e"${SSH}" $BACKUP -avz $FILE $RSYNC_DEST
+done