[Server-devel] [PATCH] Make users home directory configurable

Bernie Innocenti bernie at codewiz.org
Sun Aug 22 13:50:39 EDT 2010


The default is still /library/users, of course.

This patch also adds an explicit "-m" argument to createuser, which
seems to be required on Debian and quotes around $username, just in
case.

Signed-off-by: Bernie Innocenti <bernie at codewiz.org>
---
 conf.schoolserver/idmgr.conf |    5 ++++-
 scripts/create_user          |   18 +++++++++++-------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/conf.schoolserver/idmgr.conf b/conf.schoolserver/idmgr.conf
index 04b71e8..a8d8fd6 100644
--- a/conf.schoolserver/idmgr.conf
+++ b/conf.schoolserver/idmgr.conf
@@ -29,4 +29,7 @@
 #WORKDIR = '/home/idmgr'
 
 ##How many registrations before we switch to day-based clumping.
-#USE_GROUPS_THRESHOLD = 40
\ No newline at end of file
+#USE_GROUPS_THRESHOLD = 40
+
+## Where to create home directories for registered laptops
+#XO_USERS_DIR=/library/users
diff --git a/scripts/create_user b/scripts/create_user
index 96cd522..bc46fc4 100755
--- a/scripts/create_user
+++ b/scripts/create_user
@@ -28,6 +28,12 @@ if [ `whoami` != "root" ]; then
         exec sudo -S $0
 fi
 
+# Set defaults and read configuration
+XO_USERS_DIR=/library/users
+XO_USERS_GROUP=xousers
+RSSH_USERS_GROUP=rsshusers
+. /etc/idmgr.conf
+
 log() {
     echo "$1" | logger -t $LOG_TAG -s -p $LOG_LEVEL
 }
@@ -58,10 +64,8 @@ if [ "$PASSWD_ONLY" == '0' ]; then
 	echo "$pubkey" | grep -s -E '^[A-Za-z0-9+/=]+$' &> /dev/null || die "bad public key"
 fi
 
-homedir=/library/users/$username
-XO_USERS_GROUP=xousers
-RSSH_USERS_GROUP=rsshusers
-
+mkdir -p "$XO_USERS_DIR"
+homedir="$XO_USERS_DIR/$username"
 
 #make sure the xousers and rsshusers groups exist
 getent group $XO_USERS_GROUP > /dev/null 2>&1 || groupadd $XO_USERS_GROUP
@@ -72,7 +76,7 @@ if getent passwd "$username" > /dev/null 2>&1; then
     /usr/sbin/usermod -c "$full_name" "$username" || die "unable to change full name"
     NEW_USER=0
 else
-    /usr/sbin/useradd -c "$full_name" -d "$homedir"  \
+    /usr/sbin/useradd -c "$full_name" -m -d "$homedir"  \
         -G $XO_USERS_GROUP,$RSSH_USERS_GROUP -s /usr/bin/rssh "$username" \
         || die "Unable to create user"
     NEW_USER=1
@@ -95,11 +99,11 @@ clean_up_and_die(){
 
 
 userhome=`getent passwd "$username" | awk -F: '{print $6}'`
-cd $userhome || clean_up_and_die "Couldn't cd into user's home directory"
+cd "$userhome" || clean_up_and_die "Couldn't cd into user's home directory"
 
 mkdir -p --mode=700 .ssh || clean_up_and_die "Unable to mkdir .ssh"
 echo "ssh-dss $pubkey" >> .ssh/authorized_keys || clean_up_and_die "Unable to set up authorized_keys"
 chmod 600 .ssh/authorized_keys  || clean_up_and_die "Unable to chmod authorized_keys"
-chown -R $username .ssh || clean_up_and_die "Unable to chown .ssh"
+chown -R "$username" .ssh || clean_up_and_die "Unable to chown .ssh"
 
 #clean_up_and_die goodbye
-- 
1.5.6.5



More information about the Server-devel mailing list