Miscellaneous accumulated scripts that were never checked in before.
[hcoop/scripts.git] / new-user
CommitLineData
6bdbb663 1#!/bin/bash
2
3USERNM=$1
4REALNM=$2
a302d1ed 5EMAILADDR=$3
6bdbb663 6PWFILE=/var/lib/portal/$USERNM
7
8if test -z "$USERNM"; then
9 echo Usage: create-user-wrapper USERNAME \'NAME SURNAME\' [EMAIL]
10 exit 1
11fi
12
13if test -z "$REALNM"; then
14 echo Usage: create-user-wrapper USERNAME \'NAME SURNAME\' [EMAIL]
15 exit 1
16fi
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#
29echo "
30dn: uid=$USERNM,ou=People,dc=hcoop,dc=net
31changetype: modify
32replace: gecos
33gecos: $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#
40if ! test -r "$PWFILE"; then
41 echo "Skipping password set from $PWFILE (doesn't exist or permission denied)"
42 #exit 4
43else
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"
51fi
52
53
54#
55# Set email forwarding
56#
57if test -z "$EMAILADDR"; then
58 echo "Skipping email forwarding, no email address was specified."
59else
60 echo setting email forward to "$EMAILADDR"
69574f2e 61 FORWARD_PATH=$(sh -c "echo ~$USERNM/.public/.forward")
62 echo "$EMAILADDR" > $FORWARD_PATH || \
6bdbb663 63 ( echo "Failed to set forward address" && exit 6 )
69574f2e 64 chown $USERNM $FORWARD_PATH
6bdbb663 65fi
66
67#
68# Done
69#
70echo All done.
71