Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiqViq/769d4d330aaf001a5372 to your computer and use it in GitHub Desktop.
Save MiqViq/769d4d330aaf001a5372 to your computer and use it in GitHub Desktop.
For Munki: automatically create apple_update_metadata pkginfo files for XProtectPlistConfigData, Gatekeeper Configuration Data
#!/bin/bash
# reposado_auto_munkiimport_aswupd_configdata_items
#
# automatically create apple_update_metadata pkginfo files for Munki: XProtectPlistConfigData, Gatekeeper Configuration Data
#
# path to your Munki repo (local or mounted share)
munkiRepoDir="/Users/Shared/munki/repo"
# path to pkgsinfo in Munki repo
munkiPkgsInfoDir="${munkiRepoDir}/pkgsinfo"
# path to Apple Software Updates metadata directory in Munki repo, it is cleaner to separate them from other updates
munki_ASWUPD_META_Dir="${munkiPkgsInfoDir}/ASWUPD_META"
# path to your executable repoutil command
repoUtilCmd="/path/to/your/reposado/code/repoutil"
# file owner and group, needed if this script is run as root
fileOwner=jenkins
fileGroup=munki
###
# functions
function logTyper () {
timeStamp=$(date '+%h %d %T')
echo "${timeStamp}: ${1}"
}
###
# actions
if [ ! -d "${munki_ASWUPD_META_Dir}" ]; then
logTyper "Munki directory '${munki_ASWUPD_META_Dir}' is not available"
exit 1
fi
if ! [ -x "${repoUtilCmd}" ]; then
logTyper "'${repoUtilCmd}' not found"
exit 1
fi
logTyper "Checking for config-data updates..."
listSysConfigUpdates=$("${repoUtilCmd}" --products | egrep 'XProtectPlistConfigData|Gatekeeper Configuration Data' | grep -v '(Deprecated)')
OLD_IFS=${IFS}
IFS=$'\n'
# process updates
for item in ${listSysConfigUpdates}
do
itemID=$(echo "${item}" | awk '{print $1}')
if [ "" == "${itemID}" ]; then
continue
fi
getItemInfo=$("${repoUtilCmd}" --info "${itemID}")
itemTitle=$(echo "${getItemInfo}" | grep 'Title:' | awk -F 'Title:' '{print $NF}' | sed 's/^ *//;s/ *$//')
if [ "" == "${itemTitle}" ]; then
continue
fi
itemVers=$(echo "${getItemInfo}" | grep 'Version:' | awk -F 'Version:' '{print $NF}' | tr -d ' ')
itemDescr="${itemTitle} ${itemVers} [${itemID}] from Apple."
itemFileName=$(echo "${itemTitle}" | tr ' ' '_')-"${itemVers}"-"${itemID}".plist
# check if metadata file is laready in Munki repo
if [ -e "${munki_ASWUPD_META_Dir}/${itemFileName}" ]; then
logTyper "Metadata '${itemFileName}' is already in Munki repo."
continue
fi
# create a pkginfo for metadata
/usr/local/munki/makepkginfo --apple-update "${itemID}" --displayname="${itemTitle}" --catalog testing --catalog another_one --description="${itemDescr}" --unattended_install > /tmp/"${itemFileName}"
chmod a+rw /tmp/"${itemFileName}"
# copy pkginfo to proper location
cp /tmp/"${itemFileName}" "${munki_ASWUPD_META_Dir}/${itemFileName}"
if [ $? -ne 0 ]
then
logTyper "ERROR: could not copy '${itemFileName}' to '${munki_ASWUPD_META_Dir}"
fi
logTyper "Copied '${itemFileName}' to '${munki_ASWUPD_META_Dir}"
chown "${fileOwner}":"${fileGroup}" "${munki_ASWUPD_META_Dir}/${itemFileName}"
chmod ug+rw,a+r "${munki_ASWUPD_META_Dir}/${itemFileName}"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment