tell ceod when it is a club rep; club reps don't need the new member email
[public/pyceo-broken.git] / etc / spam / new-member.d / announce
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=$CEO_PROG
10 auth=$CEO_AUTH
11
12 tmp="$(tempfile)"
13 trap "rm $tmp" 0
14 exec >"$tmp"
15
16 authrn="$(getent passwd "$auth" | awk -F: '{ print $5 }' | sed -e 's/,.*//')"
17
18 h_from="$prog <ceo+$prog@csclub.uwaterloo.ca>"
19 h_to="Membership and Accounts <ceo@csclub.uwaterloo.ca>"
20 h_cc="$authrn <$auth@csclub.uwaterloo.ca>"
21
22 if [[ "$prog" = addmember || "$prog" == addclubrep ]]; then
23     user="$CEO_USER" name="$CEO_NAME" dept="$CEO_DEPT" status="$CEO_STATUS"
24     subj="New Member: $user"
25     test -z "$dept" && dept="things unknown"
26     body="Name: $name
27 Account: $user
28 Program: $dept
29 Added by: $auth"
30
31 elif [[ "$prog" = addclub ]]; then
32     user="$CEO_USER" name="$CEO_NAME" status="$CEO_STATUS"
33     subj="New Club Account: $user"
34     body="Club: $name
35 Account: $user
36 Added by: $auth"
37
38 else
39     exit 1
40 fi
41
42 output="$CEO_OUTPUT"
43
44 if test "$status" = "failure"; then
45   subj="$subj (FAILURES)"
46 fi
47
48 echo "From: $h_from"
49 echo "To: $h_to"
50 echo "Cc: $h_cc"
51 echo "X-Auth-User: $auth"
52 echo "X-New-User: $user"
53 echo "X-New-Name: $name"
54 echo "Subject: $subj"
55 echo
56 echo "$body" | fmt -s
57 echo
58
59 if test "$status" = "success"; then
60     echo all failures went undetected
61 elif test -n "$output"; then
62     echo "$output"
63 fi
64
65 echo
66 echo Your Friend,
67 echo "$prog"
68
69 exec >&2
70 env - /usr/sbin/sendmail -t -f "ceo@csclub.uwaterloo.ca" < "$tmp"