#!/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 -C > settings.cfg.orig

sed -e "s:^OSUSER=.*:OSUSER=cooldude:g" \
   -e "s:^OSGROUP=.*:OSGROUP=heroes:g" \
   -e "s:^P4USER=.*:P4USER=superman:g" \
   settings.cfg.orig > settings.cfg

./reset_sdp.sh -c settings.cfg -fast -no_ssl -no_sd -no_ppr 2>&1 | tee log.reset_sdp.test_settings.txt

msg "Checking that user superman got created, doing: id -u superman"
if id -u superman; then
   msg "User superman exists."
   exit 0
else
   msg "User superman does not exist."
   exit 1
fi
