# 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 2>/dev/null || true

# 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

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

DIALOG=${DIALOG=dialog}

mkdir -p /root/install 2>/dev/null || true
LOG="/root/install/FirstBoot.log"
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 ; 
   sleep .1
}

wipefiles() {
   shred -u $* 2>/dev/null
}

# Input: dialog return code
# is user selected "<cancel>" button, then exit installer.
isCancel () {
   # 255=timeout, 1=cancel, 0=success
   if [ "$1" != "0" ] ; then
      log "Exiting Firstboot."
      abortInstall
   fi
}
