MacOSX: adduser


Thanks for visiting! If you're new here, you may want to subscribe to my RSS feed. This blog posts regular information about web development, unix/linux, How-tos and patches. Go ahead, subscribe to my feed! You can also receive updates via email, instant messenger, skype or tweeter.

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 :

 
#!/bin/sh
echo "Enter username:"
read newuser
echo "Enter the full name for user $newuser's:"
read long_name
echo "Will $newuser an Admin user (y/N)?"
read is_admin
new_uid=`nidump passwd . | awk -F: '{print $3f}' | sort -n|tail -1`
new_uid=`expr $new_uid + 1`
nicl . -create /users/$newuser
nicl . -create /users/$newuser uid $new_uid
nicl . -create /users/$newuser realname "$long_name"
nicl . -create /users/$newuser passwd ""
nicl . -create /users/$newuser gid 20
nicl . -create /users/$newuser shell "/bin/bash"
nicl . -create /users/$newuser home "/Users/$newuser"
nicl . -create /users/$newuser _writers_passwd $newuser
passwd $newuser
ditto /System/Library/User\ Template/English.lproj /Users/$newuser
chown -R $newuser:staff /Users/$newuser
nicl . -read /users/$newuser
if [ "$is_admin" = Y -o "$is_admin" = y ]
then
nicl . -append /groups/wheel users $newuser
nicl . -append /groups/admin users $newuser
nicl . -read /groups/wheel
nicl . -read /groups/admin
fi
  • Digg
  • Reddit
  • del.icio.us
  • Slashdot
  • Spurl
  • StumbleUpon
  • Furl
  • description
  • Netscape
  • NewsVine
  • Technorati
  • YahooMyWeb
  • Simpy
If you enjoyed this post, you should subscribe to my full RSS Feeds

close Reblog this comment
blog comments powered by Disqus

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License

Technology Blogs - Blog Top Sites Search For Blogs, Submit Blogs, The Ultimate Blog Directory Blogarama - The Blog Directory 5starsblog Computers Blogs - Blog Flare blog search directory gob BlogHop