Fix restoring shell on unfreeze when member did not have a shell preference
[hcoop/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 ssh -K fritz.hcoop.net /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 actual_user=`whoami`
46 sudo sh -c "cat $PWFILE | tee -| ssh -K ${actual_user}@fritz.hcoop.net /afs/hcoop.net/common/etc/scripts/change-user-password $USERNM" || \
47 ( echo "cat $PWFILE | tee - | change-user-password $USERNM failed" && exit 5 )
48
49 # Delete password file
50 #sudo rm -- "$PWFILE"
51 # echo "Not deleting $PWFILE. Enable it in the script when you want"
52 fi
53
54
55 #
56 # Set email forwarding
57 #
58 if test -z "$EMAILADDR"; then
59 echo "Skipping email forwarding, no email address was specified."
60 else
61 echo setting email forward to "$EMAILADDR"
62 FORWARD_PATH=$(sh -c "echo ~$USERNM/.public/.forward")
63 echo "$EMAILADDR" > $FORWARD_PATH || \
64 ( echo "Failed to set forward address" && exit 6 )
65 chown $USERNM $FORWARD_PATH
66 fi
67
68 #
69 # Done
70 #
71 echo All done.
72