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

Commit 384b969

Browse files
committed
Merge pull request #51 from edunham/macscript
Specialize osx-adduser script because we only use it to add one user
2 parents aece753 + 5b08656 commit 384b969

File tree

1 file changed

+11
-34
lines changed

1 file changed

+11
-34
lines changed

osx-adduser.sh

+11-34
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,27 @@
88
# It's pretty simple as it uses and strings together the (rustic and ancient) commands that OSX
99
# already uses to add users.
1010

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

13-
echo "Enter your desired user name: "
14-
read USERNAME
15-
16-
echo "Enter a full name for this user: "
17-
read FULLNAME
18-
19-
echo "Enter a password for this user: "
20-
read -s PASSWORD
21-
22-
# ====
23-
24-
# A list of (secondary) groups the user should belong to
25-
# This makes the difference between admin and non-admin users.
26-
27-
echo "Is this an administrative user? (y/n)"
28-
read GROUP_ADD
13+
# Fail early if insufficient permissions
14+
if [[ $UID -ne 0 ]]; then echo "Please run $0 as root." && exit 1; fi
2915

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

38-
# ====
22+
SECONDARY_GROUPS="admin _lpadmin _appserveradm _appserverusr" # for an admin user
3923

4024
# Create a UID that is not currently in use
41-
echo "Creating an unused UID for new user..."
42-
43-
if [[ $UID -ne 0 ]]; then echo "Please run $0 as root." && exit 1; fi
4425

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

49-
50-
# Create the user account by running dscl (normally you would have to do each of these commands one
51-
# by one in an obnoxious and time consuming way.
30+
# Create the user account by running dscl (normally you would have to do each
31+
# of these commands one by one in an obnoxious and time consuming way.
5232
echo "Creating necessary files..."
5333

5434
dscl . -create /Users/$USERNAME
@@ -59,16 +39,13 @@ dscl . -create /Users/$USERNAME PrimaryGroupID 20
5939
dscl . -create /Users/$USERNAME NFSHomeDirectory /Users/$USERNAME
6040
dscl . -passwd /Users/$USERNAME $PASSWORD
6141

62-
6342
# Add user to any specified groups
64-
echo "Adding user to specified groups..."
6543

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

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

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

0 commit comments

Comments
 (0)