source: trunk/packages/sipb-xen-remctl-auto/files/usr/sbin/sipb-xen-remctl-update @ 420

Last change on this file since 420 was 195, checked in by tabbott, 17 years ago

restructuring of remctl code and interface

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/bin/sh
2DIR=/etc/remctl/sipb-xen-auto
3TEMPLATE=$DIR/conf.template
4MACHINEDIR=$DIR/machine.d
5MOIRADIR=$DIR/moira-acl
6MOIRATMP=$DIR/moira-tmp
7MACHINETMP=$DIR/machine-list-tmp
8AUTOMACHINELIST=$DIR/auto-machine-list
9AUTOMOIRALIST=$DIR/auto-moira-list
10BINDIR=/usr/sbin
11ACLDIR=$DIR/acl
12
13update_machine()
14{
15    machine="$1"
16    sed "s/#MACHINENAME#/$machine/g" "$TEMPLATE" | \
17        sed "s,#BINDIR#,$BINDIR,g" >| "$MACHINETMP"
18    if ! cmp -s "$MACHINEDIR/$machine" "$MACHINETMP"; then
19        mv "$MACHINETMP" "$MACHINEDIR/$machine"
20    else
21        rm -f "$MACHINETMP"
22    fi
23}
24
25update_moiragroup()
26{
27    group="$1"
28    # Should perhaps replace with LDAP, but fine for now.
29
30    # We should do more careful error checking so we don't take away
31    # all bits and delete the moira-acl files whenever there's an AFS
32    # outage.
33    pts membership system:"$group" -noauth | tail -n+2 | \
34        sed 's/\./\//' | \
35        sed 's/^  //' | \
36        sed 's/$/@ATHENA.MIT.EDU/g' >| "$MOIRATMP"
37    if test -s "$MOIRATMP"; then
38        if ! cmp -s "$MOIRADIR/$group" "$MOIRATMP"; then
39            mv "$MOIRATMP" "$MOIRADIR/$group"
40        fi
41    else
42        if test -e "$MOIRADIR/$group"; then
43            rm "$MOIRADIR/$group"
44        fi
45    fi
46    rm -f "$MOIRATMP"
47}
48
49check_machine_name()
50{
51    machinename="$1"
52    if ! perl -0e 'exit($ARGV[0] !~ /^[A-Za-z0-9][A-Za-z0-9._-]*$/)' -- "$machinename"; then
53        echo "Bad machine name"
54        exit 1
55    fi
56}
57
58case "$1" in
59    moiragroup)
60        update_moiragroup "$2"
61        ;;
62
63    all_machines)
64        # update the remctl.conf definitions
65        for machine in `cat "$AUTOMACHINELIST"`; do
66            update_machine "$machine"
67        done
68        ;;
69    all_moira)
70        # update our moira ACL lists
71        for group in `cat "$AUTOMOIRALIST"`; do
72            update_moiragroup "$group"
73        done
74        ;;
75    auto_machine_list)
76        # update the list of maintained machines
77        /bin/ls "$ACLDIR" >| "$AUTOMACHINELIST"
78        ;;
79    auto_moira_list)
80        # update the moira list-of-lists
81        # /bin/ls "$MOIRADIR" >| "$AUTOMOIRALIST" # BAD IDEA in case of outage
82
83        # This extracts the list of all moira lists we care about, and updates those.
84        grep -R moira "$ACLDIR/" /etc/remctl/acl/ | perl -pe 's/.*moira-acl\/(.*)/$1/g' >| "$AUTOMOIRALIST"
85        ;;
86    unregister)
87        machine="$2"
88        check_machine_name "$machine"
89        rm -f "$ACLDIR"/"$machine"
90        rm -f "$MACHINEDIR"/"$machine"
91        "$0" web
92        ;;
93    moveregister)
94        oldmachine="$2"
95        newmachine="$3"
96        check_machine_name "$oldmachine"
97        check_machine_name "$newmachine"
98        mv "$ACLDIR"/"$oldmachine" "$ACLDIR"/"$newmachine"
99        rm -f "$MACHINEDIR"/"$oldmachine"
100        "$0" web
101        ;;
102    register)
103        machine="$2"
104        check_machine_name "$machine"
105        if [ -e "$ACLDIR"/"$machine" ]; then
106            echo "Machine already registered"
107            exit 1
108        fi
109        echo "include /etc/remctl/acl/web" > "$ACLDIR/$machine"
110        "$0" web
111        ;;
112    web)
113        "$0" auto_machine_list
114        "$0" all_machines
115        ;;     
116    remctl-moira-update|all)
117        "$0" auto_machine_list
118        "$0" all_machines
119        "$0" auto_moira_list
120        "$0" all_moira
121        ;;
122esac
123
124exit 0
Note: See TracBrowser for help on using the repository browser.