8
8
# It's pretty simple as it uses and strings together the (rustic and ancient) commands that OSX
9
9
# already uses to add users.
10
10
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
12
12
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
29
15
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)
37
21
38
- # ====
22
+ SECONDARY_GROUPS= " admin _lpadmin _appserveradm _appserverusr " # for an admin user
39
23
40
24
# 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
44
25
45
26
# Find out the next available user ID
46
27
MAXID=$( dscl . -list /Users UniqueID | awk ' {print $2}' | sort -ug | tail -1)
47
28
USERID=$(( MAXID+ 1 ))
48
29
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.
52
32
echo " Creating necessary files..."
53
33
54
34
dscl . -create /Users/$USERNAME
@@ -59,16 +39,13 @@ dscl . -create /Users/$USERNAME PrimaryGroupID 20
59
39
dscl . -create /Users/$USERNAME NFSHomeDirectory /Users/$USERNAME
60
40
dscl . -passwd /Users/$USERNAME $PASSWORD
61
41
62
-
63
42
# Add user to any specified groups
64
- echo " Adding user to specified groups..."
65
43
66
44
for GROUP in $SECONDARY_GROUPS ; do
67
45
dseditgroup -o edit -t user -a $USERNAME $GROUP
68
46
done
69
47
70
48
# Create the home directory
71
- echo " Creating home directory..."
72
49
createhomedir -c 2>&1 | grep -v " shell-init"
73
50
74
51
echo " Created user #$USERID : $USERNAME ($FULLNAME )"
0 commit comments