Posted on 11-03-2016 06:09 AM
We have a bash login script which does a bunch of housekeeping each time a user logs in to ensure they get connected to their network storage area etcetera, but one thing we're finding is that as well as doing the things it's supposed to do, it also randomly loads a blank Safari window.
Can anyone suggest either a) how we can find out why it is doing this or b) how to stop it doing this?
The script is as follows:
#!/bin/bash
# Get logged in user, the official Apple-approved way
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
echo "Logged in user is $loggedInUser"
# Stack jamfHelper windows up to start with, kill processes when you want to change message
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Long Road Mac Login" -description "Login complete, you may now start using the Mac." &
PID_LOGINCOMPLETE=$!
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Long Road Mac Login" -description "Loading PaperCut client..." &
PID_PAPERCUT=$!
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Long Road Mac Login" -description "Resetting wallpaper..." &
PID_WALLPAPER=$!
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Long Road Mac Login" -description "Restarting Dock..." &
PID_DOCK_RESTART=$!
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Long Road Mac Login" -description "Configuring Dock icons..." &
PID_DOCK_CONFIG=$!
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Long Road Mac Login" -description "Mounting user's home directory at /Users/$loggedInUser/Documents..." &
PID_MOUNT=$!
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Long Road Mac Login" -description "Looking up user's home directory..." &
PID_LOOKUP=$!
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Long Road Mac Login" -description "This Mac is not bound to Active Directory." &
PID_NOAD=$!
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Long Road Mac Login" -description "Checking if Mac is bound to Active Directory..." &
PID_CHECKAD=$!
sleep 1
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType fs -heading "Long Road Mac Login" -description "Preparing login, please wait..." &
PID_PREPARING=$!
sleep 1
kill $PID_PREPARING
wait $PID_PREPARING 2> /dev/null
checkAD=`/usr/bin/dscl localhost -list . | grep "Active Directory"`
if [ "${checkAD}" != "Active Directory" ]
then
# Mac is not bound to Active Directory
kill $PID_CHECKAD
wait $PID_CHECKAD 2> /dev/null
echo "Not bound to Active Directory"
sleep 1
killall jamfHelper
exit 2
fi
kill $PID_NOAD
wait $PID_NOAD 2> /dev/null
kill $PID_CHECKAD
wait $PID_CHECKAD 2> /dev/null
ADAccount="true"
isStudent="false"
smbHomeRaw=`/usr/bin/dscl localhost -read "/Active Directory/COLLEGE/All Domains/Users/$loggedInUser" SMBHome 2>&1`
if [ $? != 0 ]
then
# Not an Active Directory account
ADAccount="false"
if [ "$loggedInUser" == "student" ]
then
isStudent="true"
fi
if [ "$loggedInUser" == "yellow" ]
then
isStudent="true"
fi
if [ "$loggedInUser" == "blue" ]
then
isStudent="true"
fi
fi
if [ "$ADAccount" == "true" ]
then
# Active Directory account
studentGroups=`id $loggedInUser | grep "All Students Security|Examinees"`
if [ "$studentGroups" != "" ]
then
isStudent="true"
fi
# Munge SMB Home into correct format
smbHome="smb:"
smbHome+=`echo $smbHomeRaw | awk '{ print $2 }' | sed 's.\\./.g'`
kill $PID_LOOKUP
wait $PID_LOOKUP 2> /dev/null
echo "smbHome is $smbHome"
sudo -u $loggedInUser /sbin/mount -t smbfs "$smbHome" "/Users/$loggedInUser/Documents"
fi
if [ `pgrep jamfHelper | grep $PID_LOOKUP` ]
then
kill $PID_LOOKUP
wait $PID_LOOKUP 2> /dev/null
fi
if [ "$isStudent" == "true" ]
then
# do stuff if the account is a student
# dock icons
# wallpaper
MAC_MAJOR_VERSION=`sw_vers -productVersion | awk -F '.' '{print $1 "." $2}'`
echo "Checking OS version for dockutil: $MAC_MAJOR_VERSION"
if [ "$MAC_MAJOR_VERSION" == "10.8" ]
then
echo "dockutil 1.1.4"
dockUtilPath="/Library/Scripts/dockutil.1.1.4.py"
else
echo "dockutil 2.0.4"
dockUtilPath="/Library/Scripts/dockutil.2.0.4.py"
fi
userPath="/Users/$loggedInUser"
duNoRestart="--no-restart"
duAdd="--add"
duSectionApps="--section apps"
duSectionOthers="--section others"
kill $PID_MOUNT
wait $PID_MOUNT 2> /dev/null
echo "Removing all Dock icons"
$dockUtilPath $duNoRestart --remove all $userPath
sleep 1
echo "Adding new Dock icons"
case "$loggedInUser" in
"blue"|"yellow")
$dockUtilPath $duNoRestart $duAdd "/Applications/Google Chrome.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Keynote.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Adobe Photoshop CC 2015/Adobe Photoshop CC 2015.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Adobe Premiere Pro CC 2015/Adobe Premiere Pro CC 2015.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Adobe Lightroom/Adobe Lightroom.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Adobe Audition CC 2015/Adobe Audition CC 2015.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/GarageBand.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Microsoft Office 2011/Microsoft Word.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/TextEdit.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Photos.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Font Book.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Image Capture.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Self Service.app" $duSectionApps $userPath
;;
*)
$dockUtilPath $duNoRestart $duAdd "/Applications/Google Chrome.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/VLC.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Image Capture.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Adobe Bridge CC/Adobe Bridge CC.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Adobe Illustrator CC 2015/Adobe Illustrator.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Adobe Photoshop CC 2015/Adobe Photoshop CC 2015.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Adobe After Effects CC 2015/Adobe After Effects CC 2015.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Adobe Premiere Pro CC 2015/Adobe Premiere Pro CC 2015.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Adobe InDesign CC 2015/Adobe InDesign CC 2015.app" $duSectionApps $userPath
if [ -d "/Applications/Autodesk/AutoCAD 2015" ]
then
$dockUtilPath $duNoRestart $duAdd "/Applications/Autodesk/AutoCAD 2015/AutoCad 2015.app" $duSectionApps $userPath
fi
$dockUtilPath $duNoRestart $duAdd "/Applications/Autodesk/maya2016/Maya.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Autodesk/Mudbox2016/Mudbox.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Microsoft Office 2011/Microsoft Word.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Microsoft Office 2011/Microsoft Excel.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/Microsoft Office 2011/Microsoft PowerPoint.app" $duSectionApps $userPath
$dockUtilPath $duNoRestart $duAdd "/Applications/PCClient.app" $duSectionApps $userPath
;;
esac
kill $PID_DOCK_CONFIG
wait $PID_DOCK_CONFIG 2> /dev/null
echo "Adding Documents folder and restarting Dock"
$dockUtilPath $duAdd "$userPath/Documents" --label $loggedInUser $duSectionOthers $userPath
kill $PID_DOCK_RESTART
wait $PID_DOCK_RESTART 2> /dev/null
echo "Resetting wallpaper"
case "$loggedInUser" in
yellow) osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/L2 YELLOW DESKTOP IMAGE.png"'
echo "Reset wallpaper to yellow"
;;
blue) osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/L2 BLUE DESKTOP IMAGE.png"'
echo "Reset wallpaper to blue"
;;
*) osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Library/Desktop Pictures/lrsfc_lrcstudents_wallpaper_mac.jpg"'
echo "Reset wallpaper to standard"
;;
esac
fi
kill $PID_WALLPAPER
wait $PID_WALLPAPER 2> /dev/null
if [ `pgrep jamfHelper | grep $PID_MOUNT` ]
then
kill $PID_MOUNT
wait $PID_MOUNT 2> /dev/null
fi
if [ `pgrep jamfHelper | grep $PID_DOCK_CONFIG` ]
then
kill $PID_DOCK_CONFIG
wait $PID_DOCK_CONFIG 2> /dev/null
fi
if [ `pgrep jamfHelper | grep $PID_DOCK_RESTART` ]
then
kill $PID_DOCK_RESTART
wait $PID_DOCK_RESTART 2> /dev/null
fi
if [ -d "/Applications/PCClient.app" ]
then
echo "Loading PaperCut client..."
sudo -u $loggedInUser -b /Applications/PCClient.app/Contents/MacOS/JavaAppLauncher
fi
kill $PID_PAPERCUT
wait $PID_PAPERCUT 2> /dev/null
sleep 1
kill $PID_LOGINCOMPLETE
wait $PID_LOGINCOMPLETE 2> /dev/null
killall jamfHelper
exit 0
(also, if anyone knows of a better way to handle the messaging I'd be interested. The reason I stack up all the messages at the start in reverse order is that killing one to uncover the next one reduces the screen-flashing effect that you would get if you just start one, kill it then start another one, and also ensures that the user can't start using the Mac until the login script is finished working)
Posted on 11-03-2016 03:01 PM
If you start the new window before you kill the previous one you shouldn't get the flashing effect.
The other feature that is quite nice is the -timeout option.
Another way of doing messages that I use is with a loop that reads a log file and displays the last message. Then any time you want to change the message you just echo to the end of the log file, in this instance I am using the JAMF ImagingScripts.log file, but you could use anything. I generally have it running as a script called from a LaunchAgent or LaunchDaemon that disables itself before launching the loop so that it disappears after a restart, this allows you to be doing anything you like as part of a another script and then just firing dialogue information to the agent when you want to change the message.
Basically it opens a new windows over the old one and the background one expires silenty behind it a second later.
while :
do
Status_Mark=$(date +"%H:%M:%S")
Status_Message=$(tail -n1 /Library/Logs/JAMF/ImagingScripts.log)
/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -title "Please do not use or power off" -heading "STATUS ${Status_Mark}" -description "${Status_Message}" -lockHUD -timeout 10 -windowType utility -windowPosition ll &
sleep 9
done
Sorry no idea on the Safari launch, although maybe the Papercut installer at the end as you can't see from here what that is trying to do and it might be trying to open a registration page or something?
Posted on 11-04-2016 01:07 AM
I've just checked actually and the login script may not be responsible for the Safari issue; once I quit Safari and log out, it doesn't seem to happen again on subsequent logins. There's nothing in the Login Items so I wonder if it could be something in the default user profile template? Any idea how I would check that?
Also on a somewhat related note, is there a way, either in a script or in the default user profile template, to make Chrome the default web browser?