jcs's openbsd hax
openbsd
1#
2# $OpenBSD: weekly,v 1.30 2020/02/12 20:51:49 jung Exp $
3#
4# For local additions, create the file /etc/weekly.local.
5# To get section headers, use the function next_part in weekly.local.
6#
7umask 022
8
9PARTOUT=/var/log/weekly.part
10MAINOUT=/var/log/weekly.out
11install -o 0 -g 0 -m 600 /dev/null $PARTOUT
12install -o 0 -g 0 -m 600 -b /dev/null $MAINOUT
13
14start_part() {
15 TITLE=$1
16 exec > $PARTOUT 2>&1
17}
18
19end_part() {
20 exec >> $MAINOUT 2>&1
21 test -s $PARTOUT || return
22 echo ""
23 echo "$TITLE"
24 cat $PARTOUT
25}
26
27next_part() {
28 end_part
29 start_part "$1"
30}
31
32run_script() {
33 f=/etc/$1
34 test -e $f || return
35 if [ `stat -f '%Sp%u' $f | cut -b1,6,9,11-` != '---0' ]; then
36 echo "$f has insecure permissions, skipping:"
37 ls -l $f
38 return
39 fi
40 . $f
41}
42
43start_part "Running weekly.local:"
44run_script "weekly.local"
45
46next_part "Rebuilding locate database:"
47if [ -f /var/db/locate.database ]; then
48 if TMP=`mktemp /var/db/locate.database.XXXXXXXXXX`; then
49 trap 'rm -f $TMP; exit 1' 0 1 15
50 UPDATEDB="/usr/libexec/locate.updatedb"
51 echo "${UPDATEDB} --fcodes=-" | \
52 nice -5 su -m nobody 1>$TMP
53 if [ $? -ne 0 ]; then
54 echo "Rebuilding locate database failed"
55 elif ! locate -d $TMP /etc/weekly >/dev/null; then
56 echo "Not installing invalid locate database"
57 else
58 chmod 444 $TMP
59 chown root:wheel $TMP
60 mv -f $TMP /var/db/locate.database
61 fi
62 else
63 echo "Not rebuilding locate database; can't create temp file"
64 fi
65fi
66
67next_part "Rebuilding whatis databases:"
68/usr/sbin/makewhatis $MAKEWHATISARGS
69
70next_part "Doing login accounting:"
71[ "X$LOGINACCOUNTING" = X1 ] && {
72 ac -p | sort -nr -k 2
73}
74
75end_part
76rm -f $PARTOUT
77
78[ -s $MAINOUT ] && mail -s "`hostname` weekly output" root < $MAINOUT