Skip to content

Instantly share code, notes, and snippets.

@calum-github
Last active February 17, 2016 02:09
Show Gist options
  • Select an option

  • Save calum-github/3bd5a0a26b76a0113c5b to your computer and use it in GitHub Desktop.

Select an option

Save calum-github/3bd5a0a26b76a0113c5b to your computer and use it in GitHub Desktop.
Remove old autopkg receipts plist
#!/bin/bash
##########################################################
# Date: 17-02-2016 #
# Author: Calum Hunter #
# Version: 0.1 #
# Purpose: Remove receipt plists from autopkg cache #
# after $x days #
##########################################################
# Get a list of directories in the cache folder and store them in an array
shopt -s nullglob
AUTOPKG_RECIPE_DIRS=(~/Library/AutoPkg/Cache/*)
# Number of days to wait before removing a receipt plist
DAYS="7"
for RECIPE in "${AUTOPKG_RECIPE_DIRS[@]}"; do
if [ -d "$RECIPE" ]; then
echo ""
echo "- Found cache folder for recipe: $RECIPE"
echo " - Locating receipts that are older than $DAYS days"
NUM_RECEIPTS=$(find "${RECIPE}"/receipts/ -type f -mtime +"$DAYS" -print | wc -l)
echo " - Found $NUM_RECEIPTS files that need to be removed"
echo " - Removing receipts...."
find "${RECIPE}"/receipts/ -type f -mtime +"$DAYS" | xargs rm
echo "- Complete!"
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment