s3: Use better retry logic.
[clinton/scripts.git] / destroy-user
1 #!/bin/bash
2
3 # MUST be executed:
4 # - on deleuze
5 # - as a user with an /etc/sudoers line
6 # - while holding system:administrator tokens
7
8 USER=$1
9 if test -z "$USER"; then
10 echo Usage: destroy-user USERNAME
11 exit 1
12 fi
13
14 PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
15 HOMEPATH=/afs/hcoop.net/user/$PATHBITS
16 MAILPATH=/afs/hcoop.net/common/email/$PATHBITS
17 DBPATH=/afs/.hcoop.net/common/.databases/$PATHBITS
18 # We don't use separate partitions for logs
19 #LOGSPATH=/afs/.hcoop.net/common/.logs/$USER
20
21 sudo rm -f /etc/keytabs/mailfilter/$USER
22 sudo rm -f /etc/keytabs/cgi/$USER
23 sudo rm -f /etc/keytabs/user.daemon/$USER
24
25 # LDAP
26 sudo ldapdelete -v -x -D cn=admin,dc=hcoop,dc=net -y /etc/ldap.secret \
27 uid=$USER,ou=People,dc=hcoop,dc=net
28 sudo ldapdelete -v -x -D cn=admin,dc=hcoop,dc=net -y /etc/ldap.secret \
29 uid=$USER.cgi,ou=People,dc=hcoop,dc=net
30 sudo ldapdelete -v -x -D cn=admin,dc=hcoop,dc=net -y /etc/ldap.secret \
31 uid=$USER.mailfilter,ou=People,dc=hcoop,dc=net
32 sudo ldapdelete -v -x -D cn=admin,dc=hcoop,dc=net -y /etc/ldap.secret \
33 cn=$USER,ou=Group,dc=hcoop,dc=net
34 sudo ldapdelete -v -x -D cn=admin,dc=hcoop,dc=net -y /etc/ldap.secret \
35 cn=$USER.cgi,ou=Group,dc=hcoop,dc=net
36 sudo ldapdelete -v -x -D cn=admin,dc=hcoop,dc=net -y /etc/ldap.secret \
37 cn=$USER.mailfilter,ou=Group,dc=hcoop,dc=net
38 sudo ldapdelete -v -x -D cn=admin,dc=hcoop,dc=net -y /etc/ldap.secret \
39 cn=$USER.daemon,ou=Group,dc=hcoop,dc=net
40
41 # Remove from domtool
42 domtool-rmuser $USER
43
44 # Invalidate nscd cache
45 sudo nscd -i passwd
46 sudo nscd -i group
47
48 # Remove from databases
49 sudo -u postgres psql -c "DROP TABLESPACE user_$USER"
50 #sudo -u postgres psql -c "DROP USER $USER"
51 #sudo -H mysql -e "DROP USER $USER@localhost"
52
53 fs rm $MAILPATH
54 fs rm $HOMEPATH
55 #fs rm $LOGSPATH
56 fs rm $DBPATH
57 fs rm /afs/.hcoop.net/old/user/$PATHBITS
58 fs rm /afs/.hcoop.net/old/mail/$PATHBITS
59 vos remove deleuze.hcoop.net /vicepa user.$USER
60 vos remove deleuze.hcoop.net /vicepa mail.$USER
61 vos remove deleuze.hcoop.net /vicepa db.$USER
62 #vos remove deleuze.hcoop.net /vicepa logs.$USER
63
64 vos release common.databases
65 #vos release common.logs
66
67 sudo kadmin.local -q "delprinc -force $USER@HCOOP.NET"
68 sudo kadmin.local -q "delprinc -force $USER/mailfilter@HCOOP.NET"
69 sudo kadmin.local -q "delprinc -force $USER/cgi@HCOOP.NET"
70 sudo kadmin.local -q "delprinc -force $USER/daemon@HCOOP.NET"
71
72 pts delete $USER
73 pts delete $USER.mailfilter
74 pts delete $USER.cgi
75 pts delete $USER.daemon
76
77 #fs rm /afs/hcoop.net/old/user/$PATHBITS
78 #fs rm /afs/hcoop.net/old/mail/$PATHBITS
79 #fs rm /afs/hcoop.net/old/logs/$PATHBITS
80
81 vos syncserv deleuze
82 vos syncvldb deleuze
83 fs checkvolumes
84
85 # Remove user from all of our mailing lists
86 echo $USER@hcoop.net | sudo -u list \
87 /var/lib/mailman/bin/remove_members --fromall -f -
88