addsysuser 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. #
  3. # Original adduser 05 Feb 2002 by Jon L. Gardner
  4. #
  5. # Modified for Tor installer by Nick Mathewson
  6. # 2007-06-12 Modified for leopard by Andrew Lewman
  7. if [ "`whoami`" != "root" ]; then
  8. echo "You must be root to execute this script."
  9. exit
  10. fi
  11. if [ "x$3" = "x" ]; then
  12. echo 'Usage: addsysuser <username> "<full name>" <homedir>'
  13. exit 0
  14. fi
  15. username=$1
  16. realname=$2
  17. homedir=$3
  18. # GID 20 is "staff" which is the default. Change it if you want.
  19. #gid=`niutil -readprop $ROOTPROP /groups/daemon gid`
  20. gid=`dscl . -read /groups/daemon gid`
  21. echo $gid
  22. #if [ "x`niutil -list $ROOTPROP /users|cut -f2 -d' '|grep $username`" != "x" ]; then
  23. if [ "x`dscl . -list /users|cut -f2 -d' '|grep $username`" != "x" ]; then
  24. echo The account $username already exists.
  25. exit 0
  26. fi
  27. # home is the local path to the home directory
  28. home=/Users/$username
  29. # defhome is what goes into NetInfo
  30. defhome="/Network/Servers/MyServer/Users"
  31. #echo "Determining next available system uid (please be patient)..."
  32. # Uids over 500 are for system users.
  33. #uiddef=`nidump passwd / | cut -d: -f3 | sort -n | grep -v '^[56789]..' |grep -v '^....$' | tail -n 1`
  34. #uiddef=`echo $uiddef + 1 |bc`
  35. echo Creating account for $username...
  36. dscl . -create /users/$username
  37. dscl . -create /users/$username _writers_tim_passwd $username
  38. dscl . -create /users/$username realname $realname
  39. dscl . -create /users/$username _writers_passwd $username
  40. dscl . -create /users/$username gid $gid
  41. dscl . -create /users/$username home $homedir
  42. dscl . -create /users/$username name $username
  43. dscl . -create /users/$username passwd '*'
  44. dscl . -create /users/$username shell /dev/null