Initial commit of various scripts
[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 add_lists
15 {
16     (
17     for list in $(blanche $prev | grep LIST | cut -d : -f 2); do # for each list we already know about
18         # Add a list's sublists
19         for newlist in $(blanche $list | grep LIST | cut -d : -f 2); do
20             blanche $prev -a $newlist;
21         done;
22         # Add a list's owner and memacl
23         owner=$(athrun ops qy -s -f ace_name glin $list)
24         towner=$(athrun ops qy -s -f ace_type glin $list)
25         if [[ "$towner" == "LIST" ]]; then
26             blanche $prev -a $owner
27         fi
28         macl=$(athrun ops qy -s -f memace_name glin $list)
29         tmacl=$(athrun ops qy -s -f memace_type glin $list)
30         if [[ "$tmacl" == "LIST" ]]; then
31             blanche $prev -a $macl
32         fi
33     done
34     ) 2>&1 | grep -v "Record already exists"
35 }
36
37 echo Current members: $(blanche $prev -m | wc)
38 echo Expanding out lists
39 add_lists
40 add_lists
41 echo New members: $(blanche $prev -m | wc)
42 echo Removing foreign lists
43 for list in $(blanche $anti | grep LIST | cut -d : -f 2); do blanche $prev -d $list; done
44 echo Finalized members: $(blanche $prev -m | wc)
45
46 echo 
47 echo Likely foreign members
48 blanche $prev | grep LIST: | sed -e "s/^LIST://" | grep -v $nativepat