Created
May 2, 2014 19:34
-
-
Save JDHatman/52239abf4ad8dc7f3615 to your computer and use it in GitHub Desktop.
mwa postflight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source "`dirname "${0}"`/munkiwebadmin-config" | |
REPORTSUBMITURL="${MWA_HOST}/update" | |
INVENTORYHASHURL="${MWA_HOST}/inventory/hash" | |
INVENTORYSUBMITURL="${MWA_HOST}/inventory/submit" | |
RUNTYPE="$1" | |
MAC=`ifconfig en0 | awk '$1=="ether" {print $2}'` | |
NAME=`/usr/sbin/scutil --get ComputerName` | |
REPORTPATH="/Library/Managed Installs/ManagedInstallReport.plist" | |
INVENTORYPATH="/Library/Managed Installs/ApplicationInventory.plist" | |
SHORTNAME=`ps aux 2> /dev/null | grep [l]oginwindow | cut -d " " -f1` | |
USERNAME=`dscacheutil -q user -a name ${SHORTNAME} | fgrep gecos | sed -e 's/.*gecos: \(.*\)/\1/'` | |
LOCATION=`defaults read /Library/Preferences/com.apple.RemoteDesktop Text3` | |
PLISTBUDDY="/usr/libexec/PlistBuddy" | |
# Copy the report to a temporary file. | |
TMPPLIST=/tmp/`head -c10 /dev/urandom | md5`.plist | |
cp "$REPORTPATH" "$TMPPLIST" | |
# Generate a system_profiler report. | |
PROFILEPLIST=/tmp/`head -c10 /dev/urandom | md5`.plist | |
/usr/sbin/system_profiler -xml SPNetworkDataType SPHardwareDataType > "$PROFILEPLIST" | |
# Merge system profiler report with munki report. | |
$PLISTBUDDY -c "Add :MachineInfo:SystemProfile array" "$TMPPLIST" | |
$PLISTBUDDY -c "Merge $PROFILEPLIST :MachineInfo:SystemProfile" "$TMPPLIST" | |
# Compress and encode report. | |
REPORTTMP=`mktemp -t postflight` | |
echo -n "base64bz2report=" > "$REPORTTMP" | |
bzip2 --best < "$TMPPLIST" | openssl base64 >> "$REPORTTMP" | |
# Submit Munki report to server. | |
mwa_curl --max-time 30 \ | |
-d runtype="$RUNTYPE" \ | |
-d mac="$MAC" \ | |
-d name=\""$NAME"\" \ | |
-d "@$REPORTTMP" \ | |
-d username=\""$USERNAME"\" \ | |
-d location=\""$LOCATION"\" \ | |
"$REPORTSUBMITURL/postflight" | |
if [ -e "$INVENTORYPATH" ] ; then | |
#INVENTORY_CHECKSUM=`cat /Library/Managed\ Installs/ApplicationInventory.plist | openssl dgst -sha256` | |
# Above doesn't work on Leopard. So let's call Python. | |
INVENTORY_CHECKSUM=`/usr/bin/python -c 'import hashlib; f = open("/Library/Managed Installs/ApplicationInventory.plist").read(); print hashlib.sha256(f).hexdigest()'` | |
STORED_CHECKSUM=`mwa_curl --max-time 30 "$INVENTORYHASHURL/$MAC"` | |
if [ "$INVENTORY_CHECKSUM" != "$STORED_CHECKSUM" ]; then | |
# inventory changed, sumbit to server | |
# Compress and encode inventory. | |
INVENTORYTMP=`mktemp -t inventory` | |
echo -n "base64bz2inventory=" > "$INVENTORYTMP" | |
bzip2 --best < "$INVENTORYPATH" | openssl base64 >> "$INVENTORYTMP" | |
# Submit inventory to server. | |
mwa_curl --max-time 30 \ | |
-d runtype="$RUNTYPE" \ | |
-d mac="$MAC" \ | |
-d hostname=\""$NAME"\" \ | |
-d username=\""$USERNAME"\" \ | |
-d location=\""$LOCATION"\" \ | |
-d "@$INVENTORYTMP" \ | |
"$INVENTORYSUBMITURL" | |
# clean up | |
rm -f "$INVENTORYTMP" | |
fi | |
fi | |
if [ -f /usr/local/munki/sal-submit ] | |
then | |
/usr/local/munki/sal-submit | |
fi | |
# Clean up and exit | |
rm -f "$REPORTTMP" "$TMPPLIST" "$PROFILEPLIST" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment