install-eg.sh: fix error in tarball download
[sitka/sitka-tools.git] / deployment / deployfile.sh
CommitLineData
0155bbac
JD
1#!/bin/bash
2
e6ecfebd 3_ProdServers=" app1 app2 app3 app4 utility1 utility2 sip2 bibc-prod"
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
f7c3cb5f 19 -x Do not warn when extra build steps are required
0155bbac 20 -h Print this message and exit
c41c58e7 21 -v Verbose output - echo parameters to stdout
0155bbac
JD
22EOF
23}
24
f7c3cb5f 25while getopts ":f:p:u:bdPxvh" opt
0155bbac
JD
26do
27 case $opt in
28 f ) FILE=$OPTARG;;
29 p ) DEST=$OPTARG;;
c41c58e7 30 d ) AUTOPATH="d";;
0155bbac
JD
31 u ) USER=$OPTARG;;
32 b ) BACKUP="-b --suffix=.`date +%Y%m%d%H%M`";;
1f0c9b83 33 P ) PROD="P";;
f7c3cb5f 34 x ) SKIP_BUILD_CHECK="x";;
c41c58e7 35 v ) VERBOSE="v";;
0155bbac
JD
36 h ) usage && exit 0;;
37 esac
38done
39shift $(($OPTIND - 1))
40
c41c58e7 41if [[ -z "$FILE" ]] || ([[ -z "$DEST" ]] && [[ -z "$AUTOPATH" ]]) | ([[ $# -lt 1 ]] && [[ -z "$PROD" ]])
0155bbac
JD
42then
43 usage
44 exit 1
c41c58e7
JD
45fi
46
f7c3cb5f
JD
47if [[ -z "$SKIP_BUILD_CHECK" ]] ; then
48 if [[ $FILE = *Open-ILS/web/js/ui/default/staff* ]] ; then
49 echo "It looks like you are trying to deploy Evergreen web client JS."
50 echo "In EG 3.1+ and master, you must build JS before copying into place."
51 echo "After making changes, run 'npm run build' before deploying."
52 echo "(Re-run this script with the -x flag to skip this warning.)"
53 exit 1
54 fi
55fi
56
c41c58e7
JD
57# attempt to determine the remote destination path automatically
58if [[ -n "$AUTOPATH" ]] && [[ -z "$DEST" ]]
59then
60
61 AUTODEST=$FILE
62
63 # TPAC
64 if [ "$FILE" == "$AUTODEST" ]; then
65 AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/src/templates/\(.*\)$|/srv/openils/var/templates/\1|')
66 fi
67
68 # perl
69 if [ "$FILE" == "$AUTODEST" ]; then
f404334e 70 AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/src/perlmods/lib/\(.*\)$|/usr/local/share/perl/5.18.2/\1|')
c41c58e7 71 fi
0155bbac 72
c41c58e7
JD
73 # web
74 if [ "$FILE" == "$AUTODEST" ]; then
75 AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/web/\(.*\)$|/srv/openils/var/web/\1|')
0155bbac
JD
76 fi
77
c41c58e7
JD
78 # xul
79 if [ "$FILE" == "$AUTODEST" ]; then
80 AUTODEST=$(printf '%s' "$FILE" | sed 's|^.*Open-ILS/xul/staff_client/server/\(.*\)$|/srv/openils/var/web/xul/server/\1|')
1f0c9b83 81 fi
82
c41c58e7
JD
83 if [ "$FILE" == "$AUTODEST" ]; then
84 echo "Destination path could not be determined.\n"
85 exit 1
86 fi
87
88 DEST=$AUTODEST
89
0155bbac 90fi
c41c58e7 91
23767567 92if [[ -z "$USER" ]]
c41c58e7
JD
93then
94 SSH="ssh"
920342e4 95 RSYNC_OPTS="-avz"
c41c58e7
JD
96else
97 SSH="ssh -l${USER}"
920342e4 98 RSYNC_OPTS="-rlpD --chown=${USER}:${USER}"
c41c58e7
JD
99fi
100
101if [[ -z "$PROD" ]]
102then
103 _hosts="$@"
104else
105 echo "adding ${_ProdServers} to hosts"
106 _hosts="$@$_ProdServers"
107fi
108
109for HOST in $_hosts
110do
111 RSYNC_DEST="${HOST}:${DEST}"
112 if [[ -z "$VERBOSE" ]]; then
a0241ef5
JD
113 echo "deploying to ${HOST}"
114 else
c41c58e7
JD
115 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"
116 fi
920342e4 117 rsync -e"${SSH}" $BACKUP $RSYNC_OPTS $FILE $RSYNC_DEST
c41c58e7 118done