check-incs.sh : whitespaces and braces

This commit is contained in:
Jérémy Lecour 2019-12-15 18:52:09 +01:00
parent 832a219f0b
commit fe6811bc1e

View file

@ -5,35 +5,35 @@ EVOBACKUP_CONFIGS="/etc/evobackup/*"
relative_date() { relative_date() {
format=$(echo $1 | cut -d'.' -f1) format=$(echo $1 | cut -d'.' -f1)
time_jump=$(echo $1 | cut -d'.' -f2) time_jump=$(echo $1 | cut -d'.' -f2)
reference_date=$(date "${format}") reference_date=$(date "${format}")
past_date=$(date --date "${reference_date} ${time_jump}" +"%Y-%m-%d") past_date=$(date --date "${reference_date} ${time_jump}" +"%Y-%m-%d")
echo ${past_date} echo ${past_date}
} }
inc_exists() { inc_exists() {
ls -d /backup/incs/$1 > /dev/null 2>&1 ls -d /backup/incs/$1 > /dev/null 2>&1
} }
jail_exists() { jail_exists() {
ls -d /backup/jails/$1 > /dev/null 2>&1 ls -d /backup/jails/$1 > /dev/null 2>&1
} }
# default return value is 0 (succes) # default return value is 0 (succes)
rc=0 rc=0
# loop for each configured jail # loop for each configured jail
for file in ${EVOBACKUP_CONFIGS}; do for file in ${EVOBACKUP_CONFIGS}; do
jail_name=$(basename $file) jail_name=$(basename ${file})
# check if jail is present # check if jail is present
if jail_exists ${jail_name}; then if jail_exists ${jail_name}; then
# get jail last configuration date # get jail last configuration date
jail_config_age=$(date --date "$(stat -c %y ${file})" +%s) jail_config_age=$(date --date "$(stat -c %y ${file})" +"%s")
# loop for each line in jail configuration # loop for each line in jail configuration
for line in $(cat $file); do for line in $(cat ${file}); do
# inc date in ISO format # inc date in ISO format
inc_date=$(relative_date $line) inc_date=$(relative_date ${line})
# inc date in seconds from epoch # inc date in seconds from epoch
inc_age=$(date --date "${inc_date}" +%s) inc_age=$(date --date "${inc_date}" +"%s")
# check if the configuration changed after the inc date # check if the configuration changed after the inc date
if [ $jail_config_age -lt $inc_age ]; then if [ "${jail_config_age}" -lt "${inc_age}" ]; then
# Error if inc is not found # Error if inc is not found
if ! inc_exists ${jail_name}/${inc_date}*; then if ! inc_exists ${jail_name}/${inc_date}*; then
echo "ERROR: inc is missing \`${jail_name}/${inc_date}'" >&2 echo "ERROR: inc is missing \`${jail_name}/${inc_date}'" >&2