source: trunk/packages/sipb-xen-remctl-auto/sipb-xen-remctl-auto/files/usr/sbin/remctl-update.sh @ 121

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

Move things around and add web interface support code.

  • Property svn:executable set to *
File size: 2.0 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 -nameorid "system:$group" -noauth | tail -n+2 | \
34        sed 's/\./\//; s/^  //; s/$/@ATHENA.MIT.EDU/g' >| "$MOIRATMP"
35    if test -s "$MOIRATMP"; then
36        if ! cmp -s "$MOIRADIR/$group" "$MOIRATMP"; then
37            mv "$MOIRATMP" "$MOIRADIR/$group"
38        fi
39    else
40        if test -e "$MOIRADIR/$group"; then
41            rm "$MOIRADIR/$group"
42        fi
43    fi
44    rm -f "$MOIRATMP"
45}
46
47case "$1" in
48    moiragroup)
49        update_moiragroup "$2"
50        ;;
51
52    all_machines)
53        # update the remctl.conf definitions
54        for machine in `cat "$AUTOMACHINELIST"`; do
55            update_machine "$machine"
56        done
57        ;;
58    all_moira)
59        # update our moira ACL lists
60        for group in `cat "$AUTOMOIRALIST"`; do
61            update_moiragroup "$group"
62        done
63        ;;
64    auto_machine_list)
65        # update the list of maintained machines
66        /bin/ls "$ACLDIR" >| "$AUTOMACHINELIST"
67        ;;
68    auto_moira_list)
69        # update the moira list-of-lists
70        # /bin/ls "$MOIRADIR" >| "$AUTOMOIRALIST" # BAD IDEA in case of outage
71
72        # This extracts the list of all moira lists we care about, and updates those.
73        grep -R moira "$ACLDIR/" /etc/remctl/acl/ | perl -pe 's/.*moira-acl\/(.*)/$1/g' >| "$AUTOMOIRALIST"
74        ;;
75    all)
76        "$0" auto_machine_list
77        "$0" all_machines
78        "$0" auto_moira_list
79        "$0" all_moira
80        ;;
81esac
82
83exit 0
Note: See TracBrowser for help on using the repository browser.