Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Original concepts by Noel B. Alonso: https://gist.github.com/nbalonso/5696340
- # and Rich Trouton: https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/create_custom_guest_account
- # ---------------------------------------------------------
- # Set all Variables
- # ---------------------------------------------------------
- #----- Debugging
- #bash -x ./[script_name.sh] for detailed script output
- #bash -n ./[script_name.sh] for syntax checking
- set -u # verbose error checking during execution
- #----- Standards
- script="Create-Guest-Account"
- now=$(date +"%m-%d-%Y %H:%M:%S")
- #----- Executables
- mkdir=$(which mkdir)
- chown=$(which chown)
- chmod=$(which chmod)
- dscl=$(which dscl)
- security=$(which security)
- killall=$(which killall)
- #----- Computations
- OSVERS=$(sw_vers -productVersion | awk -F. '{print $2}')
- #----- Assignments
- USERNAME="Guest" ## Account short name
- DISPLAYNAME="Guest User" ## Account name displayed in System Preferences
- GUESTUID="600"
- GUESTGROUPID="600"
- #----- Set Logging
- Log="/Library/Logs/Nike"
- if [ ! -d "${Log}" ];
- then
- $mkdir $Log
- $chown root:wheel $Log
- $chmod 777 $Log
- fi
- exec >> "${Log}"/"${script}".log 2>&1
- #----------------------------------------------------------
- # Timestamp
- #----------------------------------------------------------
- echo ""
- echo "##### $script"
- echo "##### $now"
- #----------------------------------------------------------
- # Script
- #----------------------------------------------------------
- if [[ ${OSVERS} -ge 9 ]]; then
- ${dscl} . -create /Users/"${USERNAME}"
- ${dscl} . -create /Users/"${USERNAME}" dsAttrTypeNative:_defaultLanguage en
- ${dscl} . -create /Users/"${USERNAME}" dsAttrTypeNative:_guest true
- ${dscl} . -create /Users/"${USERNAME}" dsAttrTypeNative:_writers__defaultLanguage "${USERNAME}"
- ${dscl} . -create /Users/"${USERNAME}" dsAttrTypeNative:_writers_UserCertificate "${USERNAME}"
- ${dscl} . -create /Users/"${USERNAME}" AuthenticationHint ''
- ${dscl} . -create /Users/"${USERNAME}" NFSHomeDirectory /Users/"${USERNAME}"
- #setting up an empty password and giving local Kerberos some time to process it
- ${dscl} . -passwd /Users/"${USERNAME}" "${USERNAME}"
- sleep 2
- ${dscl} . -create /Users/"${USERNAME}" Picture "/Library/User Pictures/Nature/Leaf.tif"
- ${dscl} . -create /Users/"${USERNAME}" PrimaryGroupID "${GUESTGROUPID}"
- ${dscl} . -create /Users/"${USERNAME}" RealName "${DISPLAYNAME}"
- ${dscl} . -create /Users/"${USERNAME}" RecordName "${USERNAME}"
- ${dscl} . -create /Users/"${USERNAME}" UniqueID "${GUESTUID}"
- ${dscl} . -create /Users/"${USERNAME}" UserShell /bin/bash
- ${security} add-generic-password -a "${USERNAME}" -s com.apple.loginwindow.guest-account -A -w "${USERNAME}" -D "application password" /Library/Keychains/System.keychain
- # Restart loginwindow
- # ${killall} loginwindow
- else
- echo "Script requires an OS of OSX 10.9 or later to function."
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement