Testing version for validation and overdue checks.
[public/pyceo-broken.git] / misc / notify-hook
1 #!/bin/sh
2
3 prog=$1
4 auth=$2
5 shift 2
6
7 tmp="$(tempfile)"
8 trap "rm $tmp" 0
9 exec >"$tmp"
10
11 authrn="$(getent passwd "$auth" | awk -F: '{ print $5 }' | sed 's/,.*//')"
12
13 echo "From: $prog <ceo+$prog@csclub.uwaterloo.ca>"
14 echo "To: Membership and Accounts <ceo@csclub.uwaterloo.ca>"
15 echo "Cc: $authrn <$auth@csclub.uwaterloo.ca>"
16
17 if test "$prog" = addmember; then
18     user=$1 name=$2 dept=$3; shift 3
19     subj="New Member: $user"
20     test -z "$dept" && dept="things unknown"
21     body="Name: $name
22 Account: $user
23 Program: $dept
24 Added by: $auth"
25
26 elif test "$prog" = addclub; then
27     user=$1 name=$2; shift 2
28     subj="New Club Account: $user"
29     body="Club: $name
30 Account: $user
31 Added by: $auth"
32
33 else
34     exit 1
35 fi
36
37 output=$(cat)
38
39 echo "X-Auth-User: $auth"
40 echo "X-New-User: $user"
41 echo "X-New-Name: $name"
42 echo "Subject: $subj"
43 echo
44 echo "$body" | fmt -s
45 echo
46
47 if test -n "$output"; then
48     echo
49     echo "$output"
50 fi
51
52 echo
53 echo Your Friend,
54 echo "$prog"
55
56 exec >&- 2>&-
57 /usr/sbin/sendmail -t -f "ceo@csclub.uwaterloo.ca" < "$tmp"