#!/bin/bash
#
# test_conf_files
#
# Fuer alle Konfigurationsdateien aus /etc/uls/conf_files.conf
# Datei komprimiert ans ULS senden
#
################################################################
#
CONF=/etc/uls/conf_files.conf
#
while getopts c:? op
 do
  case "$op" in
    c) CONF=$OPTARG;;
    ?) echo "usage: `basename $0` [-c <conf>] <date> <time>"
       exit 0;;
    *) echo "usage: `basename $0` [-c <conf>] <date> <time>"
       exit 1;;
  esac
done
shift $(( $OPTIND -1))
#
if [[ $# -lt 2 ]]
 then
  DT="`date '+%F %T%:z'`"
else
  DT="$1 $2"
fi
#
if which xz >/dev/null 2>&1
 then
  COMPRESS=xz
  EXT=xz
else
  COMPRESS=bzip2
  EXT=bz2
fi
#
ACC=all
export ACC
#
if [[ -f "$CONF" ]]
 then
   awk -F '[ \t]*#' '$1 != ""{print $1}' "$CONF" | while read section teststep files
   do
    if [[ ${section#*[} != $section ]]
     then
      S=${section#*[}
      ACC=${S%]*}
    else
      ls $files 2>/dev/null | while read pathname
       do
        filename="`basename $pathname`"
        $COMPRESS -c "$pathname" | send_stdin_file -s $ACC $section $teststep "$filename" $DT $filename.$EXT
      done
    fi
  done
fi
