Skip to content

Instantly share code, notes, and snippets.

@leeramsay
Last active September 2, 2015 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeramsay/110babde61c87074c14e to your computer and use it in GitHub Desktop.
Save leeramsay/110babde61c87074c14e to your computer and use it in GitHub Desktop.
Bash script to parse installed Mac OS pkgs, and find any that have modified the default user template.
#!/bin/bash
# Find packages that have touched the default profile.
# Edit this to your org string for your packages.
# All your packages have a consistent org string, I hope!
# I'd suggest you pipe this script into more, or output to a text file for readability.
# EDIT ME
org="com.leeroy"
# User Template match
defprof="/System/Library/User Template"
# For packages that match our org string
for i in $(/usr/sbin/pkgutil --pkgs=^$org.*); do
# Look for the user template path in the bill of materials
if /usr/bin/grep -q "${defprof}" <<< $(/usr/sbin/pkgutil --lsbom "${i}"); then
# Formatting
echo -e '\n=======\n' "${i}" '\n=======\n'
# I couldn't remember how to store strings with newlines in variables in bash
# So I just ran an identical pkgutil command twice, oh the shame.
# I'm also only printing the relevant default profile parts of the package
# Remove the pipe into grep, if you want to see everything.
/usr/sbin/pkgutil --lsbom "${i}" | /usr/bin/grep "${defprof}"
fi
done
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment