Add build.sh
[public/pyceo-broken.git] / misc / notify-hook
1 #!/bin/bash -p
2
3 # This is a privileged script.
4 IFS=$' \t\n'
5 PATH=/usr/bin:/bin
6 unset ENV BASH_ENV CDPATH
7 umask 077
8
9 prog=$1
10 auth=$2
11 shift 2
12
13 tmp="$(tempfile)"
14 trap "rm $tmp" 0
15 exec >"$tmp"
16
17 authrn="$(getent passwd "$auth" | awk -F: '{ print $5 }' | sed -e 's/,.*//')"
18
19 h_from="$prog <ceo+$prog@csclub.uwaterloo.ca>"
20 h_to="Membership and Accounts <ceo@csclub.uwaterloo.ca>"
21 h_cc="$authrn <$auth@csclub.uwaterloo.ca>"
22
23 if test "$prog" = addmember; then
24     user=$1 name=$2 dept=$3 status=$4; shift 4
25     subj="New Member: $user"
26     test -z "$dept" && dept="things unknown"
27     body="Name: $name
28 Account: $user
29 Program: $dept
30 Added by: $auth"
31
32 elif test "$prog" = addclub; then
33     user=$1 name=$2 status=$4; shift 4
34     subj="New Club Account: $user"
35     body="Club: $name
36 Account: $user
37 Added by: $auth"
38
39 else
40     exit 1
41 fi
42
43 output=$(cat)
44
45 if test "$status" = "failure"; then
46   subj="$subj (FAILURES)"
47 fi
48
49 echo "From: $h_from"
50 echo "To: $h_to"
51 echo "Cc: $h_cc"
52 echo "X-Auth-User: $auth"
53 echo "X-New-User: $user"
54 echo "X-New-Name: $name"
55 echo "Subject: $subj"
56 echo
57 echo "$body" | fmt -s
58 echo
59
60 if test "$status" = "success"; then
61     echo all failures went undetected
62 elif test -n "$output"; then
63     echo "$output"
64 fi
65
66 echo
67 echo Your Friend,
68 echo "$prog"
69
70 exec >&2
71 env - /usr/sbin/sendmail -t -f "ceo@csclub.uwaterloo.ca" < "$tmp"