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.

78 lines
1.7 KiB

  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. #
  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=-" | \
  45. nice -5 su -m nobody 1>$TMP
  46. if [ $? -ne 0 ]; then
  47. echo "Rebuilding locate database failed"
  48. elif ! locate -d $TMP /etc/weekly >/dev/null; then
  49. echo "Not installing invalid locate database"
  50. else
  51. chmod 444 $TMP
  52. chown root:wheel $TMP
  53. mv -f $TMP /var/db/locate.database
  54. fi
  55. else
  56. echo "Not rebuilding locate database; can't create temp file"
  57. fi
  58. fi
  59. next_part "Rebuilding whatis databases:"
  60. /usr/sbin/makewhatis $MAKEWHATISARGS
  61. next_part "Doing login accounting:"
  62. [ "X$LOGINACCOUNTING" = X1 ] && {
  63. ac -p | sort -nr -k 2
  64. }
  65. end_part
  66. rm -f $PARTOUT
  67. [ -s $MAINOUT ] && mail -s "`hostname` weekly output" root < $MAINOUT