use master branch again for osrf/eg install
[sitka/sitka-tools.git] / deployment / deployfile.sh
CommitLineData
0155bbac
JD
1#!/bin/bash
2
26cd9883 3_ProdServers=" app1 app2 app3 utility1 sip2 bibc-prod28-1"
1f0c9b83 4
0155bbac
JD
5usage()
6{
7 cat <<EOF
8USAGE:
9./deployfile.sh -f filename -p /path/to/destination/ [ -u remoteuser ] [ -b ] host1 [ host2 ... ]
c41c58e7 10./deployfile.sh -f evergreen.git/Open-ILS/something/something -d [ -u remoteuser ] [ -b ] host1 [ host2 ... ]
0155bbac
JD
11
12OPTIONS:
13 -f Name of file to be deployed
c41c58e7
JD
14 -p Path on remote server where file should be deployed to (overrides -d)
15 -d Determine remote path automatically (experimental; ignored if a path is specified with -p)
0155bbac
JD
16 -u Username to use when logging into remote server; if not provided, defaults to current user
17 -b Backup flag (optional); creates a backup instead of overwriting file on remote server
c41c58e7 18 -P Auto add all production machines to host list
0155bbac 19 -h Print this message and exit
c41c58e7 20 -v Verbose output - echo parameters to stdout
0155bbac
JD
21EOF
22}
23
c41c58e7 24while getopts ":f:p:u:bdPvh" opt
0155bbac
JD
25do
26 case $opt in
27 f ) FILE=$OPTARG;;
28 p ) DEST=$OPTARG;;
c41c58e7 29 d ) AUTOPATH="d";;
0155bbac
JD
30 u ) USER=$OPTARG;;
31 b ) BACKUP="-b --suffix=.`date +%Y%m%d%H%M`";;
1f0c9b83 32 P ) PROD="P";;
c41c58e7 33 v ) VERBOSE="v";;
0155bbac
JD
34 h ) usage && exit 0;;
35 esac
36done
37shift $(($OPTIND - 1))
38
c41c58e7 39if [[ -z "$FILE" ]] || ([[ -z "$DEST" ]] && [[ -z "$AUTOPATH" ]]) | ([[ $# -lt 1 ]] && [[ -z "$PROD" ]])
0155bbac
JD
40then
41 usage
42 exit 1
c41c58e7
JD
43fi
44
45# attempt to determine the remote destination path automatically
46if [[ -n "$AUTOPATH" ]] && [[ -z "$DEST" ]]
47then
48
49 AUTODEST=$FILE
50
51 # TPAC
52 if [ "$FILE" == "$AUTODEST" ]; then
53 AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/src/templates/\(.*\)$|/srv/openils/var/templates/\1|')
54 fi
55
56 # perl
57 if [ "$FILE" == "$AUTODEST" ]; then
f404334e 58 AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/src/perlmods/lib/\(.*\)$|/usr/local/share/perl/5.18.2/\1|')
c41c58e7 59 fi
0155bbac 60
c41c58e7
JD
61 # web
62 if [ "$FILE" == "$AUTODEST" ]; then
63 AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/web/\(.*\)$|/srv/openils/var/web/\1|')
0155bbac
JD
64 fi
65
c41c58e7
JD
66 # xul
67 if [ "$FILE" == "$AUTODEST" ]; then
68 AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/xul/staff_client/server/\(.*\)$|/srv/openils/var/web/xul/server/\1|')
1f0c9b83 69 fi
70
c41c58e7
JD
71 if [ "$FILE" == "$AUTODEST" ]; then
72 echo "Destination path could not be determined.\n"
73 exit 1
74 fi
75
76 DEST=$AUTODEST
77
0155bbac 78fi
c41c58e7 79
23767567 80if [[ -z "$USER" ]]
c41c58e7
JD
81then
82 SSH="ssh"
920342e4 83 RSYNC_OPTS="-avz"
c41c58e7
JD
84else
85 SSH="ssh -l${USER}"
920342e4 86 RSYNC_OPTS="-rlpD --chown=${USER}:${USER}"
c41c58e7
JD
87fi
88
89if [[ -z "$PROD" ]]
90then
91 _hosts="$@"
92else
93 echo "adding ${_ProdServers} to hosts"
94 _hosts="$@$_ProdServers"
95fi
96
97for HOST in $_hosts
98do
99 RSYNC_DEST="${HOST}:${DEST}"
100 if [[ -z "$VERBOSE" ]]; then
101 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"
102 fi
920342e4 103 rsync -e"${SSH}" $BACKUP $RSYNC_OPTS $FILE $RSYNC_DEST
c41c58e7 104done