Created
November 9, 2012 21:56
-
-
Save itsecureadmin/4048528 to your computer and use it in GitHub Desktop.
osx-adduser.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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