I got a request to simplify the process of addition of mobile accounts to macs from our local techs. Their primary complaint was that the script we used currently to create mobile accounts from AD creadentials was terminal based and hence confusing. Our local network is waay too slow for network users to just login, hence the necessity of adding mobile accounts. I created a bash script with interactive dialogs which would run as a policy in JAMF Self Service. All the tech would need to do is run the policy and enter the AD username for which the mac was to be configured.
As usual free to use as long as i'm credited.
#!/bin/sh
#createmobileuser.sh interactive app to create mobile accounts by checking AD.
#created by tausif
checkAD=`/usr/bin/dscl localhost -list . | grep "Active Directory"`
if [ "${checkAD}" != "Active Directory" ]; then
osascript -e 'tell application "System Events" to display dialog "A This machine is not bound to Active Directory" & "\nExiting" with title "Not on CORP Domain" buttons {"OK"} default button 1 giving up after 300 with icon 0'
exit 1
else
activeDirectoryPrompt=$(/usr/bin/osascript << EOF
tell application "System Events" to display dialog "Please the user's Active Directory login ID:" default answer "CORP ID..." with title "Mobile account created" buttons {"Continue"} default button "Continue" giving up after 300 with icon note
set activeDirectoryPrompt to the text returned of result
EOF)
FirstName="`/usr/bin/dscl /Search -read /Users/$activeDirectoryPrompt FirstName | awk '{ print $2 }'`"
LastName="`/usr/bin/dscl /Search -read /Users/$activeDirectoryPrompt LastName | awk '{ print $2 }'`"
RealName="$FirstName $LastName"
confirm=$(osascript -e 'tell application "System Events" to display dialog " Is the user named: '$FirstName' '$LastName' ?" with title "Please Click Yes or no" buttons {"Yes", "No"} default button "Yes" giving up after 300 with icon path to resource "AccountsPref.icns" in bundle "/System/Library/PreferencePanes/Accounts.prefPane/Contents/Resources"')
if [[ $confirm =~ Yes ]];
then
#create mobile account and log all messages, this is necessary as the command spews some weird messages.
/System/Library/CoreServices/ManagedClient.app/Contents/Resources/createmobileaccount -v -n $activeDirectoryPrompt &>/private/var/log/mobacc.log
dscl . -append /Groups/admin GroupMembership $activeDirectoryPrompt
osascript -e 'tell application "System Events" to display dialog "Account created." with title "Account created." buttons {"Ok"} default button "Ok" giving up after 300 with icon path to resource "AccountsPref.icns" in bundle "/System/Library/PreferencePanes/Accounts.prefPane/Contents/Resources"'
exit 0
else
osascript -e 'tell application "System Events" to display dialog "Incorrect username. Account creation has ended." with title "Incorrect Username" buttons {"Ok"} default button "Ok" giving up after 300 with icon path to resource "AccountsPref.icns" in bundle "/System/Library/PreferencePanes/Accounts.prefPane/Contents/Resources"'
fi
fi
exit 0
As usual free to use as long as i'm credited.
#!/bin/sh
#createmobileuser.sh interactive app to create mobile accounts by checking AD.
#created by tausif
checkAD=`/usr/bin/dscl localhost -list . | grep "Active Directory"`
if [ "${checkAD}" != "Active Directory" ]; then
osascript -e 'tell application "System Events" to display dialog "A This machine is not bound to Active Directory" & "\nExiting" with title "Not on CORP Domain" buttons {"OK"} default button 1 giving up after 300 with icon 0'
exit 1
else
activeDirectoryPrompt=$(/usr/bin/osascript << EOF
tell application "System Events" to display dialog "Please the user's Active Directory login ID:" default answer "CORP ID..." with title "Mobile account created" buttons {"Continue"} default button "Continue" giving up after 300 with icon note
set activeDirectoryPrompt to the text returned of result
EOF)
FirstName="`/usr/bin/dscl /Search -read /Users/$activeDirectoryPrompt FirstName | awk '{ print $2 }'`"
LastName="`/usr/bin/dscl /Search -read /Users/$activeDirectoryPrompt LastName | awk '{ print $2 }'`"
RealName="$FirstName $LastName"
confirm=$(osascript -e 'tell application "System Events" to display dialog " Is the user named: '$FirstName' '$LastName' ?" with title "Please Click Yes or no" buttons {"Yes", "No"} default button "Yes" giving up after 300 with icon path to resource "AccountsPref.icns" in bundle "/System/Library/PreferencePanes/Accounts.prefPane/Contents/Resources"')
if [[ $confirm =~ Yes ]];
then
#create mobile account and log all messages, this is necessary as the command spews some weird messages.
/System/Library/CoreServices/ManagedClient.app/Contents/Resources/createmobileaccount -v -n $activeDirectoryPrompt &>/private/var/log/mobacc.log
dscl . -append /Groups/admin GroupMembership $activeDirectoryPrompt
osascript -e 'tell application "System Events" to display dialog "Account created." with title "Account created." buttons {"Ok"} default button "Ok" giving up after 300 with icon path to resource "AccountsPref.icns" in bundle "/System/Library/PreferencePanes/Accounts.prefPane/Contents/Resources"'
exit 0
else
osascript -e 'tell application "System Events" to display dialog "Incorrect username. Account creation has ended." with title "Incorrect Username" buttons {"Ok"} default button "Ok" giving up after 300 with icon path to resource "AccountsPref.icns" in bundle "/System/Library/PreferencePanes/Accounts.prefPane/Contents/Resources"'
fi
fi
exit 0
No comments:
Post a Comment