classify-users: determine type of Athena accounts
[user/alex/software/my-snippets.git] / list-of-lists-updater
1 #!/bin/bash
2 # Alex Dehnert --- 2009-04-23
3 # Attempt to update the list of UA lists
4 # Takes the container mailing lists on the commandline
5
6 prev=$1
7 anti=$2
8 nativepat=$3
9
10 prev=${prev:-ua-lists}
11 anti=${anti:-ua-foreign-lists}
12 nativepat=${nativepat:-ua}
13
14 function prefix {
15     #echo "$@"
16     "$@"
17 }
18
19 function add_lists
20 {
21     (
22     lists=$(blanche $prev | grep LIST | cut -d : -f 2)
23     for list in $lists; do # for each list we already know about
24         # Add a list's sublists
25         for newlist in $(blanche $list | grep LIST | cut -d : -f 2); do
26             prefix blanche $prev -a $newlist;
27         done;
28         # Add a list's owner and memacl
29         owner=$(athrun ops qy -s -f ace_name glin $list)
30         towner=$(athrun ops qy -s -f ace_type glin $list)
31         if [[ "$towner" == "LIST" ]]; then
32             prefix blanche $prev -a $owner
33         fi
34         macl=$(athrun ops qy -s -f memace_name glin $list)
35         tmacl=$(athrun ops qy -s -f memace_type glin $list)
36         if [[ "$tmacl" == "LIST" ]]; then
37             prefix blanche $prev -a $macl
38         fi
39         # Add stuff this owns
40         owned=$(athrun ops qy -s get_ace_use list $list | grep -v ^$prev\$ | grep LIST | cut -d " " -f 2)
41         for newlist in $owned; do
42             prefix blanche $prev -a $newlist;
43         done;
44     done
45     ) 2>&1 | grep -v "Record already exists" | grep -v "moira (query): No records in database match query"
46 }
47
48 echo Current members: $(blanche $prev -m | wc)
49 echo Expanding out lists
50 add_lists
51 echo New members: $(blanche $prev -m | wc)
52 echo Removing foreign lists
53 for list in $(blanche $anti | grep LIST | cut -d : -f 2); do blanche $prev -d $list; done
54 echo Finalized members: $(blanche $prev -m | wc)
55
56 echo 
57 echo Likely foreign members
58 blanche $prev | grep LIST: | sed -e "s/^LIST://" | egrep -v "$nativepat"