Macos12.3 - NoMad python 2 deprecation and unable to use launchtl

tegus232
Contributor

Hi,

 

Can someone look at the script below and help provide an update so we can get this to work with 12.3 OS? python3 command asks for xcode install which we don't want to perform on here. Would be super helpful. We use it to push installs and updates of the app as well. we have our own icon dropper as pkg file as well

 

#!/bin/bash

log() {
echo "$1"
/usr/bin/logger -t "NoMAD Installer:" "$1"
}
log "Installing NoMAD.app"

tempDir=$(/usr/bin/mktemp -d -t "NoMAD_Installer")

cleanUp() {
log "Performing cleanup tasks..."
/bin/rm -r "$tempDir"
}

trap cleanUp exit

loggedInUserPid=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; username = SCDynamicStoreCopyConsoleUser(None, None, None)[1]; print(username);')

launchctlCmd=$(python -c 'import platform; from distutils.version import StrictVersion as SV; print("asuser") if SV(platform.mac_ver()[0]) >= SV("10.10") else "bsexec"')

packageDownloadUrl="https://files.nomad.menu/NoMAD.pkg"

log "Downloading NoMAD.pkg..."
/usr/bin/curl -s $packageDownloadUrl -o "$tempDir/NoMAD.pkg"
if [ $? -ne 0 ]; then
log "curl error: The package did not successfully download"; exit 1
fi

pkgSignatureCheck=$(/usr/sbin/pkgutil --check-signature "$tempDir/NoMAD.pkg")
if [ $? -ne 0 ]; then
log "pkgutil error: The downloaded package did not pass the signature check"; exit 1
fi

log "Installing NoMAD.app..."
/usr/sbin/installer -pkg "$tempDir/NoMAD.pkg" -target /
if [ $? -ne 0 ]; then
log "installer error: The package did not successfully install"; exit 1
fi

log "Writing LaunchAgent..."
read -d '' launchAgent <<"EOF"
<?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">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.trusourcelabs.NoMAD</string>
<key>LimitLoadToSessionType</key>
<array>
<string>Aqua</string>
</array>
<key>ProgramArguments</key>
<array>
<string>/Applications/NoMAD.app/Contents/MacOS/NoMAD</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF
echo "$launchAgent" > /Library/LaunchAgents/com.trusourcelabs.NoMAD.plist

/usr/sbin/chown root:wheel /Library/LaunchAgents/com.trusourcelabs.NoMAD.plist
/bin/chmod 644 /Library/LaunchAgents/com.trusourcelabs.NoMAD.plist

log "Loading LaunchAgent..."
/bin/launchctl "$launchctlCmd" "$loggedInUserPid" /bin/launchctl load /Library/LaunchAgents/com.trusourcelabs.NoMAD.plist
if [ $? -ne 0 ]; then
log "launchctl error: The LaunchAgent failed to load"; exit 1
fi

log "NoMAD.app install complete"
exit 0

 

 

2 REPLIES 2

mm2270
Legendary Contributor III

sdagley
Esteemed Contributor II

@tegus232 Neither of those calls to python is necessary. You can replace the line that get the loggedInUserPid with:

 

currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
loggedInUserPid=$(id -u "$currentUser")

 

And unless you need to support versions of macOS back to 10.10, which Jamf Pro  doesn't even support these days, replace the call to set launchctlCmd with:

 

launchctlCmd="asuser"

 

 (There's actually other more cleanup that could be done, but those 2 changes will eliminate the python usage in your script)