# 05-autoinst
# Auto-Install
# If file "/autoinst.conf" is found on CD media or PXE server, then the values
# in that file are used to answer prompts from the first boot scripts, thus 
# installing without user interaction.
# We prompt for a confirmation and give the user a reasonable timeout to 
# abort before we automatically proceed.

# Read the Security Configuration values
SECFILE=/etc/slossec.conf
[ -f "$SECFILE" ] && source "$SECFILE"
# are we auto-firstbooting?
if [ -e /etc/autoinst.conf ] ; then
   AUTOINST=/etc/autoinst.conf
   # source the auto-install config values to make them available to installer
   source $AUTOINST
   log "First-boot 05-autoinst found file $AUTOINST"

   $DIALOG \
     --timeout $AUTO_PICKUP_TO \
     --clear \
     --nocancel \
     --visit-items \
     --default-item "1" \
     --backtitle "$BT" \
     --title "Firstboot Mode" \
    --menu "\nDefault selection starts in $AUTO_PICKUP_TO seconds.\n\nSelect setup mode:\n " $H1 $W1 2 \
     1 "Auto configuration" \
     2 "Manual configuration" \
     2>$tempfile

   k=$(echo $?)
   a=$(cat $tempfile)
   # map timeout to 
   [ ${#a} -gt 2 ] || [ "$a" == "" ] && a="1" && k="0"

   # user selected auto firstboot (or timeout default)
   if [ "$a" == "1" ] ; then
     log "Continuing with auto-first-boot. Source $AUTOINST"
     $DIALOG --backtitle "$BT" --title "Firstboot" --infobox "\n Auto configuration selected.\n\nApplying DHCP IP and default password policy... " $H1 $W1
     sleep $autoTO

   # user selected manual firstboot
   elif [ "$a" == "2" ] ; then
     log "Disabling auto-first-boot."
     unset AUTOINST
     TO="0" # do not timeout of prompts if not auto-first-booting
     $DIALOG --backtitle "$BT" --title "Firstboot" --infobox "\n Manual configuration selected.\n\nManual configuration mode enabled..." $H1 $W1
     sleep 1

   # if none above, exit firstboot
   else
     FBExit
   fi
fi

