Refactor app_usage_monitor into user-level agent and privileged daemon.

This commit is contained in:
Greg Neagle
2018-04-07 19:10:16 -07:00
parent 37c0e79822
commit 62dd7700fd
8 changed files with 479 additions and 28 deletions

View File

@@ -1,9 +1,24 @@
#!/bin/sh
#!/bin/bash
# only do this if we are installing to current startup volume
# Lovingly lifted from Per Olofsson
# https://github.com/MagerValp/Scripted-Mac-Package-Creation/blob/master/scripts/postinstall
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# Execute postinstall actions if we're installing on a live system.
# This is useful for loading launch daemons and agents.
if [ "$3" == "/" ]; then
#(re-)load our LaunchDaemon
/bin/launchctl unload /Library/LaunchDaemons/com.googlecode.munki.app_usage_monitor.plist
/bin/launchctl load /Library/LaunchDaemons/com.googlecode.munki.app_usage_monitor.plist
# Run postinstall actions for root.
launchctl load /Library/LaunchDaemons/com.googlecode.munki.appusaged.plist
# Run postinstall actions for all logged in users.
for pid_uid in $(ps -axo pid,uid,args | grep -i "[l]oginwindow.app" | awk '{print $1 "," $2}'); do
pid=$(echo $pid_uid | cut -d, -f1)
uid=$(echo $pid_uid | cut -d, -f2)
launchctl bsexec "$pid" chroot -u "$uid" / launchctl load /Library/LaunchAgents/com.googlecode.munki.app_usage_monitor.plist
done
fi
exit 0