Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USERNAME=it
- macOSLAPSDownloadURL="https://github.com/joshua-d-miller/macOSLAPS/releases/download/4.0.0(845)/macOSLAPS-Binary-4.0.0.845.pkg"
- installerchoices='<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
- <plist version="1.0">
- <array>
- <dict>
- <key>attributeSetting</key>
- <integer>1</integer>
- <key>choiceAttribute</key>
- <string>selected</string>
- <key>choiceIdentifier</key>
- <string>installer_choice_1</string>
- </dict>
- <dict>
- <key>attributeSetting</key>
- <integer>0</integer>
- <key>choiceAttribute</key>
- <string>selected</string>
- <key>choiceIdentifier</key>
- <string>installer_choice_2</string>
- </dict>
- </array>
- </plist>'
- function create_it_user () {
- FULLNAME="IT"
- #Initially just put the computers serial number as the password. This is just temporary!
- PASSWORD=$(system_profiler SPHardwareDataType | grep 'Serial Number (system)' | awk '{print $NF}')
- SECONDARY_GROUPS="staff"
- MAXID=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1)
- USERID=$((MAXID+1))
- # Create the user account
- dscl . -create /Users/$USERNAME
- dscl . -create /Users/$USERNAME UserShell /bin/bash
- dscl . -create /Users/$USERNAME RealName "$FULLNAME"
- dscl . -create /Users/$USERNAME UniqueID "$USERID"
- dscl . -create /Users/$USERNAME PrimaryGroupID 20
- dscl . -create /Users/$USERNAME NFSHomeDirectory /Users/$USERNAME
- dscl . -create /Users/$USERNAME IsHidden 1
- dscl . -passwd /Users/$USERNAME $PASSWORD
- dscl . -append /Groups/admin GroupMembership $USERNAME
- # Add user to any specified groups
- for GROUP in $SECONDARY_GROUPS ; do
- dseditgroup -o edit -t user -a $USERNAME $GROUP
- done
- defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array-add "$USERNAME"
- curl -L -o /tmp/macOSLAPS.pkg $macOSLAPSDownloadURL
- echo "$installerchoices" > /tmp/InstallerChoices.xml
- installer -applyChoiceChangesXML /tmp/InstallerChoices.xml -pkg /tmp/macOSLAPS.pkg -target /
- rm /tmp/macOSLAPS.pkg
- rm /tmp/InstallerChoices.xml
- file="/private/etc/paths.d/laps"
- if [ -f "$file" ] ; then
- rm "$file"
- fi
- # Call macOSLAPS to set password. This could be commented out and keep the serialnumber
- # as the password until it forces the change with the custom attribute instead
- /usr/local/laps/macOSLAPS
- # Create the home directory
- #createhomedir -c -u $USERNAME > /dev/null
- # Make user standard user instead of admin. Do not implement for now.
- #echo "Removing other users from admin group..."
- #adminUsers=$(dscl . -read Groups/admin GroupMembership | cut -c 18-)
- #for user in $adminUsers
- #do
- # if [ "$user" != "root" ] && [ "$user" != "it" ]
- # then
- # dseditgroup -o edit -d $user -t user admin
- # if [ $? = 0 ]; then echo "Removed user $user from admin group"; fi
- # else
- # echo "Admin user $user left alone"
- # fi
- #done
- }
- function downloadmacOSLAPS () {
- curl -L -o /tmp/macOSLAPS.pkg $macOSLAPSDownloadURL
- echo "$installerchoices" > /tmp/InstallerChoices.xml
- installer -applyChoiceChangesXML /tmp/InstallerChoices.xml -pkg /tmp/macOSLAPS.pkg -target /
- rm /tmp/macOSLAPS.pkg
- rm /tmp/InstallerChoices.xml
- file="/private/etc/paths.d/laps"
- if [ -f "$file" ] ; then
- rm "$file"
- fi
- }
- function letsGo () {
- if id -u "it" >/dev/null 2>&1; then
- downloadmacOSLAPS
- else
- create_it_user
- fi
- }
- letsGo
Advertisement
Add Comment
Please, Sign In to add comment