# 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

# default timeout (seconds) for firstboot selection/input screens
FB_UI_TIMEOUT=30
# timeout for password entry screens in manual firstboot
PW_TO=$FB_UI_TIMEOUT
# timeout for auto-firstboot selection screens
AUTO_PICKUP_TO=$FB_UI_TIMEOUT
# global timeout for displaying values when doing auto-install
autoTO=2

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

DIALOG=${DIALOG=dialog}

mkdir -p /root/install
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 ; 
   echo "$@"; 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."
      $DIALOG --backtitle "$BT" --title "Exit Firstboot" --infobox "\n Exit Firstboot" $H1 $W1
      sleep .1
      abortInstall
   fi
}
