-
Notifications
You must be signed in to change notification settings - Fork 4
/
alert-ucb.sh
executable file
·104 lines (98 loc) · 2.58 KB
/
alert-ucb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
#
# a helper for making 'alerts' for the django webapps for ucb museums on rtl 'managed servers'
#
#set -x
WHOLE_LIST="bampfa botgarden cinefiles pahma ucjeps"
if [[ $# -eq 0 ]] ;
then
echo
echo "./alert-ucb.sh -h for help"
echo
exit 1
fi
while [[ $# -gt 0 ]] ;
do
opt="$1";
shift;
case ${opt} in
'-h' )
echo
echo "usage:"
echo
echo "to make an alert for all ucb museums"
echo "./alert_ucb.sh -a -l 'Attention Please' -m 'Webapps coming down for upgrade at 10am'"
echo
echo "to alert particular museums, e.g. for pahma and cinefiles"
echo "./alert_ucb.sh pahma -l 'Alert' -m 'PAHMA and CineFiles restarting shortly.' cinefiles"
echo
echo "nb: You CAN customize all this further if you really need to. See the README.md for details."
echo
echo "to clear alerts"
echo "./alert_ucb.sh -a -c"
echo "./alert_ucb.sh -c ucjeps bampfa"
echo
echo "to see what alerts are set"
echo "./alert_ucb.sh -a -s"
echo "./alert_ucb.sh -s ucjeps bampfa"
echo
exit 0
;;
'-a' )
MUSEUMS=$WHOLE_LIST
;;
'-l' )
ALERT=$1 ; shift;
;;
'-c' )
ACTION='clear' ;
;;
'-s' )
ACTION='show' ;
;;
'-m' )
MESSAGE=$1 ; shift;
;;
* )
if [[ ! $MUSEUMS =~ .*$opt.* ]]
then
MUSEUMS="${MUSEUMS} $opt"
fi
;;
esac
done
SITE_DIR=cspace_django_site
BASE_DIR='/var/www'
echo "****************************************************************************"
echo "Alert webapp users:"
echo "****************************************************************************"
if [[ $ACTION != 'clear' && $ACTION != 'show' ]]
then
echo "label: ${ALERT}"
echo "message: ${MESSAGE}"
echo "****************************************************************************"
fi
for t in $MUSEUMS
do
if [[ $ACTION == 'clear' ]]
then
rm -f ${BASE_DIR}/${t}/config/alert.cfg
echo "Cleared alert for ${t}."
elif [[ $ACTION == 'show' ]]
then
echo
echo "Alert for ${t}:"
if [[ -f ${BASE_DIR}/${t}/config/alert.cfg ]]
then
cat ${BASE_DIR}/${t}/config/alert.cfg
else
echo "No alert set"
fi
else
perl -pe "s/#ALERT#/${ALERT}/; s/#MESSAGE#/${MESSAGE}/;" ${BASE_DIR}/${t}/${SITE_DIR}/alert_template.cfg > ${BASE_DIR}/${t}/config/alert.cfg
echo "Set alert for ${t}."
fi
done
echo "****************************************************************************"
echo "Done."
echo "****************************************************************************"