weekly revision 1.23
11.1Scgd#!/bin/sh -
21.1Scgd#
31.23Smartti#	$NetBSD: weekly,v 1.23 2007/06/06 13:30:48 martti Exp $
41.7Smikel#	from: @(#)weekly	8.2 (Berkeley) 1/2/94
51.1Scgd#
61.1Scgd
71.11Smycroftexport PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/libexec
81.12Slukemumask 077
91.12Slukem
101.12Slukemif [ -s /etc/weekly.conf ]; then
111.12Slukem	. /etc/weekly.conf
121.12Slukemfi
131.12Slukem
141.10Slukemhost=`hostname`
151.12Slukemdate=`date`
161.18Sjmmvrcvar_manpage='weekly.conf(5)'
171.1Scgd
181.12Slukemecho "To: ${MAILTO:-root}"
191.12Slukemecho "Subject: $host weekly output for $date"
201.12Slukemecho ""
211.6Smrg
221.10Slukemif [ -f /etc/rc.subr ]; then
231.10Slukem	. /etc/rc.subr
241.10Slukemelse
251.10Slukem	echo "Can't read /etc/rc.subr; aborting."
261.10Slukem	exit 1;
271.6Smrgfi
281.6Smrg
291.23SmarttiWEEKLYDIR=$(mktemp -d -t _weekly) || exit 1
301.19Skim
311.19Skimtrap "/bin/rm -rf $WEEKLYDIR ; exit 0" EXIT INT QUIT PIPE
321.19Skim
331.19Skimif ! cd "$WEEKLYDIR"; then
341.19Skim	echo "Can not cd to $WEEKLYDIR".
351.19Skim	exit 1
361.19Skimfi
371.19Skim
381.19SkimTMP=weekly.$$
391.19Skim
401.1Scgd#echo ""
411.1Scgd#echo "Removing old .o files:"
421.1Scgd#find /usr/src -name '*.o' -atime +21 -print -a -exec rm -f {} \;
431.1Scgd
441.1Scgd# see if /usr/src exists and is local
451.1Scgd# before looking there for checked-out files
461.1Scgd
471.2Scgd#if [ -d /usr/src -a \
481.8Smycroft#  -n "`find -f /usr/src ! -fstype local -prune -or -type d -print -prune`" ];
491.2Scgd#then
501.16Skim#	echo ""
511.16Skim#	echo "Looking for checked out files:"
521.2Scgd#
531.23Smartti#	TDIR=$(mktemp -d -t _checkout) || exit 1
541.17Slukem#	trap "/bin/rm -rf $TDIR ; exit 0" EXIT INT QUIT
551.2Scgd#	for file in `find -f /usr/src ! -fstype local -prune -or \
561.2Scgd#	    -name 'p.*' -print | egrep 'SCCS/p\.'`; do
571.2Scgd#		owner=`awk '{ print $3 }' $file`
581.2Scgd#		echo "$owner	$file"
591.17Slukem#		echo $file >> "$TDIR/$owner"
601.2Scgd#	done | sed -e 's,SCCS/p.,,'
611.7Smikel#	if test -n "`ls $TDIR`"; then
621.7Smikel#		for file in $TDIR/*; do
631.7Smikel#			sed -e 's,SCCS/p.,,' $file | \
641.15Slukem#			    Mail -s 'checked out files' ${file##*/}
651.7Smikel#		done
661.7Smikel#	fi
671.2Scgd#fi
681.1Scgd
691.16Skimif checkyesno rebuild_locatedb; then
701.16Skim	echo ""
711.16Skim	if [ -f /var/db/locate.database ]; then
721.16Skim		echo "Rebuilding locate database:"
731.16Skim		chmod 644 /var/db/locate.database
741.16Skim		chown nobody:nobody /var/db/locate.database
751.20Slukem		(cd / && nice -5 su -m nobody -c /usr/libexec/locate.updatedb 2>/dev/null)
761.16Skim		chown root:wheel /var/db/locate.database
771.16Skim	else
781.16Skim		echo "Not rebuilding locate database; no /var/db/locate.database"
791.16Skim	fi
801.14Sadfi
811.14Sad
821.22Sreedif checkyesno rebuild_whatisdb; then
831.22Sreed	echo ""
841.22Sreed	if [ -f /etc/man.conf -o -d /usr/share/man ]; then
851.22Sreed		echo "Rebuilding whatis databases:"
861.22Sreed		nice -n 5 /usr/libexec/makewhatis -f
871.22Sreed	else
881.22Sreed		echo "Not rebuilding whatis databases"
891.22Sreed	fi
901.22Sreedfi
911.22Sreed
921.14Sadif [ -f /etc/weekly.local ]; then
931.19Skim	. /etc/weekly.local > $TMP 2>&1
941.19Skim	if [ -s $TMP ] ; then
951.19Skim		printf "\nRunning /etc/weekly.local:\n"
961.19Skim		cat $TMP
971.19Skim	fi
981.19Skim	rm -f $TMP
991.4Scgdfi
100