You need domtool-admin rights to destroy a user
[clinton/scripts.git] / new-user
1 #!/bin/bash
2
3 USERNM=$1
4 REALNM=$2
5 EMAILADDR=$3
6 PWFILE=/var/lib/portal/$USERNM
7
8 if test -z "$USERNM"; then
9 echo Usage: create-user-wrapper USERNAME \'NAME SURNAME\' [EMAIL]
10 exit 1
11 fi
12
13 if test -z "$REALNM"; then
14 echo Usage: create-user-wrapper USERNAME \'NAME SURNAME\' [EMAIL]
15 exit 1
16 fi
17
18
19
20 #
21 # Create user
22 #
23 /afs/hcoop.net/common/etc/scripts/create-user $USERNM || \
24 ( echo "create-user $USERNM failed" && exit 2 )
25
26 #
27 # Entry in LDAP is created, set real name
28 #
29 echo "
30 dn: uid=$USERNM,ou=People,dc=hcoop,dc=net
31 changetype: modify
32 replace: gecos
33 gecos: $REALNM
34 " | sudo ldapmodify -x -D cn=admin,dc=hcoop,dc=net -y /etc/ldap.secret || \
35 (echo Error modifying LDAP entry && exit 3 )
36
37 #
38 # Now set the password
39 #
40 if ! test -r "$PWFILE"; then
41 echo "Skipping password set from $PWFILE (doesn't exist or permission denied)"
42 #exit 4
43 else
44 echo Setting password from $PWFILE
45 sudo sh -c "cat $PWFILE | tee -| /afs/hcoop.net/common/etc/scripts/change-user-password $USERNM" || \
46 ( echo "cat $PWFILE | tee - | change-user-password $USERNM failed" && exit 5 )
47
48 # Delete password file
49 #sudo rm -- "$PWFILE"
50 echo "Not deleting $PWFILE. Enable it in the script when you want"
51 fi
52
53
54 #
55 # Set email forwarding
56 #
57 if test -z "$EMAILADDR"; then
58 echo "Skipping email forwarding, no email address was specified."
59 else
60 echo setting email forward to "$EMAILADDR"
61 FORWARD_PATH=$(sh -c "echo ~$USERNM/.public/.forward")
62 echo "$EMAILADDR" > $FORWARD_PATH || \
63 ( echo "Failed to set forward address" && exit 6 )
64 chown $USERNM $FORWARD_PATH
65 fi
66
67 #
68 # Done
69 #
70 echo All done.
71