#!/bin/sh # # Description: Run check on all expected incs of all jails # Usage: check-incs all # set -u # shellcheck source=./includes LIBDIR="$(dirname "$0")" && . "${LIBDIR}/includes" # default return value is 0 (succes) rc=0 # loop for each configured jail for jail_name in $("${LIBDIR}/bkctld-list"); do incs_policy_file=$(current_jail_incs_policy_file "${jail_name}") # Today in seconds from epoch today_epoch=$(date +"%s") # Today in ISO format today_iso=$(date +"%Y-%m-%d") if [ -n "${incs_policy_file}" ]; then # get jail last configuration date jail_config_epoch=$(date --date "$(stat -c %y "${incs_policy_file}")" +"%s") # read each line in jail configuration while read line; do ## TODO # deal with empty lines # inc date in ISO format inc_iso=$(relative_date "${line}") # inc date in seconds from epoch inc_epoch=$(date --date "${inc_iso}" +"%s") # skip line if date is in the future if [ "${inc_epoch}" -gt "${today_epoch}" ]; then echo "INFO: ${jail_name} : no inc expected for ${inc_iso}" else # check if the configuration changed after the inc date # or if it's today's inc if [ "${jail_config_epoch}" -lt "${inc_epoch}" ] \ || [ "${today_iso}" = "${inc_iso}" ]; then # Error if inc is not found if ! inc_exists "${jail_name}" "${inc_iso}*"; then echo "ERROR: ${jail_name} : missing inc for ${inc_iso}" >&2 rc=1 fi else echo "INFO: ${jail_name} : no inc expected for ${inc_iso}" fi fi done < "${incs_policy_file}" else echo "INFO: ${jail_name} : no inc expected at all" fi done exit $rc