Skip to content

Instantly share code, notes, and snippets.

@phillymjs
Last active July 31, 2019 20:13
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillymjs/6951484 to your computer and use it in GitHub Desktop.
Save phillymjs/6951484 to your computer and use it in GitHub Desktop.
I wrote this script for myself and thought others might find it useful. Run it on your Reposado server, and it will check for current Apple updates that are not assigned to any of your branches. If it finds any, it will send an email notification. If you also use Margarita to provide a web interface, you can have the email include a link to that…
#!/bin/sh
# File locations - Change as needed
list="/tmp/updatelist.txt" # List of updates not in any branches
email="/tmp/updatemail.txt" # Temp file to hold the email message
mailbinary="/usr/sbin/sendmail" # Location of the binary that sends mail
repoutil="/usr/local/reposado/repoutil" # Location of the repoutil binary
# Options for automatically adding new updates to a branch - Change as desired
autoadd=true
testbranch="Test"
# Email Information - Change as desired
fromname="${HOSTNAME}"
from="sender@yourdomain.com"
to="recipient@yourdomain.com"
subject="Software Update Alert"
margserver="${HOSTNAME}"
margport="8089"
# List available updates that are not in any branch and are not marked as deprecated
${repoutil} --updates | grep "\[\]" | grep -v "(Deprecated)" > ${list}
# Count the new updates
updatecount=$(cat ${list} | wc -l | tr -d ' ')
# If updates are available send the email notification and optionally add them to a designated branch
if [ "${updatecount}" -gt 0 ]; then
# If autoadd is enabled then add the updates to the designated branch to mirror Apple's branch
if [ "${autoadd}" = true ] ; then
# Remove deprecated updates from the designated branch
deprecatedproductIDs=$(${repoutil} --updates | grep "${testbranch}" | grep "(Deprecated)" | awk '{ print $1 }' | tr '\n' ' ')
${repoutil} --remove-product=${deprecatedproductIDs} ${testbranch}
# Add the new updates to the designated branch
newproductIDs=$(cat ${list} | awk '{ print $1 }' | tr '\n' ' ')
${repoutil} --add-product=${newproductIDs} ${testbranch}
fi
(
echo "From: ${fromname} <${from}>";
echo "To: ${to}";
echo "Subject: ${subject}";
echo "";
) > ${email}
if [ "${updatecount}" -gt 1 ]; then
if [ "${autoadd}" = true ] ; then
echo "The following ${updatecount} updates were added to the ${testbranch} update branch:" >> ${email}
else
echo "There are ${updatecount} new updates awaiting your approval:" >> ${email}
fi
else
if [ "${autoadd}" = true ] ; then
echo "The following update was added to the ${testbranch} update branch:" >> ${email}
else
echo "There is ${updatecount} new update awaiting your approval:" >> ${email}
fi
fi
(
echo
cat /tmp/updatelist.txt | awk -F ' '+ '{ print $2 " v" $3 }'
echo
# Add a link to Margarita
echo "Click here to visit the web interface: http://${margserver}:${margport}"
) >> ${email}
cat ${email} | ${mailbinary} -t
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment