[121] | 1 | #!/bin/sh |
---|
| 2 | DIR=/etc/remctl/sipb-xen-auto |
---|
| 3 | TEMPLATE=$DIR/conf.template |
---|
| 4 | MACHINEDIR=$DIR/machine.d |
---|
| 5 | MOIRADIR=$DIR/moira-acl |
---|
| 6 | MOIRATMP=$DIR/moira-tmp |
---|
| 7 | MACHINETMP=$DIR/machine-list-tmp |
---|
| 8 | AUTOMACHINELIST=$DIR/auto-machine-list |
---|
| 9 | AUTOMOIRALIST=$DIR/auto-moira-list |
---|
| 10 | BINDIR=/usr/sbin |
---|
| 11 | ACLDIR=$DIR/acl |
---|
| 12 | |
---|
| 13 | update_machine() |
---|
| 14 | { |
---|
[126] | 15 | machine="$1" |
---|
[121] | 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 | |
---|
| 25 | update_moiragroup() |
---|
| 26 | { |
---|
[126] | 27 | group="$1" |
---|
[121] | 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. |
---|
[126] | 33 | pts membership system:"$group" -noauth | tail -n+2 | \ |
---|
| 34 | sed 's/\./\//' | \ |
---|
| 35 | sed 's/^ //' | \ |
---|
| 36 | sed 's/$/@ATHENA.MIT.EDU/g' >| "$MOIRATMP" |
---|
[121] | 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 | |
---|
| 49 | case "$1" in |
---|
| 50 | moiragroup) |
---|
| 51 | update_moiragroup "$2" |
---|
| 52 | ;; |
---|
| 53 | |
---|
| 54 | all_machines) |
---|
| 55 | # update the remctl.conf definitions |
---|
| 56 | for machine in `cat "$AUTOMACHINELIST"`; do |
---|
| 57 | update_machine "$machine" |
---|
| 58 | done |
---|
| 59 | ;; |
---|
| 60 | all_moira) |
---|
| 61 | # update our moira ACL lists |
---|
| 62 | for group in `cat "$AUTOMOIRALIST"`; do |
---|
| 63 | update_moiragroup "$group" |
---|
| 64 | done |
---|
| 65 | ;; |
---|
| 66 | auto_machine_list) |
---|
| 67 | # update the list of maintained machines |
---|
| 68 | /bin/ls "$ACLDIR" >| "$AUTOMACHINELIST" |
---|
| 69 | ;; |
---|
| 70 | auto_moira_list) |
---|
| 71 | # update the moira list-of-lists |
---|
| 72 | # /bin/ls "$MOIRADIR" >| "$AUTOMOIRALIST" # BAD IDEA in case of outage |
---|
| 73 | |
---|
| 74 | # This extracts the list of all moira lists we care about, and updates those. |
---|
| 75 | grep -R moira "$ACLDIR/" /etc/remctl/acl/ | perl -pe 's/.*moira-acl\/(.*)/$1/g' >| "$AUTOMOIRALIST" |
---|
| 76 | ;; |
---|
[130] | 77 | unregister) |
---|
| 78 | machine="$2" |
---|
| 79 | rm -f "$ACLDIR"/"$machine" |
---|
| 80 | rm -f "$MACHINEDIR"/"$machine" |
---|
| 81 | "$0" web |
---|
| 82 | ;; |
---|
[126] | 83 | register) |
---|
[130] | 84 | machine="$2" |
---|
| 85 | if [ "$machine" == "Domain-0" ]; then |
---|
[126] | 86 | echo "No, you can't control Domain 0" |
---|
| 87 | exit 1 |
---|
| 88 | fi |
---|
[130] | 89 | if [ -e /etc/xen/"$machine" ]; then |
---|
[126] | 90 | echo "Machine already exists outside database" |
---|
| 91 | exit 1 |
---|
| 92 | fi |
---|
[130] | 93 | if [ -e "$ACLDIR"/"$machine" ]; then |
---|
[126] | 94 | echo "Machine already registered" |
---|
| 95 | exit 1 |
---|
| 96 | fi |
---|
[130] | 97 | echo "include /etc/remctl/acl/web" > "$ACLDIR/$machine" |
---|
[126] | 98 | "$0" web |
---|
| 99 | ;; |
---|
| 100 | web) |
---|
| 101 | "$0" auto_machine_list |
---|
| 102 | "$0" all_machines |
---|
| 103 | ;; |
---|
[130] | 104 | remctl-moira-update|all) |
---|
[121] | 105 | "$0" auto_machine_list |
---|
| 106 | "$0" all_machines |
---|
| 107 | "$0" auto_moira_list |
---|
| 108 | "$0" all_moira |
---|
| 109 | ;; |
---|
| 110 | esac |
---|
| 111 | |
---|
| 112 | exit 0 |
---|