From 5b08656e462c446687af0af775ef0ed7753a9097 Mon Sep 17 00:00:00 2001 From: edunham Date: Sat, 9 Jan 2016 21:25:07 -0800 Subject: [PATCH] Specialize osx-adduser script because we only use it to add one user No need to ask people to think when setting up slaves; it introduces too much risk of inconsistency between hosts --- osx-adduser.sh | 45 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/osx-adduser.sh b/osx-adduser.sh index 57307e7..1b0c069 100644 --- a/osx-adduser.sh +++ b/osx-adduser.sh @@ -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 @@ -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)"