#!/bin/bash # _________________________________________________________________ # | |\ # | --- Slapt Update --- | | # | | | # | Author: Sean Donner | | # | Email: sean.donner at gmail dot com | | # | | | # | This script will notify you via email or STDOUT | | # | about new Slackware packages as they become availible | | # | | | # | See http://www.aetherstorm.com/slapt_example.txt | | # | for an example of the emails you can expect to receive | | # |_________________________________________________________________| | # \__________________________________________________________________\| # _________________________________________________________________________________ # | | # | Set this to the address of which the email | # | will be mailed *from* | # | | MAIL_FROM="slapt_update@example.com" # |_________________________________________________________________________________| # | | # | Set this to the address that the email will | # | be sent *to* | # | | RCPT_TO="your_email@example.com" # |_________________________________________________________________________________| # | | # | Change this to "1" if you want to be notified about | # | updates to packages that are normally on your | # | EXCLUDE list | # | | IGNORE_EXCLUDES="1" # |_________________________________________________________________________________| # | | # | Change this to "1" if you are tracking -current | # | | TRACK_CURRENT="0" # |_________________________________________________________________________________| # | | # | Change this to "0" if you do not want the new | # | additions of the changelog to be included in the | # | email notification. | # | It is highly recommended that you leave this enabled | # | as the changelog often has important information, | # | especially if tracking -current. | # | | REPORT_CHANGELOG="1" # |_________________________________________________________________________________| # | | # | Change this to "1" to include a report of packages | # | that are obsolete and are no longer apart of the | # | slackware package tree. | # | Any packages that have been custom-made | # | will be listed in this report unless you have put | # | them on your EXCLUDE list. | # | Note: this option will do nothing unless | # | TRACK_CURRENT is set to "1" above. | # | | REPORT_OBSOLETE="1" # |_________________________________________________________________________________| # | | # | Change this to "1" if you want to have | # | slapt-get automatically download (but not install) | # | new packages | # | | DOWNLOAD="1" # |_________________________________________________________________________________| # | | # | Change these URLs to point to a mirror of your liking. | # | Make sure you give the full URL to the ChangeLog.txt file. | # | Also ensure that you are using the correct changelog for | # | your installed version of Slackware | # | | CHANGELOG_STABLE="http://slackware.osuosl.org/slackware-12.2/ChangeLog.txt" CHANGELOG_CURRENT="http://slackware.osuosl.org/slackware-current/ChangeLog.txt" # |_________________________________________________________________________________| # | | # | Change this to "1" if you want to have the report | # | sent to STDOUT rather than having it emailed. This | # | option is usefull for pipeing the output to other | # | commands or for debugging purposes or for using the | # | crontab facility to send out the email | # | | SEND_TO_STDOUT="0" # |_________________________________________________________________________________| #=========================== DO NOT EDIT BELOW THIS LINE ============================ if [[ "${TRACK_CURRENT}" == "1" ]]; then CHANGELOG="${CHANGELOG_CURRENT}" else CHANGELOG="${CHANGELOG_STABLE}" fi if [[ ! -d /etc/slapt-get ]]; then echo "ERROR, you do not seem to have slapt-get installed!" exit 1 fi if [[ "${SEND_TO_STDOUT}" == "0" ]]; then if [[ "${MAIL_FROM}" == "slaptupdate@example.com" || "${RCPT_TO}" == "user@example.com" ]]; then echo "ERROR, you MUST change both MAIL_FROM and RCPT_TO email addresses!" exit 2 fi fi if ! curl -Is "${CHANGELOG}" | grep "Last-Modified:" > /tmp/changelog.last; then echo "ERROR in CHANGELOG URL, cannot continue!" if [[ "${SEND_TO_STDOUT}" == "0" ]]; then mail -s "Slapt Update URL ERROR" -r "Slapt Update <${MAIL_FROM}>" "${RCPT_TO}" <<-EOF Slapt Update is having problems downloading from the following URL: ${CHANGELOG} This may be due to a syntax error in the URL itself, or the URL is no longer reachable from the Internet. EOF fi exit 3 fi if [[ ! -f /etc/slapt-get/changelog.last ]]; then curl -Is "${CHANGELOG}" | grep "Last-Modified:" > /etc/slapt-get/changelog.last fi if [[ ! -f /etc/slapt-get/changelog ]]; then curl -s "${CHANGELOG}" --output /etc/slapt-get/changelog fi if ! diff /tmp/changelog.last /etc/slapt-get/changelog.last > /dev/null 2>&1; then slapt-get --update > /dev/null 2>&1 if (( "${TRACK_CURRENT}" && "${IGNORE_EXCLUDES}" )); then SLAPT_COMMAND="slapt-get --dist-upgrade --remove-obsolete --ignore-excludes --simulate" MODE="1" elif (( "${TRACK_CURRENT}" && ! "${IGNORE_EXCLUDES}" )); then SLAPT_COMMAND="slapt-get --dist-upgrade --remove-obsolete --simulate" MODE="2" elif (( ! "${TRACK_CURRENT}" && "${IGNORE_EXCLUDES}" )); then SLAPT_COMMAND="slapt-get --upgrade --ignore-excludes --simulate" MODE="3" else SLAPT_COMMAND="slapt-get --upgrade --simulate" MODE="4" fi function package_data { $SLAPT_COMMAND | awk -v report_obsolete="${REPORT_OBSOLETE}" '/to be (installed|upgraded|removed)/ { Seen[$5, ++ind[$5]] = $1 " " $NF; } END { printArray(Seen, "installed", "+", "New Packages"); if (report_obsolete == 1) printArray(Seen, "removed", "-", "Obsolete Packages"); printArray(Seen, "upgraded", "*", "Upgraded Packages"); } function printArray(Array, action, bullet, header, n,T) { print "[==]", header, "---"; while (Array[action, ++n]) { split(Array[action, n], T); if (T[2] == "installed" || T[2] == "removed") print "["bullet"]", T[1]; else print "["bullet"]", T[1], "=>", T[2]; } if (n == 1) print "[*] --none ---"; printf "\n" }' } function change_data { curl -s "${CHANGELOG}" --output /tmp/changelog if [[ "${REPORT_CHANGELOG}" == "1" ]]; then diff /etc/slapt-get/changelog /tmp/changelog | awk 'BEGIN { printf "[==] Changelog Excerpt ---\n" } NR > 1 { sub(/(>|<)/,"[%]"); print } END { if (NR == 0) print "[%] --none ---" }' fi mv /tmp/changelog /etc/slapt-get/changelog } if [[ "${SEND_TO_STDOUT}" == "0" ]]; then ( package_data && change_data ) | mail -s "New Packages Available" -r "Slapt Update <${MAIL_FROM}>" "${RCPT_TO}" else package_data change_data fi if [[ "${DOWNLOAD}" == "1" ]]; then if [[ "${MODE}" == "1" ]]; then slapt-get --dist-upgrade --ignore-excludes --download-only > /dev/null 2>&1 elif [[ "${MODE}" == "2" ]]; then slapt-get --dist-upgrade --download-only > /dev/null 2>&1 elif [[ "${MODE}" == "3" ]]; then slapt-get --upgrade --ignore-excludes --download-only > /dev/null 2>&1 else slapt-get --upgrade --download-only > /dev/null 2>&1 fi fi mv /tmp/changelog.last /etc/slapt-get/changelog.last else rm /tmp/changelog.last fi # _________________________________________________________________________________ # | | # | --- CHANGELOG --- | # | | # | [==] Fri Jan 05 2008 --- | # | [%] Removed CHECK_UPDATE option because this script is unlikely to ever change | # | | # | [==] Tue Apr 19 2005 --- | # | [%] Updated CHANGELOG URL's to a faster site, also updated the path for 10.1 | # | [%] Changed project description to reflect script's ability to report to STDOUT | # | [%] Changed comment about STDOUT being usefull for only debugging purposes | # | [%] Forgot to update email check to look for example.com rather than foobar.com | # | | # | [==] Thur Feb 3 2005 --- | # | [%] Upgraded version to 1.0 | # | [%] Rewrote report generation entirly in awk (Thank you xmb for the awk help) | # | [%] Added ability to ignore excludes | # | [%] Added ability to report obsolete packages | # | [%] Added ability to send the report to STDOUT rather than an email | # | [%] If Changelog URL stops working, a notification email will be sent | # | [%] Removed Verbose Notify feature as it's no longer needed with new code | # | [%] Made Changelog report optional | # | [%] Used awk for changelog report generation | # | [%] Changed default email domains from foobar.com to the reserved example.com | # | | # | [==] Sat Jan 29 2005 --- | # | [%] Upgraded to version 0.91 | # | [%] Used --dist-upgrade instead of just --upgrade when tracking -current | # | [%] Added the ability to have the script check for new versions of itself | # | [%] Added checks for URL and email input | # | | # | [==] Mon Oct 3 2004 --- | # | [%] Version 0.90 released | # |_________________________________________________________________________________|