]> arthur.barton.de Git - usertools.macosx.git/blobdiff - useradd.macosx.sh
Support Mac OS X 10.6 as well as 10.5.
[usertools.macosx.git] / useradd.macosx.sh
index 518aef341413a2cedd7ec7ca53567645bc6e8733..653a63b539557cb6ded0944db47151d5117ce929 100755 (executable)
@@ -1,16 +1,14 @@
 #!/bin/bash
 #
 # useradd.macosx
-# Copyright (c)2008 Barton IT-Consulting, Alexander Barton
+# Copyright (c)2008,2009 Barton IT-Consulting, Alexander Barton
 #
-# 2008-07-28, alex@barton-it.de - R2
-#  - start directory services when not running (e. g. single user mode)
-# 2008-07-28, alex@barton-it.de - R1
-#  - initial version.
+# This is free software; see the source for copying conditions. There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 #
 
 NAME=`basename $0`
-RELEASE="2"
+RELEASE="3"
 
 Abort() {
        [ $# -lt 1 ] \
@@ -20,7 +18,7 @@ Abort() {
 }
 Usage() {
        echo "$NAME (useradd.macosx.sh) release $RELEASE"
-       echo "Copyright (c)2008 Barton IT-Consulting, Alexander Barton (alex@barton-it.de)"
+       echo "Copyright (c)2008,2009 Barton IT-Consulting, Alex Barton (alex@barton-it.de)"
        echo
        echo "This is free software; see the source for copying conditions. There is NO"
        echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -45,8 +43,8 @@ sw_vers -productName 2>/dev/null | grep "Mac OS X" >/dev/null 2>&1
 [ $? -eq 0 ] || Abort "This script requires Mac OS X!"
 epoch=`sw_vers -productVersion | cut -d'.' -f1`
 major=`sw_vers -productVersion | cut -d'.' -f2`
-if [ $epoch -ne 10 -o $major -ne 5 ]; then
-       Abort "This script requires Mac OS X 10.5.x Leopard!"
+if [ $epoch -ne 10 -o $major -lt 5 -o $major -gt 6 ]; then
+       Abort "This script requires Mac OS X 10.5.x or 10.6.x!"
 fi
 
 # Defaults
@@ -111,6 +109,8 @@ done
 [ -n "$home_dir" ] || home_dir="/Users/$user_name"
 [ -n "$shell" ] || shell="/bin/bash"
 
+[ "$UID" -eq 0 ] || Abort "This script must be run as root!"
+
 # Check that directory services are running
 launchctl list 2>/dev/null | fgrep "com.apple.DirectoryServices" >/dev/null 2>&1
 if [ $? -ne 0 ]; then
@@ -126,13 +126,8 @@ fi
 # No user ID given, generate it
 if [ $user_id -lt 0 ]; then
        # search next free user ID
-       declare -i new_id=501
-       id "$new_id" >/dev/null 2>&1
-       while [ $? -eq 0 ]; do
-               new_id=$new_id+1;
-               id "$new_id" >/dev/null 2>&1
-       done
-       user_id=$new_id
+       user_id=`echo $[$(dscl . -list /Users uid | awk '{print $2}' \
+               | sort -n | tail -n1)+1]`
 fi
 
 # Validate user name, user id and group id
@@ -168,7 +163,7 @@ dscl . -create /Users/"$user_name" PrimaryGroupID "$group_id" || Abort
 dscl . -create /Users/"$user_name" NFSHomeDirectory "$home_dir" || Abort
 dscl . -create /Users/"$user_name" UserShell "$shell" || Abort
 dscl . -create /Users/"$user_name" RealName "$real_name" || Abort
-dscl . -passwd /Users/"$user_name" "maccc" || Abort
+#dscl . -passwd /Users/"$user_name" "maccc" || Abort
 if [ "$become_admin" -ne 0 ]; then
        [ "$verbose" -ne 0 ] && echo "Adding user to 'admin' group ..."
        dscl . -append /Groups/admin GroupMembership "$user_name" || Abort
@@ -184,4 +179,4 @@ chmod 755 "$home_dir" || Abort
 echo "User '$user_name' ($user_id) has been created."
 exit 0
 
-# -eof-
\ No newline at end of file
+# -eof-