#!/bin/bash
#------------------------------------------------------------------------------
set -u

function msg () { echo -e "$*"; }
function errmsg () { msg "\\nError: ${1-Unknown Error}\\n"; ErrorCount+=1; }
function bail () { errmsg "${1-Unknown Error}"; exit "${2:-1}"; }

cd /hxdepots/reset || bail "Could not cd to: /hxdepots/reset"

if [[ -r reset_sdp.sh.txt ]]; then
   mv reset_sdp.sh.txt reset_sdp.sh
   chmod +x reset_sdp.sh
fi

./reset_sdp.sh -X -R 2>&1 | tee log.reset_sdp.test_cleanup.txt

if grep -q 'Extreme Cleanup complete. Stopping' log.reset_sdp.test_cleanup.txt; then
   msg "Found expected string in log.reset_sdp.test_cleanup.txt."
   exit 0
else
   msg "Did not find expected string in log.reset_sdp.test_cleanup.txt."
   exit 1
fi
