circmod renaming: ill-no-renew -> ill-no-renewal.
[sitka/sitka-tools.git] / deployment / deployfile.sh
CommitLineData
0155bbac
JD
1#!/bin/bash
2
1f0c9b83 3_ProdServers=" app1-1 app1-2 app2-1 app2-2 app3-1 app3-2 stanns bibc-prod"
4
0155bbac
JD
5usage()
6{
7 cat <<EOF
8USAGE:
9./deployfile.sh -f filename -p /path/to/destination/ [ -u remoteuser ] [ -b ] host1 [ host2 ... ]
10
11OPTIONS:
12 -f Name of file to be deployed
13 -p Path on remote server where file should be deployed to
14 -u Username to use when logging into remote server; if not provided, defaults to current user
15 -b Backup flag (optional); creates a backup instead of overwriting file on remote server
16 -h Print this message and exit
1f0c9b83 17 -P auto add all production machines to host list
0155bbac
JD
18EOF
19}
20
1f0c9b83 21while getopts ":f:p:u:bPh" opt
0155bbac
JD
22do
23 case $opt in
24 f ) FILE=$OPTARG;;
25 p ) DEST=$OPTARG;;
26 u ) USER=$OPTARG;;
27 b ) BACKUP="-b --suffix=.`date +%Y%m%d%H%M`";;
1f0c9b83 28 P ) PROD="P";;
0155bbac
JD
29 h ) usage && exit 0;;
30 esac
31done
32shift $(($OPTIND - 1))
33
1f0c9b83 34if [[ -z "$FILE" ]] || [[ -z "$DEST" ]] | ([[ $# -lt 1 ]] && [[ -z "$PROD" ]])
0155bbac
JD
35then
36 usage
37 exit 1
38else
39
40 if [[ -z "$BACKUP" ]]
41 then
42 SSH="ssh"
43 else
44 SSH="ssh -l${USER}"
45 fi
46
1f0c9b83 47 if [[ -z "$PROD" ]]
48 then
49 _hosts="$@"
50 else
51 echo "adding ${_ProdServers} to hosts"
52 _hosts="$@$_ProdServers"
53 fi
54
55 for HOST in $_hosts
0155bbac
JD
56 do
57 RSYNC_DEST="${HOST}:${DEST}"
58 #echo -e "$HOST:\n\tFILE=$FILE\n\tDEST=$DEST\n\tUSER=$USER\n\tBACKUP=$BACKUP\n\tSSH=$SSH\n\tRSYNC_DEST=$RSYNC_DEST\n"
59 rsync -e"${SSH}" $BACKUP -avz $FILE $RSYNC_DEST
60 done
61fi