#!/bin/bash
#
# test_certexpires
#
# Ablaufdatum von SSL-Zertifikaten prüfen
# ruft test_certexpire auf
#
#################################
WDIR="`dirname $0`"
#
CONF=/etc/uls/certexpires.conf
#
unset S DT TMP_PATH
#
while getopts c:d:S? op
 do
  case "$op" in
    c) CONF="$OPTARG";;
    d) TMP_PATH="-d $OPTARG";;
    S) S="-S";;
    *) echo "usage: $0 [-d storepath] [-c confpath] [-S] [<date> <time>]"
       exit 1;;
  esac
done
shift $(( $OPTIND - 1 ))
#
#
if [[ $# -lt 2 ]]
 then
  DT="`date '+%F %T%:z'`"
else
  DT="$1 $2"
fi
#
if [[ -f "$CONF" ]]
 then
  grep '^ *[^#]* ' "$CONF" | while read file sec tst host
   do
    if [[ -n "$tst" ]]
     then
      if [[ -n "$host" ]]
       then
        $WDIR/test_certexpire -D "$DT" $TMP_PATH $S -h "$host" "$sec" "$tst" "$file"
      else
        $WDIR/test_certexpire -D "$DT" $TMP_PATH $S "$sec" "$tst" "$file"
      fi
    fi
  done
fi
