#!/bin/bash
#
# send_script2uls
#
# send_script2uls schickt das Protokoll, das per script erzeugt wird ans ULS
#
# Aufruf:
# send_script2uls <filename> <hostname> <Section> <Teststep> <Detail> <date time>
##############################################################################
#
if [[ ${PATH#*/usr/local/bin} = $PATH ]]
 then
  export PATH=$PATH:/usr/local/bin
fi
#
if which xz >/dev/null 2>&1
 then
  COMPRESS=xz
  EXT=xz
else
  COMPRESS=bzip2
  EXT=bz2
fi
#
trap '' 1 2 3 6 9 14 15
#
if [[ $# -ne 6 ]]
 then
  echo "usage: $0 <filename> <hostname> <Section> <Teststep> <Detail> <date time>"
  exit 1
fi
#
if [[ ! -r "$1.fifo" ]]
 then
  echo "$0: $1 ist nicht lesbar."
  exit 2
fi
#
umask 077
#
MAGIC=$RANDOM
export MAGIC
( send_test_value -S -s sec -h "$2" "$3" "$4" "$5-Magic" $6 "$MAGIC" " "
  echo "Magic-Start: $MAGIC"
  cat "$1.fifo"
  echo "Magic-End: $MAGIC"
) | $COMPRESS | send_stdin_file -S -s sec -a -b 1024000 -h "$2" "$3" "$4" "$5" $6 "$1.$EXT" && send_test_value -S -s sec -h "$2" "$3" "$4" "$5-Finish" $6 "$MAGIC" " " || send_test_value -S -s sec -h "$2" "$3" "$4" "$5-Abort" $6 "$MAGIC" " "
rm -f "$1.fifo"
