1) reworking of lvm stuff into a single python script rather than a pile of shell...
[invirt/packages/invirt-remote.git] / files / usr / sbin / remctl-update.sh
index 4427531..c5cf3f3 100755 (executable)
@@ -12,7 +12,7 @@ ACLDIR=$DIR/acl
 
 update_machine()
 {
-    machine=$1
+    machine="$1"
     sed "s/#MACHINENAME#/$machine/g" "$TEMPLATE" | \
        sed "s,#BINDIR#,$BINDIR,g" >| "$MACHINETMP"
     if ! cmp -s "$MACHINEDIR/$machine" "$MACHINETMP"; then
@@ -24,14 +24,16 @@ update_machine()
 
 update_moiragroup()
 {
-    group=$1
+    group="$1"
     # Should perhaps replace with LDAP, but fine for now.
 
     # We should do more careful error checking so we don't take away
     # all bits and delete the moira-acl files whenever there's an AFS
     # outage.
-    pts membership -nameorid "system:$group" -noauth | tail -n+2 | \
-       sed 's/\./\//; s/^  //; s/$/@ATHENA.MIT.EDU/g' >| "$MOIRATMP"
+    pts membership system:"$group" -noauth | tail -n+2 | \
+       sed 's/\./\//' | \
+       sed 's/^  //' | \
+       sed 's/$/@ATHENA.MIT.EDU/g' >| "$MOIRATMP"
     if test -s "$MOIRATMP"; then
        if ! cmp -s "$MOIRADIR/$group" "$MOIRATMP"; then
            mv "$MOIRATMP" "$MOIRADIR/$group"
@@ -44,6 +46,15 @@ update_moiragroup()
     rm -f "$MOIRATMP"
 }
 
+check_machine_name()
+{
+    machine="$1"
+    if ! perl -0e 'exit($ARGV[0] !~ /^[A-Za-z0-9][A-Za-z0-9._-]*$/)' -- "$machinename"; then
+       echo "Bad machine name"
+       exit 1
+    fi
+}
+
 case "$1" in
     moiragroup)
        update_moiragroup "$2"
@@ -72,7 +83,37 @@ case "$1" in
        # This extracts the list of all moira lists we care about, and updates those.
        grep -R moira "$ACLDIR/" /etc/remctl/acl/ | perl -pe 's/.*moira-acl\/(.*)/$1/g' >| "$AUTOMOIRALIST"
        ;;
-    all)
+    unregister)
+       machine="$2"
+       check_machine_name "$machine"
+       rm -f "$ACLDIR"/"$machine"
+       rm -f "$MACHINEDIR"/"$machine"
+       "$0" web
+       ;;
+    moveregister)
+        oldmachine="$2"
+        newmachine="$3"
+       check_machine_name "$oldmachine"
+       check_machine_name "$newmachine"
+        mv "$ACLDIR"/"$oldmachine" "$ACLDIR"/"$newmachine"
+        rm -f "$MACHINEDIR"/"$oldmachine"
+        "$0" web
+       ;;
+    register)
+       machine="$2"
+       check_machine_name "$machine"
+       if [ -e "$ACLDIR"/"$machine" ]; then
+           echo "Machine already registered"
+           exit 1
+       fi
+       echo "include /etc/remctl/acl/web" > "$ACLDIR/$machine"
+       "$0" web
+       ;;
+    web)
+       "$0" auto_machine_list
+       "$0" all_machines
+       ;;      
+    remctl-moira-update|all)
        "$0" auto_machine_list
        "$0" all_machines
        "$0" auto_moira_list