addsysuser 3.2 KB

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