Skip to content
This repository has been archived by the owner on Nov 21, 2018. It is now read-only.

Commit

Permalink
Merge pull request #51 from edunham/macscript
Browse files Browse the repository at this point in the history
Specialize osx-adduser script because we only use it to add one user
  • Loading branch information
brson committed Jan 11, 2016
2 parents aece753 + 5b08656 commit 384b969
Showing 1 changed file with 11 additions and 34 deletions.
45 changes: 11 additions & 34 deletions osx-adduser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,27 @@
# It's pretty simple as it uses and strings together the (rustic and ancient) commands that OSX
# already uses to add users.

# === Typically, this is all the info you need to enter ===
# Customized to be less interactive for Rust Buildbot slaves as of Jan 2016

echo "Enter your desired user name: "
read USERNAME

echo "Enter a full name for this user: "
read FULLNAME

echo "Enter a password for this user: "
read -s PASSWORD

# ====

# A list of (secondary) groups the user should belong to
# This makes the difference between admin and non-admin users.

echo "Is this an administrative user? (y/n)"
read GROUP_ADD
# Fail early if insufficient permissions
if [[ $UID -ne 0 ]]; then echo "Please run $0 as root." && exit 1; fi

if [ "$GROUP_ADD" = n ] ; then
SECONDARY_GROUPS="staff" # for a non-admin user
elif [ "$GROUP_ADD" = y ] ; then
SECONDARY_GROUPS="admin _lpadmin _appserveradm _appserverusr" # for an admin user
else
echo "You did not make a valid selection!"
fi
USERNAME='rustbuild'
FULLNAME='Rust Buildbot'
# We already have admin credentials on the machine if we're running this
# script, and access the user by su-ing to it.
PASSWORD=$(openssl rand -base64 30)

# ====
SECONDARY_GROUPS="admin _lpadmin _appserveradm _appserverusr" # for an admin user

# Create a UID that is not currently in use
echo "Creating an unused UID for new user..."

if [[ $UID -ne 0 ]]; then echo "Please run $0 as root." && exit 1; fi

# Find out the next available user ID
MAXID=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1)
USERID=$((MAXID+1))


# Create the user account by running dscl (normally you would have to do each of these commands one
# by one in an obnoxious and time consuming way.
# Create the user account by running dscl (normally you would have to do each
# of these commands one by one in an obnoxious and time consuming way.
echo "Creating necessary files..."

dscl . -create /Users/$USERNAME
Expand All @@ -59,16 +39,13 @@ dscl . -create /Users/$USERNAME PrimaryGroupID 20
dscl . -create /Users/$USERNAME NFSHomeDirectory /Users/$USERNAME
dscl . -passwd /Users/$USERNAME $PASSWORD


# Add user to any specified groups
echo "Adding user to specified groups..."

for GROUP in $SECONDARY_GROUPS ; do
dseditgroup -o edit -t user -a $USERNAME $GROUP
done

# Create the home directory
echo "Creating home directory..."
createhomedir -c 2>&1 | grep -v "shell-init"

echo "Created user #$USERID: $USERNAME ($FULLNAME)"

0 comments on commit 384b969

Please sign in to comment.