3d8e The FreeBSD Forums - View Single Post - Useful scripts
Thread: Useful scripts
View Single Post
  #37  
Old September 1st, 2009, 11:14
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Administrator
 
Join Date: Nov 2008
Location: Rotterdam, the Netherlands
Posts: 9,838
Thanks: 30
Thanked 1,888 Times in 1,333 Posts
Default portupdater script

My 'portupdater' script for daily use. Requires ports-mgmt/portmaster and ports-mgmt/portaudit.

The script can be run from cron, which will invoke portsnap with a random sleep period of 0-60 minutes and does not require any intervention. It mails a summary to e.g. root.

It can also be run from the command-line when an extra argument is supplied (e.g. portupdater yes or portupdater now). This will make it run immediately, and with some extra functions that may require interaction.

The script will only update/maintain the ports tree and show a summary, it will not update ports. The ports that need updating are printed, of course.

The script can be made to work with ports-mgmt/portupgrade by just replacing the applicable commands. In fact, this script used to be portupgrade-based before I switched to portmaster.
Code:
#!/bin/sh
hostname=$(hostname)
date=$(/bin/date)

echo "
Updating portaudit first.
"
/usr/local/etc/periodic/security/410.portaudit

echo "
Portupdater for ${hostname} started at ${date}


========== Fetching latest ports snapshot from server. ==================
"

if [ $# -lt 1 ]
then
portvar="cron"
else
portvar="fetch"
fi

/usr/sbin/portsnap ${portvar} || exit 1

echo "
========== Updating ports tree with new snapshot. =======================
"
/usr/sbin/portsnap update || exit 1

echo "
============ Cleaning out all obsolete distfiles. =======================
"
/usr/local/sbin/portmaster -y --clean-distfiles || exit 1

if [ ${portvar} = "fetch" ]
then
echo "
Ah, you're actually here. Good.

Running some (possibly) interactive stuff.
"
/bin/sleep 5

echo "
============ Cleaning out stale ports. ==================================
"
/usr/local/sbin/portmaster -s || exit 1
echo "
============ Checking port dependencies. ================================
"
/usr/local/sbin/portmaster --check-depends || exit 1
echo "
============ Cleaning up /var/db/ports. =================================
"
/usr/local/sbin/portmaster --check-port-dbdir || exit 1
fi

echo "
=================== See which ports need updating. ======================
"
/usr/sbin/pkg_version -IvL '=' || exit 1

echo "
================= Warnings from /usr/ports/UPDATING. ====================
"
weekago=$( /bin/date -v-1w +%Y%m%d )
lastpkg=$( ls -D %Y%m%d -ltr /var/db/pkg | /usr/bin/tail -n1 | /usr/bin/tr -s " " "\t" | /usr/bin/cut -f 6 )
if [ ${weekago} -lt ${lastpkg} ]
 then usedate=${weekago}
 else usedate=${lastpkg}
fi
/usr/sbin/pkg_updating -d ${usedate}
echo "
See /usr/ports/UPDATING for further details.

========== Portupdater done. ============================================
"
__________________
FreeBSD Forums: Information for New Members | FreeBSD Forums Rules
FreeBSD Resources: The FreeBSD Handbook | Manuals | FAQ | Wiki
Before you post: How to ask questions the smart way
If you must know .. So, what does an Administrator/Moderator do?
---> Do not PM me with FreeBSD questions. I do not work here. <---

Last edited by DutchDaemon; November 7th, 2011 at 19:28. Reason: script overhaul (revised November 2011)
Reply With Quote
The Following 23 Users Say Thank You to DutchDaemon For This Useful Post:
AASoft (July 18th, 2012), adrian_m (August 9th, 2012), atmosx (March 16th, 2013), baitisj (September 9th, 2012), Bart_ (November 8th, 2011), biniar (September 2nd, 2011), captobvious (November 14th, 2010), cuq (January 19th, 2012), daiv (July 6th, 2012), dougs (July 6th, 2010), emka81 (May 20th, 2010), ghostcorps (September 15th, 2011), interfasys (March 22nd, 2011), jayl (November 4th, 2011), KdeBruin (September 29th, 2012), kdemidofff (July 9th, 2010), kpa (November 5th, 2011), MacGyver (April 30th, 2013), mefizto (February 2nd, 2011), rexpretor (April 4th, 2011), sixtydoses (March 11th, 2010), t4z3v4r3d (September 12th, 2011), vand777 (January 29th, 2011)
 
0