in Bash

Bash :: Check PKG Receipt Exists

While scripting a configuration manifest for DEPNotify, it would skip to the next policy before the last had completed, and so would skip to the end and close the splash screen before the build was finished.

This defeats the purpose of having a screen stopping any interaction until the machine had completed so after a little interaction on the #DEPNotify slack channel on Macadmins, it was suggested to write a bom file as the last action of a policy but this would require every policy to have additional work to add this.

JAMF already writes an empty PKG or DMG to `/Library/Application Support/JAMF/Receipts/` upon completion so why not use this?

Below is the function I wrote:


# Check to see if package receipt exists. Time range is 1 mins
# if it does, it returns the full package name. If not, it waits until
fileExists() {
  # Package name passed with FUNC
  # Path to JAMF pkg receipts
  receiptPath="/Library/Application Support/JAMF/Receipts"
  # Time range for find: currently 30 mins
  range="$(date -v -30M)"
  # Find pkg receipts that match $1 less than 30 mins old
  results="$(find "${receiptPath}" -newermt "$range" | grep -i $package)"
  # Strip the path
  results="$(basename "$results")"

  # Loop until result exists; echo pkg name when it does
  while :; do
    [[ $results != "" ]] && echo $results && break
    sleep 1

Write a Comment