#!/bin/bash
#
# uls_stop_maint
#
# ULS Ueberwachungspause updaten
#
# Aufruf: uls_stop_maint [<section> [<teststep> [<detail>]]]
#
##########################################################
#
ULSTIMESTAMPFILE="/var/tmp/uls_maint_suspension_timestamp-$(id -u).dat"
USERVERNAME=" ($(id -un))"
if [[ ! -f "$ULSTIMESTAMPFILE" ]]; then
  ULSTIMESTAMPFILE='/var/tmp/uls_maint_suspension_timestamp.dat'
  unset USERVERNAME
fi
#
if [[ "$1" == -* ]]; then
  echo "usage: $(basename $0) [<section> [<teststep> [<detail>]]]"
  exit
fi
#
if [[ -f "$ULSTIMESTAMPFILE" ]]; then
  DT=$(<"$ULSTIMESTAMPFILE")
else
  echo "Error: Timestampfile $ULSTIMESTAMPFILE not found."
  exit 1
fi
if echo "$DT" | grep -q	 '^[2-9][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]'; then
  #
  # ULS Ueberwachungspause aendern
  if [[ -f /etc/uls/uls.conf ]]; then
    . /etc/uls/uls.conf
  fi
  #
  DTE=`date -d '+15 minute' '+%F %T%:z'`
  echo "PC;$DT;$ULSHOSTNAME;${1:-*};$2;$3;$DTE;;;Set by uls_start_maint for patching$USERNAME" | send_test_tab -S
  rm -f "$ULSTIMESTAMPFILE"
  #
else
  echo "Error: Wrong timeformat in Timestampfile $ULSTIMESTAMPFILE."
  exit 1
fi
