Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
osx-adduser.sh
#!/bin/bash
#
# Author: Josh Miller
# Date: 11/06/2012
#
# ensure username was entered
user=$1
if [ -z ${user} ]
then
echo "please enter a username"
exit 1;
fi
# get a list of users - not used yet
user_list=$(dscl . -list /Users)
# get the highest UniqueID so far
next_available_uniqueid=0
for i in $(ls /Users)
do
uniqueid=$(dscl . -read /Users/${i} UniqueID | awk '{print $2}')
if [ ${uniqueid} -gt ${next_available_uniqueid} ]
then
next_available_uniqueid=${uniqueid}
fi
done
let next_available_uniqueid=${next_available_uniqueid}+1
# get staff groupid
staff_groupid=$(dscl . -read /Groups/staff PrimaryGroupID | awk '{print $2}')
dscl . -create /Users/${user}
# Create and set the shell property to bash.
dscl . -create /Users/${user} UserShell /bin/bash
# Create and set the user’s ID.
dscl . -create /Users/${user} UniqueID ${next_available_uniqueid}
# Create and set the user’s group ID property.
dscl . -create /Users/${user} PrimaryGroupID 20
# Create and set the user home directory.
dscl . -create /Users/${user} NFSHomeDirectory /Users/${user}
cp -a "/System/Library/User Template/English.lproj" /Users/${user}
chown -R ${user} /Users/${user}
# Set the password - need to incorporate apg into this and email notification ?
dscl . -passwd /Users/${user} vit0ojAkdawWyek-${user}
# add to the admin / staff groups
dscl . -append /Groups/admin GroupMembership ${user}
dscl . -append /Groups/staff GroupMembership ${user}
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment