Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.6 KiB

  1. #
  2. # $OpenBSD: weekly,v 1.26 2014/04/18 10:00:48 schwarze 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. #
  7. umask 022
  8. PARTOUT=/var/log/weekly.part
  9. MAINOUT=/var/log/weekly.out
  10. install -o 0 -g 0 -m 600 /dev/null $PARTOUT
  11. install -o 0 -g 0 -m 600 -b /dev/null $MAINOUT
  12. start_part() {
  13. TITLE=$1
  14. exec > $PARTOUT 2>&1
  15. }
  16. end_part() {
  17. exec >> $MAINOUT 2>&1
  18. test -s $PARTOUT || return
  19. echo ""
  20. echo "$TITLE"
  21. cat $PARTOUT
  22. }
  23. next_part() {
  24. end_part
  25. start_part "$1"
  26. }
  27. run_script() {
  28. f=/etc/$1
  29. test -e $f || return
  30. if [ `stat -f '%Sp%u' $f | cut -b1,6,9,11-` != '---0' ]; then
  31. echo "$f has insecure permissions, skipping:"
  32. ls -l $f
  33. return
  34. fi
  35. . $f
  36. }
  37. start_part "Running weekly.local:"
  38. run_script "weekly.local"
  39. next_part "Rebuilding locate database:"
  40. if [ -f /var/db/locate.database ]; then
  41. if TMP=`mktemp /var/db/locate.database.XXXXXXXXXX`; then
  42. trap 'rm -f $TMP; exit 1' 0 1 15
  43. UPDATEDB="/usr/libexec/locate.updatedb"
  44. echo "${UPDATEDB} --fcodes=- --tmpdir=${TMPDIR:-/var/tmp}" | \
  45. nice -5 su -m nobody 2>/dev/null 1>$TMP
  46. if [ -s "$TMP" ]; then
  47. chmod 444 $TMP
  48. chown root:wheel $TMP
  49. mv -f $TMP /var/db/locate.database
  50. else
  51. echo "Not installing locate database; zero size"
  52. fi
  53. else
  54. echo "Not rebuilding locate database; can't create temp file"
  55. fi
  56. fi
  57. next_part "Rebuilding whatis databases:"
  58. /usr/sbin/makewhatis ${MAKEWHATISARGS:--Q}
  59. next_part "Doing login accounting:"
  60. [ "X$LOGINACCOUNTING" = X1 ] && {
  61. ac -p | sort -nr -k 2
  62. }
  63. end_part
  64. rm -f $PARTOUT
  65. [ -s $MAINOUT ] && mail -s "`hostname` weekly output" root < $MAINOUT