addsysuser 1.7 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. ROOTPROP=/
  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. if [ "x`niutil -list $ROOTPROP /users|cut -f2 -d' '|grep $username`" != "x" ]; then
  21. echo The account $username already exists.
  22. exit 0
  23. fi
  24. # home is the local path to the home directory
  25. home=/Users/$username
  26. # defhome is what goes into NetInfo
  27. defhome="/Network/Servers/MyServer/Users"
  28. #echo "Determining next available system uid (please be patient)..."
  29. # Uids over 500 are for system users.
  30. uiddef=`nidump passwd / | cut -d: -f3 | sort -n | grep -v '^[56789]..' |grep -v '^....$' | tail -n 1`
  31. uiddef=`echo $uiddef + 1 |bc`
  32. echo Creating account for $username...
  33. niutil -create $ROOTPROP /users/$username
  34. niutil -createprop $ROOTPROP /users/$username _writers_tim_passwd $username
  35. niutil -createprop $ROOTPROP /users/$username realname $realname
  36. niutil -createprop $ROOTPROP /users/$username _writers_passwd $username
  37. niutil -createprop $ROOTPROP /users/$username uid $uiddef
  38. #niutil -createprop $ROOTPROP /users/$username home_loc "<home_dir><url>afp://afp.server.com/Users/</url><path>$username</path></home_dir>"
  39. niutil -createprop $ROOTPROP /users/$username gid $gid
  40. niutil -createprop $ROOTPROP /users/$username home $homedir
  41. niutil -createprop $ROOTPROP /users/$username name $username
  42. niutil -createprop $ROOTPROP /users/$username passwd '*'
  43. niutil -createprop $ROOTPROP /users/$username shell /dev/null