Sync keytabs to navajos
[hcoop/scripts.git] / create-user
index b401d00..3ffa5f9 100755 (executable)
@@ -1,14 +1,14 @@
 #!/bin/bash -ex
 
 # MUST be executed:
-#  - on deleuze
+#  - on fritz
 #  - as a user with an /etc/sudoers line
-#  - member of "wheel" unix group on deleuze
+#  - member of "wheel" unix group on deleuze (FIXME: TRUE?)
 #  - while holding tickets for a user who can 'ssh -K' to mire
 #     - and is a member of "wheel" on mire
 #  - while holding tokens for a user who is:
 #     - a member of system:administrator
-#     - listed in 'bos listusers deleuze'
+#     - listed in 'bos listusers fritz'
 #  - and who has been set up with Domtool admin privileges by:
 #     - running 'domtool-adduser $USER' while holding AFS admin tokens as
 #       someone who is already a Domtool admin
@@ -41,19 +41,23 @@ fi
 # Run a command on both mire and deleuze; assumes that no escaping is
 # needed.
 function mire_and_deleuze() {
-    $*
-    ssh -K mire.hcoop.net $*
+    execute_on_deleuze $*
+    execute_on_mire $*
+}
+
+function execute_on_deleuze () {
+    ssh -K deleuze.hcoop.net $*
 }
 
-function execute_on_fritz () {
-    ssh -K fritz.hcoop.net $*
+function execute_on_mire () {
+    ssh -K mire.hcoop.net $*
 }
 
 function execute_on_all_machines () {
     $*
     ssh -K mire.hcoop.net $*
     ssh -K hopper.hcoop.net $*
-    ssh -K fritz.hcoop.net $*
+    ssh -K deleuze.hcoop.net $*
 }
 
 #
@@ -91,54 +95,8 @@ PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
 HOMEPATH=/afs/hcoop.net/user/$PATHBITS
 MAILPATH=/afs/hcoop.net/common/email/$PATHBITS
 
-#
-# Create LDAP entries. (With the whole libnss-ptdb, I kind of
-# lost the idea of what I want to do with LDAP, but we'll 
-# see with time how well it integrates...)
-# The ID returned from AFS is important here, we want to make
-# sure those IDs match.
-#
-
-# USER entry
-echo "
-dn: uid=$USER,ou=People,dc=hcoop,dc=net
-objectClass: top
-objectClass: person
-objectClass: posixAccount
-cn: $USER
-uid: $USER
-gidNumber: $ID
-sn: $USER
-host: abulafia
-host: mire
-
-dn: cn=$USER,ou=Group,dc=hcoop,dc=net
-objectClass: top
-objectClass: posixGroup
-cn: $USER
-gidNumber: $ID
-memberUid: $USER
-" | sudo ldapadd -x -D cn=admin,dc=hcoop,dc=net -y /etc/ldap.secret || true
-
-# USER.daemon entry
-echo "
-dn: uid=$USER.daemon,ou=People,dc=hcoop,dc=net
-objectClass: top
-objectClass: person
-objectClass: posixAccount
-cn: $USER.daemon
-uid: $USER.daemon
-gidNumber: $ID_DAEMON
-sn: $USER.daemon
-
-dn: cn=$USER.daemon,ou=Group,dc=hcoop,dc=net
-objectClass: top
-objectClass: posixGroup
-cn: $USER.daemon
-gidNumber: $ID_DAEMON
-memberUid: $USER.daemon
-" | sudo ldapadd -x -D cn=admin,dc=hcoop,dc=net -y /etc/ldap.secret || true
 
+# LDAP bit excised (see git history...)
 
 #
 # Export .mailfilter and .cgi keys to a keytab file
@@ -160,6 +118,12 @@ sudo chmod 440            /etc/keytabs/user.daemon/$USER
 (cd /etc/keytabs
    sudo tar clpf - user.daemon/$USER | \
      ssh hopper.hcoop.net cd /etc/keytabs\; sudo tar xlpf -)
+(cd /etc/keytabs
+   sudo tar clpf - user.daemon/$USER | \
+     ssh deleuze.hcoop.net cd /etc/keytabs\; sudo tar xlpf -)
+(cd /etc/keytabs
+   sudo tar clpf - user.daemon/$USER | \
+     ssh navajos.hcoop.net cd /etc/keytabs\; sudo tar xlpf -)
 
 #
 # Create/mount/set-perms on user's volumes (home, mail, databases, logs)
@@ -211,7 +175,10 @@ mkdir -p $HOMEPATH/.public/.domtool
 chown $USER:nogroup $HOMEPATH/.public/.domtool
 test -e $HOMEPATH/.domtool || \
     test -L $HOMEPATH/.domtool || \
-        sudo -u $USER ln -s $HOMEPATH/.public/.domtool $HOMEPATH/.domtool
+        execute_on_deleuze sudo -u $USER ln -s $HOMEPATH/.public/.domtool $HOMEPATH/.domtool
+        # ^^ work around sudo env_reset crap without having to
+        # actually figure out how to make it work cleanly -- clinton,
+        # 2011-11-30
 
 # Gitweb hosting
 test -L /var/cache/git/$USER || \
@@ -259,7 +226,7 @@ else
 fi
 
 # Create database tablespaces
-execute_on_fritz /afs/hcoop.net/common/etc/scripts/create-user-database $USER
+sudo /afs/hcoop.net/common/etc/scripts/create-user-database $USER
 
 #
 # Mount points for backup volumes
@@ -294,10 +261,10 @@ mire_and_deleuze sudo chmod ug=rwx,o= /var/lock/apache2/dav/$USER
 # Domtool integration
 #
 
-domtool-adduser $USER
+execute_on_deleuze domtool-adduser $USER
 
 #
 # Subscribe user to our mailing lists.
 #
-echo $USER@hcoop.net | sudo -u list \
+echo $USER@hcoop.net | execute_on_deleuze sudo -u list \
     /var/lib/mailman/bin/add_members -r - hcoop-announce