adding new flag for deployfile.sh for easy deploy to all production
authorkreed <kreed@sitka.bclibraries.ca>
Thu, 28 Mar 2013 19:05:34 +0000 (12:05 -0700)
committerkreed <kreed@sitka.bclibraries.ca>
Thu, 28 Mar 2013 19:05:34 +0000 (12:05 -0700)
deployment/deployfile.sh
deployment/deployfile.sh.old [new file with mode: 0755]

index d76778f..0b98e12 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+_ProdServers=" app1-1 app1-2 app2-1 app2-2 app3-1 app3-2 stanns bibc-prod"
+
 usage()
 {
   cat <<EOF
@@ -12,22 +14,24 @@ OPTIONS:
   -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
   -h    Print this message and exit
+  -P   auto add all production machines to host list
 EOF
 }
 
-while getopts ":f:p:u:bh" opt
+while getopts ":f:p:u:bPh" opt
 do
   case $opt in
     f ) FILE=$OPTARG;;
     p ) DEST=$OPTARG;;
     u ) USER=$OPTARG;;
     b ) BACKUP="-b --suffix=.`date +%Y%m%d%H%M`";;
+    P ) PROD="P";;
     h ) usage && exit 0;;
   esac
 done
 shift $(($OPTIND - 1))
 
-if [[ -z "$FILE" ]] || [[ -z "$DEST" ]] | [[ $# -lt 1 ]]
+if [[ -z "$FILE" ]] || [[ -z "$DEST" ]] | ([[ $# -lt 1 ]] && [[ -z "$PROD" ]])
 then
   usage
   exit 1
@@ -40,7 +44,15 @@ else
     SSH="ssh -l${USER}"
   fi
 
-  for HOST in "$@"
+  if [[ -z "$PROD" ]]
+  then
+     _hosts="$@"
+  else
+    echo "adding ${_ProdServers} to hosts"
+    _hosts="$@$_ProdServers"
+  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"
diff --git a/deployment/deployfile.sh.old b/deployment/deployfile.sh.old
new file mode 100755 (executable)
index 0000000..d76778f
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+usage()
+{
+  cat <<EOF
+USAGE:
+./deployfile.sh -f filename -p /path/to/destination/ [ -u remoteuser ] [ -b ] host1 [ host2 ... ]
+
+OPTIONS:
+  -f    Name of file to be deployed
+  -p    Path on remote server where file should be deployed to
+  -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
+  -h    Print this message and exit
+EOF
+}
+
+while getopts ":f:p:u:bh" opt
+do
+  case $opt in
+    f ) FILE=$OPTARG;;
+    p ) DEST=$OPTARG;;
+    u ) USER=$OPTARG;;
+    b ) BACKUP="-b --suffix=.`date +%Y%m%d%H%M`";;
+    h ) usage && exit 0;;
+  esac
+done
+shift $(($OPTIND - 1))
+
+if [[ -z "$FILE" ]] || [[ -z "$DEST" ]] | [[ $# -lt 1 ]]
+then
+  usage
+  exit 1
+else
+
+  if [[ -z "$BACKUP" ]]
+  then
+    SSH="ssh"
+  else
+    SSH="ssh -l${USER}"
+  fi
+
+  for HOST in "$@"
+  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
+fi