+ debug=1
+ debug "Debugging info (when run with -d)"
+ info "Informational messages (verbosity level 4)"
+ warning "Warnings (verbosity level 3 and up)"
+ error "Errors (verbosity level 2 and up)"
+ fatal "Fatal, halting errors (always shown)"
+}
+
+##
+## this function handles the running of a backup action
+##
+## these globals are modified:
+## fatals, errors, warnings, actions_run, errormsg
+##
+
+function process_action() {
+ local file="$1"
+ local suffix="$2"
+
+ setfile $file
+
+ # skip over this config if "when" option
+ # is not set to the current time.
+ getconf when "$defaultwhen"
+ if [ "$processnow" == 1 ]; then
+ info ">>>> starting action $file (because of --now)"
+ elif [ "$when" == "hourly" ]; then
+ info ">>>> starting action $file (because 'when = hourly')"
+ else
+ IFS=$'\t\n'
+ for w in $when; do
+ IFS=$' \t\n'
+ isnow "$w"
+ ret=$?
+ IFS=$'\t\n'
+ if [ $ret == 0 ]; then
+ debug "skipping $file because it is not $w"
+ return
+ else
+ info ">>>> starting action $file (because it is $w)"
+ fi
+ done
+ IFS=$' \t\n'
+ fi
+
+ let "actions_run += 1"
+
+ # call the handler:
+ local bufferfile="/tmp/backupninja.buffer.$$"
+ echo "" > $bufferfile
+ echo_debug_msg=1
+ (
+ . $scriptdir/$suffix $file
+ ) 2>&1 | (
+ while read a; do
+ echo $a >> $bufferfile
+ [ $debug ] && colorize "$a"
+ done
+ )
+ retcode=$?
+ # ^^^^^^^^ we have a problem! we can't grab the return code "$?". grrr.
+ echo_debug_msg=0
+
+ _warnings=`cat $bufferfile | grep "^Warning: " | wc -l`
+ _errors=`cat $bufferfile | grep "^Error: " | wc -l`
+ _fatals=`cat $bufferfile | grep "^Fatal: " | wc -l`
+
+ ret=`grep "\(^Warning: \|^Error: \|^Fatal: \)" $bufferfile`
+ rm $bufferfile
+ if [ $_fatals != 0 ]; then
+ msg "*failed* -- $file"
+ errormsg="$errormsg\n== fatal errors from $file ==\n\n$ret\n"
+ passthru "Fatal: <<<< finished action $file: FAILED"
+ elif [ $_errors != 0 ]; then
+ msg "*error* -- $file"
+ errormsg="$errormsg\n== errors from $file ==\n\n$ret\n"
+ error "<<<< finished action $file: ERROR"
+ elif [ $_warnings != 0 ]; then
+ msg "*warning* -- $file"
+ errormsg="$errormsg\n== warnings from $file ==\n\n$ret\n"
+ warning "<<<< finished action $file: WARNING"
+ else
+ msg "success -- $file"
+ info "<<<< finished action $file: SUCCESS"
+ fi
+
+ let "fatals += _fatals"
+ let "errors += _errors"
+ let "warnings += _warnings"
+}
+
+#####################################################
+## MAIN
+
+setupcolors
+conffile="/etc/backupninja.conf"
+loglevel=3
+
+## process command line options
+
+while [ $# -ge 1 ]; do
+ case $1 in
+ -h|--help) usage;;
+ -d|--debug) debug=1;;
+ -t|--test) test=1;debug=1;;
+ -n|--now) processnow=1;;
+ -f|--conffile)
+ if [ -f $2 ]; then
+ conffile=$2
+ else
+ echo "-f|--conffile option must be followed by an existing filename"
+ fatal "-f|--conffile option must be followed by an existing filename"
+ usage
+ fi
+ # we shift here to avoid processing the file path
+ shift
+ ;;
+ --run)
+ debug=1
+ if [ -f $2 ]; then
+ singlerun=$2
+ processnow=1
+ else
+ echo "--run option must be fallowed by a backupninja action file"
+ fatal "--run option must be fallowed by a backupninja action file"
+ usage
+ fi
+ shift
+ ;;
+ *)
+ debug=1
+ echo "Unknown option $1"
+ fatal "Unknown option $1"
+ usage
+ exit
+ ;;
+ esac
+ shift
+done
+
+#if [ $debug ]; then
+# usercolors=yes
+#fi