Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
check Rich's updated version of this at https://gist.github.com/rtrouton/8016797
#!/bin/bash
#variables
DSCL="/usr/bin/dscl"
SECURITY="/usr/bin/security"
LOGGER="/usr/bin/logger"
OSREL=`/usr/bin/uname -r | cut -f 1 -d '.'`;
case "${OSREL}" in
10)
#Mac OS X Snow Leopard
${LOGGER} -s -t createmyguest.sh "INFO: executing the 10.6 version of the script"
${DSCL} . -create /Users/myguest
${DSCL} . -create /Users/myguest UserShell /bin/bash
${DSCL} . -create /Users/myguest RealName "Guest Account"
${DSCL} . -create /Users/myguest UniqueID 201
${DSCL} . -create /Users/myguest PrimaryGroupID 201
${DSCL} . -create /Users/myguest NFSHomeDirectory /Users/Guest
${DSCL} . -create /Users/myguest RecordType dsRecTypeStandard:Users
${DSCL} . -create /Users/myguest dsAttrTypeNative:_defaultLanguage en
${DSCL} . -create /Users/myguest dsAttrTypeNative:_guest true
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers__defaultLanguage Guest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers_jpegphoto Guest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers_LinkedIdentity Guest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers_picture Guest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers_UserCertificate Guest
${DSCL} . -create /Users/myguest AppleMetaNodeLocation /Local/Default
#setting up an empty password and giving local Kerberos some time to process it
${DSCL} . -passwd /Users/myguest ''
sleep 2
;;
11)
#OS X Lion
${DSCL} . -create /Users/myguest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_defaultLanguage en
${DSCL} . -create /Users/myguest dsAttrTypeNative:_guest true
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers__defaultLanguage Guest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers_LinkedIdentity Guest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers_UserCertificate Guest
${DSCL} . -create /Users/myguest AuthenticationHint ''
${DSCL} . -create /Users/myguest NFSHomeDirectory /Users/Guest
#setting up an empty password and giving local Kerberos some time to process it
${DSCL} . -passwd /Users/myguest ''
sleep 2
${DSCL} . -create /Users/myguest Picture "/Library/User Pictures/Nature/Leaf.tif"
${DSCL} . -create /Users/myguest PrimaryGroupID 201
${DSCL} . -create /Users/myguest RealName "Local Guest"
${DSCL} . -create /Users/myguest RecordName myguest
#Lion does not like two users with same UUID so don't use 201 on the next line
${DSCL} . -create /Users/myguest UniqueID 401
${DSCL} . -create /Users/myguest UserShell /bin/bash
#Adding the keychain item that allows Guest to login in 10.7
${SECURITY} add-generic-password -a myguest -s com.apple.loginwindow.guest-account -D "application password" /Library/Keychains/System.keychain
;;
12)
#OS X Mountain Lion
${LOGGER} -s -t createmyguest.sh "INFO: executing the 10.8 version of the script"
${DSCL} . -create /Users/myguest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_defaultLanguage en
${DSCL} . -create /Users/myguest dsAttrTypeNative:_guest true
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers__defaultLanguage Guest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers_UserCertificate Guest
${DSCL} . -create /Users/myguest AuthenticationHint ''
${DSCL} . -create /Users/myguest NFSHomeDirectory /Users/Guest
#setting up an empty password and giving local Kerberos some time to process it
${DSCL} . -passwd /Users/myguest ''
sleep 2
${DSCL} . -create /Users/myguest Picture "/Library/User Pictures/Nature/Leaf.tif"
${DSCL} . -create /Users/myguest PrimaryGroupID 201
${DSCL} . -create /Users/myguest RealName "Local Guest"
${DSCL} . -create /Users/myguest RecordName myguest
#OS X does not like two users with same UUID so don't use 201 on the next line
${DSCL} . -create /Users/myguest UniqueID 401
${DSCL} . -create /Users/myguest UserShell /bin/bash
#Adding the keychain item that allows Guest to login in 10.8
${SECURITY} add-generic-password -a myguest -s com.apple.loginwindow.guest-account -D "application password" /Library/Keychains/System.keychain
;;
13)
#OS X Maveriks
${LOGGER} -s -t createmyguest.sh "INFO: executing the 10.9 version of the script"
${DSCL} . -create /Users/myguest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_defaultLanguage en
${DSCL} . -create /Users/myguest dsAttrTypeNative:_guest true
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers__defaultLanguage Guest
${DSCL} . -create /Users/myguest dsAttrTypeNative:_writers_UserCertificate Guest
${DSCL} . -create /Users/myguest AuthenticationHint ''
${DSCL} . -create /Users/myguest NFSHomeDirectory /Users/Guest
#setting up an empty password and giving local Kerberos some time to process it
${DSCL} . -passwd /Users/myguest ''
sleep 2
${DSCL} . -create /Users/myguest Picture "/Library/User Pictures/Nature/Leaf.tif"
${DSCL} . -create /Users/myguest PrimaryGroupID 201
${DSCL} . -create /Users/myguest RealName "Local Guest"
${DSCL} . -create /Users/myguest RecordName myguest
#OS X does not like two users with same UUID so don't use 201 on the next line
${DSCL} . -create /Users/myguest UniqueID 401
${DSCL} . -create /Users/myguest UserShell /bin/bash
#Adding the keychain item that allows Guest to login in 10.9
${SECURITY} add-generic-password -a myguest -s com.apple.loginwindow.guest-account -D "application password" /Library/Keychains/System.keychain
;;
*)
#Any other version
${LOGGER} -s -t createmyguest.sh "ERROR: Operating system version not supported by this script"
exit -1;;
esac
${LOGGER} -s -t createmyguest.sh "INFO: Exiting"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment