MacOSX: adduser

I really needed an adduser like program on MacOSX  and after a few searches on the internet I found a script that works like the linux adduser program.

I remember I had to modify it to use bash ( my preferred shell ) as the default shell and I make it use the right path when copying the user template. I can't remember exactly where I found it so if you have seen this someplace else feel free to let me know and I'll be happy to give credit.

Here it is :

  1.  
  2. #!/bin/sh
  3. echo "Enter username:"
  4. read newuser
  5. echo "Enter the full name for user $newuser's:"
  6. read long_name
  7. echo "Will $newuser an Admin user (y/N)?"
  8. read is_admin
  9. new_uid=`nidump passwd . | awk -F: '{print $3f}' | sort -n|tail -1`
  10. new_uid=`expr $new_uid + 1`
  11. nicl . -create /users/$newuser
  12. nicl . -create /users/$newuser uid $new_uid
  13. nicl . -create /users/$newuser realname "$long_name"
  14. nicl . -create /users/$newuser passwd ""
  15. nicl . -create /users/$newuser gid 20
  16. nicl . -create /users/$newuser shell "/bin/bash"
  17. nicl . -create /users/$newuser home "/Users/$newuser"
  18. nicl . -create /users/$newuser _writers_passwd $newuser
  19. passwd $newuser
  20. ditto /System/Library/User\ Template/English.lproj /Users/$newuser
  21. chown -R $newuser:staff /Users/$newuser
  22. nicl . -read /users/$newuser
  23. if [ "$is_admin" = Y -o "$is_admin" = y ]
  24. then
  25. nicl . -append /groups/wheel users $newuser
  26. nicl . -append /groups/admin users $newuser
  27. nicl . -read /groups/wheel
  28. nicl . -read /groups/admin
  29. fi

One thought on “MacOSX: adduser

Leave a Reply