# 00-screen
# initialize values

# create default dialog settings file
dialog --create-rc ~/.dialogrc 2>/dev/null

# calculate screen size, e.g. "MaxSize: 24, 80"
dialog --print-maxsize 2>/tmp/maxsize
WM="$(cut -d' ' -f3 /tmp/maxsize)"  # Width Max,    e.g. "80"
HM="$(cut -d' ' -f2 /tmp/maxsize)"  # Height Max,   e.g. "24,"
HM="$(echo $HM | cut -d, -f1)"      # remove comma, e.g. "24"
rm -f /tmp/maxsize

# calculate good size of dialog boxes
W1="$((WM*70/100))"  # dialog box width  = 70% of screen width. E.g. 80 * 70% = 56
H1="$((HM*75/100))"  # dialog box height = 75% of screen height E.g. 24 * 75% = 18

# calculate positions for double-tailbox used by 02-installManifest & 35-rpm
W2=$(((WM-W1)/2))   # left margin = (TotalWidth - DialogWidth) / 2
H2=$((HM*40/100))   # height of each box is 40% of screen height
H3=$((HM*10/100))   # top position of box 1 at 10% of screen height
H4=$((HM*50/100-1)) # top position of box 2 at 50% of screen height

# global timeout value, in seconds, for all dialog boxes
TO=10
autoTO=2

# back title for dialog boxes
BT="SLOS Hardening"

DIALOG=${DIALOG=dialog}
: ${DIALOG_OK=0}
: ${DIALOG_CANCEL=1}
: ${DIALOG_HELP=2}
: ${DIALOG_EXTRA=3}
: ${DIALOG_ITEM_HELP=4}
: ${DIALOG_ESC=255}

: ${SIG_NONE=0}
: ${SIG_HUP=1}
: ${SIG_INT=2}
: ${SIG_QUIT=3}
: ${SIG_KILL=9}
: ${SIG_TERM=15}

: ${DIALOG=dialog}

mkdir -p /root/install
LOG="/root/install/security.log"
LOGERR="/root/install/LOG.err"
tempfile=$(tempfile 2>/dev/null) || tempfile=/tmp/test.tmp
# trap "rm -f $tempfile $LOG" 0 1 2 5 15

log() {
   echo "$@" >> $LOG
}

nolog() {
   echo "$@"
}

show() { 
   echo "$@" >> $LOG ; 
   echo "$@"; sleep .1;
}

logcmd()  { 
   echo "$@" >> $LOG 
   "$@" >> $LOG 2>&1 
}

error() {
   log "$@"
   $DIALOG --backtitle "$BT" --title INSTALLERROR --msgbox "Error: $@" $H1 $W1
   
   case "$ON_ERROR" in
      abort) abortInstall;;
      ask) $DIALOG --backtitle "$BT" --title INSTALLERROR --yesno "To Continue Installation?" $H1 $W1
         if [ $? -ne 0 ] ; then
            abortInstall
         fi
   ;;
      *) echo;; # Continue
   esac
}

errorAndWait() {
   log "ERROR: $@"
   $DIALOG --backtitle "$BT" --title INSTALLERROR --msgbox "Error: $@" $H1 $W1
   case "$ON_ERROR" in
      abort) abortInstall;;
      ask) $DIALOG --backtitle "$BT" --title INSTALLERROR --yesno "To Continue Installation?" $H1 $W1
         if [ $? -ne 0 ] ; then
            abortInstall
         fi
   ;;
      *) echo;; # Continue
   esac
}

showError()
{
    errorAndWait "$@"
}

warning() {
   log "$@"
   nolog "$@"
}

errorExit() {
   abortInstall
}

pause() {
   show "    Press <ENTER> to continue: "
   getenter
}

wipefiles() {
   shred -n 13 -z -u /tmp/slossec.conf /tmp/test$$ "$@" 2>/dev/null
}

