Index: etc/periodic.subr =================================================================== --- etc/periodic.subr (revision 0) +++ etc/periodic.subr (working copy) @@ -0,0 +1,105 @@ +# $FreeBSD$ +# +# Copyright (c) 1997-2004 The FreeBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE FREEBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# periodic.subr +# functions used by periodic(5) scripts +# +# Many of the following functions were grabbed wholesale from rc.subr. +# + +# +# checkyesno var +# Test $1 variable, and warn if not set to YES or NO. +# Return 0 if it's "yes" (et al), nonzero otherwise. +# +checkyesno() +{ + eval _value=\$${1} + debug "checkyesno: $1 is set to $_value." + case $_value in + + # "yes", "true", "on", or "1" + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + return 0 + ;; + + # "no", "false", "off", or "0" + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + return 1 + ;; + *) + warn "\$${1} is not set properly - see ${rcvar_manpage}." + return 1 + ;; + esac +} + +# +# debug message +# If debugging is enabled in rc.conf output message to stderr. +# BEWARE that you don't call any subroutine that itself calls this +# function. +# +debug() +{ + case ${periodic_debug} in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + if [ -x /usr/bin/logger ]; then + logger "$0: DEBUG: $*" + fi + echo 1>&2 "$0: DEBUG: $*" + ;; + esac +} + +# +# err exitval message +# Display message to stderr and log to the syslog, and exit with exitval. +# +err() +{ + exitval=$1 + shift + + if [ -x /usr/bin/logger ]; then + logger "$0: ERROR: $*" + fi + echo 1>&2 "$0: ERROR: $*" + exit $exitval +} + +# +# warn message +# Display message to stderr and log to the syslog. +# +warn() +{ + if [ -x /usr/bin/logger ]; then + logger "$0: WARNING: $*" + fi + echo 1>&2 "$0: WARNING: $*" +} + Property changes on: etc/periodic.subr ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* Index: etc/periodic/daily/120.clean-preserve =================================================================== --- etc/periodic/daily/120.clean-preserve (revision 229316) +++ etc/periodic/daily/120.clean-preserve (working copy) @@ -5,6 +5,8 @@ # Remove stale files in /var/preserve # +. /etc/periodic.subr + # If there is a global system configuration file, suck it in. # if [ -r /etc/defaults/periodic.conf ] @@ -13,31 +15,30 @@ source_periodic_confs fi -case "$daily_clean_preserve_enable" in - [Yy][Ee][Ss]) +if checkyesno daily_clean_preserve_enable; then + rc=0 if [ -z "$daily_clean_preserve_days" ] then - echo '$daily_clean_preserve_enable is set but' \ + err 2 '$daily_clean_preserve_enable is set but' \ '$daily_clean_preserve_days is not' - rc=2 elif [ ! -d /var/preserve ] then - echo '$daily_clean_preserve_enable is set but /var/preserve' \ + err 2 '$daily_clean_preserve_enable is set but /var/preserve' \ "doesn't exist" - rc=2 else - echo "" - echo "Removing stale files from /var/preserve:" + if checkyesno daily_clean_preserve_verbose; then + echo "" + echo "Removing stale files from /var/preserve:" + fi + if cd /var/preserve then - case "$daily_clean_preserve_verbose" in - [Yy][Ee][Ss]) + if checkyesno daily_clean_preserve_verbose; then print=-print;; - *) + else print=;; - esac - + fi rc=$(find . ! -name . -mtime +$daily_clean_preserve_days \ -delete $print | tee /dev/stderr | wc -l) [ -z "$print" ] && rc=0 @@ -45,9 +46,7 @@ else rc=3 fi - fi;; + fi +fi - *) rc=0;; -esac - exit $rc