addsysuser 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. ROOTPROP=/
  8. if [ "`whoami`" != "root" ]; then
  9. echo "You must be root to execute this script."
  10. exit
  11. fi
  12. if [ "x$3" = "x" ]; then
  13. echo 'Usage: addsysuser <username> "<full name>" <homedir>'
  14. exit 0
  15. fi
  16. username=$1
  17. realname=$2
  18. homedir=$3
  19. if [ -x /usr/bin/dscl ]; then
  20. # Determine the gid of the daemon group
  21. gid=`dscl . -read /groups/daemon gid`
  22. if [ "x`dscl . -list /users|cut -f2 -d' '|grep $username`" != "x" ]; then
  23. echo The account $username already exists.
  24. exit 0
  25. fi
  26. # home is the local path to the home directory
  27. home=/Users/$username
  28. echo Creating account for $username...
  29. dscl . -create /users/$username
  30. dscl . -create /users/$username _writers_tim_passwd $username
  31. dscl . -create /users/$username realname $realname
  32. dscl . -create /users/$username _writers_passwd $username
  33. dscl . -create /users/$username gid $gid
  34. dscl . -create /users/$username home $homedir
  35. dscl . -create /users/$username name $username
  36. dscl . -create /users/$username passwd '*'
  37. dscl . -create /users/$username shell /dev/null
  38. else
  39. # Determine the gid of the daemon group
  40. gid=`niutil -readprop $ROOTPROP /groups/daemon gid`
  41. if [ "x`niutil -list $ROOTPROP /users|cut -f2 -d' '|grep $username`" != "x" ]; then
  42. echo The account $username already exists.
  43. exit 0
  44. fi
  45. # home is the local path to the home directory
  46. home=/Users/$username
  47. # defhome is what goes into NetInfo
  48. defhome="/Network/Servers/MyServer/Users"
  49. #echo "Determining next available system uid (please be patient)..."
  50. # Uids over 500 are for system users.
  51. uiddef=`nidump passwd / | cut -d: -f3 | sort -n | grep -v '^[56789]..' |grep -v '^....$' | tail -n 1`
  52. uiddef=`echo $uiddef + 1 |bc`
  53. echo Creating account for $username...
  54. niutil -create $ROOTPROP /users/$username
  55. niutil -createprop $ROOTPROP /users/$username _writers_tim_passwd $username
  56. niutil -createprop $ROOTPROP /users/$username realname $realname
  57. niutil -createprop $ROOTPROP /users/$username _writers_passwd $username
  58. niutil -createprop $ROOTPROP /users/$username uid $uiddef
  59. #niutil -createprop $ROOTPROP /users/$username home_loc "<home_dir><url>afp://afp.server.com/Users/</url><path>$username</path></home_dir>"
  60. niutil -createprop $ROOTPROP /users/$username gid $gid
  61. niutil -createprop $ROOTPROP /users/$username home $homedir
  62. niutil -createprop $ROOTPROP /users/$username name $username
  63. niutil -createprop $ROOTPROP /users/$username passwd '*'
  64. niutil -createprop $ROOTPROP /users/$username shell /dev/null
  65. fi