#!/bin/bash
# License: lgpl v2

# This is the Kevux Weird Installation script, known as KiWI
# The purpose of this script is to provide a simple installation for end-users using whatever resources are available
# This is called "Weird" because it combines a bunch of normally unrelated software and uses them to perform an installation process
#
# This program should be called without any arguments unless you know what you are doing
# This program will call itself with the appropriate arguments as needed

main(){
  public_name="Kevux Weird Installer (KiWI)"
  system_name=kiwi
  version=0.3.1
  umask 0027

  # ensure that the HOME variable is defined
  if [[ $HOME == "" ]] ; then
    export HOME=/home/users/$(whoami)
  fi

  # ensure that the PATH variable is defined
  if [[ $PATH == "" ]] ; then
    export PATH=/bin:/sbin:/toolchain/bin
  fi

  if [[ $KIWI_COLOR != "" ]] ; then
    export do_color=$KIWI_COLOR
  fi

  local password_buffer=
  local kiwi_install=kiwi.install
  local kiwi_settings=settings.install
  local kiwi_directory=/share/kiwi/
  local current_step_file=~/install.mode
  local current_mode=

  while [[ $count -lt $main_size ]] ; do
    i=${main_input[$count]}

    if [[ $grab_next == "" ]] ; then
      if [[ $i == "-h" || $i == "--help" ]] ; then
        do_help=yes
      elif [[ $i == "+n" || $i == "++no_color" ]] ; then
        do_color=none
      elif [[ $i == "+l" || $i == "++light" ]] ; then
        do_color=light
      elif [[ $i == "+v" || $i == "++version" ]] ; then
        echo $version
        return
      elif [[ $current_mode == "" ]] ; then
        current_mode=$i
      fi
    else
      grab_next=
    fi

    let count=$count+1
  done

  export KIWI_COLOR=$do_color
  standard_handle_colors

  if [[ $do_help != "" ]] ; then
    show_help
    return
  fi

  # start kiwi configure if any of the xorg dependencies are not available
  if [[ $current_mode == "" ]] ; then
    if [[ $(type -p kiwi_wm) == "" || $(type -p startx) == "" || $(type -p Xorg) == "" ]] ; then
      current_mode=configure
    fi
  fi

  if [[ $current_mode == "" ]] ; then
    perform_graphical_start
  elif [[ $current_mode != "" ]] ; then
    while [[ $current_mode != "" && $current_mode != "done" ]] ; do
      if [[ $current_mode == "configure" ]] ; then
        perform_configure
      elif [[ $current_mode == "install" ]] ; then
        if [[ $UID != "0" ]] ; then
          standard_error "Installation may only be done by the uid=0 (root) user"
          cleanup_main
          exit -1
        fi

        perform_install
      elif [[ $current_mode == "finished" ]] ; then
        perform_finished
      elif [[ $current_mode == "exit" ]] ; then
        exec bash -l
      elif [[ $current_mode == "reboot" ]] ; then
        perform_reboot
        break
      fi
    done
  else
    standard_error "Invalid Mode: $c_notice$current_mode"
    cleanup_main
    exit -1
  fi
}

show_help(){
  standard_help_title
  echo -e "$c_highlight$system_name$c_reset $c_notice[${c_reset}options$c_notice]$c_reset $c_notice[${c_reset}command$c_notice]$c_reset"
  echo -e "  ${c_important}configure${c_reset}    This mode will accept user input and save settings into ~/settings.install"
  echo -e "  ${c_important}install${c_reset}      This mode will process ~/settings.install and install the system"
  echo -e "  ${c_important}reboot${c_reset}       This mode is a convenice function for rebooting the system"
  echo
  standard_help_options
}

perform_graphical_start(){
  export WM="kiwi_wm"
  export WM_PROG=".kiwi_install"

  if [[ ! -e ~/$WM_PROG ]] ; then
    cp $kiwi_directory$kiwi_install ~/.kiwi_install
  fi

  startx

  if [[ $? -ne 0 ]] ; then
    print_error_line "ERROR: failed to start the graphical display"
    sleep 1
    ngc -u program/terminal
  fi
}

perform_configure(){
  local skip_to_install="no"
  local installation_type=

  clear
  echo
  echo -e "${c_title}Welcome to the KiWI Configure Screen$c_reset"
  echo -e "This is a step-by-step installer and will ask you a series of questions"
  echo -e "Most of the steps will required you to type in a number and press enter"
  echo
  echo -e "${c_notice}Press enter to begin${c_reset}"
  read input_buffer

  # mark the current step
  echo "configure" > $current_step_file

  if [[ ! -f ~/$kiwi_settings ]] ; then
    if [[ -f ${kiwi_directory}kiwi_settings.install ]] ; then
      cp ${kiwi_directory}kiwi_settings.install ~/$kiwi_settings
    else
      touch ~/$kiwi_settings
    fi
  fi

  input_buffer="0"

  # prompt for step by step or auto installation
  configure_system_prompt_installation_type

  if [[ $input_buffer == "1" || $input_buffer == "2" ]] ; then
    input_buffer="0"

    # step 1
    while [[ $input_buffer == "0" ]] ; do
      configure_system_information
    done

    if [[ $input_buffer == "-" ]] ; then
      return
    fi

    input_buffer="0"

    # step 2
    while [[ $input_buffer == "0" ]] ; do
      configure_user_information
    done

    if [[ $input_buffer == "-" ]] ; then
      return
    fi

    input_buffer="0"

    # step 3
    while [[ $input_buffer == "0" ]] ; do
      configure_destination_information
    done

    if [[ $input_buffer == "-" ]] ; then
      return
    fi
  fi

  # mark the next step
  current_mode="install"
  echo $current_mode > $current_step_file
}

configure_system_prompt_installation_type_header(){
  clear
  echo
  echo -e "${c_title}KiWI Configure Screen${c_reset}"
  echo -e "  ${c_notice}Configuration Mode${c_reset}"
  echo
}

configure_system_prompt_installation_type(){
  input_buffer=

  while [[ $input_buffer != "0" ]] ; do
    configure_system_prompt_installation_type_header

    echo -e "What configuration mode would you like to use?"
    echo -e "(1) Perform Quick Configuration (Recommended)"
    echo -e "(2) Perform Step-By-Step Configuration (Suggested)"
    echo -e "(3) Use Pre-created Configuration File (Advanced)"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "1" ]] ; then
      installation_type=quick
      break
    elif [[ $input_buffer == "2" ]] ; then
      installation_type=full
      break
    elif [[ $input_buffer == "3" ]] ; then
      current_mode="install"
      echo $current_mode > $current_step_file
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done
}

print_system_information_header(){
  clear
  echo
  echo -e "${c_title}System Information Settings${c_reset}"
  echo -e "  ${c_notice}Set $*${c_reset}"
  echo
}

configure_system_information(){
  local system_name="$(fss_extended_read -c 0 -n system_name ~/$kiwi_settings)"
  local system_clock="$(fss_extended_read -c 0 -n system_clock ~/$kiwi_settings)"
  local system_timezone="$(fss_extended_read -c 0 -n system_timezone ~/$kiwi_settings)"
  local system_clock_ntp_server="$(fss_extended_read -c 0 -n system_clock_ntp_server ~/$kiwi_settings)"
  local system_keymap="$(fss_extended_read -c 0 -n system_keymap ~/$kiwi_settings)"
  local b43_firmware_fix="$(fss_extended_read -c 0 -n b43_firmware_fix ~/$kiwi_settings)"

  # Use the live system name as a default if one is not set
  if [[ $system_name == "" ]] ; then
    if [[ $installation_type == "quick" ]] ; then
      system_name=computer.kevux
    else
      system_name=$(cat /etc/network/hostname)
    fi

    echo "system_name $system_name" >> ~/$kiwi_settings
  fi

  if [[ $system_clock == "" ]] ; then
    if [[ $installation_type == "quick" ]] ; then
      system_clock=ntpdate
    else
      system_clock=utc
    fi

    echo "system_clock $system_clock" >> ~/$kiwi_settings
  fi

  if [[ $system_timezone == "" ]] ; then
    if [[ $installation_type == "quick" ]] ; then
      system_timezone=CST6CDT
    else
      system_timezone=UTC
    fi

    echo "system_timezone $system_timezone" >> ~/$kiwi_settings
  fi

  # default to North America
  if [[ $system_clock_ntp_server == "" ]] ; then
    system_clock_ntp_server="0.north-america.pool.ntp.org"
    echo "system_clock_ntp_server $system_clock_ntp_server" >> ~/$kiwi_settings
  fi

  # default to qwerty
  if [[ $system_keymap == "" ]] ; then
    system_keymap=qwerty
    echo "system_keymap $system_keymap" >> ~/$kiwi_settings
  fi

  # default to no so that a network connection is not required by default
  if [[ $b43_firmware_fix == "" ]] ; then
    b43_firmware_fix=no
    echo "b43_firmware_fix $b43_firmware_fix" >> ~/$kiwi_settings
  fi

  input_buffer=

  while [[ $input_buffer != "0" && $installation_type != "quick" ]] ; do
    print_system_information_header "System Name"

    echo -e "Would you like to set the System Name, which currently is: '${c_notice}${system_name}${c_reset}'"
    echo -e "(1) Keep Current System Name"
    echo -e "(2) Set a New System Name"
    echo -e "(0) Reconfigure System Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      input_buffer=

      while [[ $input_buffer == "" ]] ; do
        echo
        echo -e "${c_notice}Enter in System Name and press enter:${c_reset}"
        print_input_line
        read input_buffer

        if [[ $(echo $input_buffer | grep -P -s -o '^(\d|\w)(\d|\w|-|_|)*((\.)(\d|\w)(\d|\w|-|_|)*)*') == "" ]] ; then
          print_error_line "ERROR: '$input_buffer' is not a system name, only letters, numbers, decimals, dashes, and underscores are allowed."
          input_buffer=
        fi
      done

      system_name=$(standard_to_lower $input_buffer)

      apply_this_setting "System Name" system_name "$system_name"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" && $installation_type != "quick" ]] ; do
    print_system_information_header "System Clock"

    echo -e "Set the system clock to UTC format or to local format, which currently is: '${c_notice}${system_clock}${c_reset}'"
    echo -e "(1) Keep Current System Clock Settings"
    echo -e "(2) System Clock to UTC (Recommended)"
    echo -e "(3) System Clock to local"
    echo -e "(4) System Clock to NTPDate (Suggested)"
    echo -e "(5) System Clock to NTP (Suggested)"
    echo -e "(0) Reconfigure System Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" || $input_buffer == "3" || $input_buffer == "4" || $input_buffer == "5" ]] ; then
      if [[ $input_buffer == "5" ]] ; then
        system_clock="ntp"
      elif [[ $input_buffer == "4" ]] ; then
        system_clock="ntpdate"
      elif [[ $input_buffer == "2" ]] ; then
        system_clock="utc"
      else
        system_clock="local"
      fi

      apply_this_setting "System Clock" system_clock "$system_clock"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  if [[ ( $system_clock == "ntp" || $system_clock == "ntpdate" ) && $installation_type != "quick" ]] ; then
    input_buffer=

    while [[ $input_buffer != "0" ]] ; do
      print_system_information_header "System Clock NTP Server"

      echo -e "Set the ntp server to use for initializing the system clock, which currently is: '${c_notice}${system_clock_ntp_server}${c_reset}'"
      echo -e "(1) Keep System Clock NTP Server Settings"
      echo -e "(2) NTP Server to Africa"
      echo -e "(3) NTP Server to Asia"
      echo -e "(4) NTP Server to Europe"
      echo -e "(5) NTP Server to Global (Recommended)"
      echo -e "(6) NTP Server to North America (Suggested)"
      echo -e "(7) NTP Server to Oceania"
      echo -e "(8) NTP Server to South America"
      echo -e "(9) Manually Specify NTP Server (Advanced)"
      echo -e "(0) Reconfigure System Information"
      echo -e "(-) Restart Configure Process"
      echo
      print_input_line
      read input_buffer

      if [[ $input_buffer == "0" ]] ; then
        return
      elif [[ $input_buffer == "-" ]] ; then
        current_mode=configure
        return
      elif [[ $input_buffer == "1" ]] ; then
        break
      elif [[ $input_buffer == "2" || $input_buffer == "3" ||  $input_buffer == "4"  ||  $input_buffer == "5" ||  $input_buffer == "6" ||  $input_buffer == "7" ||  $input_buffer == "8" ]] ; then
        if [[ $input_buffer == "2" ]] ; then
          system_clock_ntp_server="2.africa.pool.ntp.org"
        elif [[ $input_buffer == "3" ]] ; then
          system_clock_ntp_server="0.asia.pool.ntp.org"
        elif [[ $input_buffer == "4" ]] ; then
          system_clock_ntp_server="0.europe.pool.ntp.org"
        elif [[ $input_buffer == "5" ]] ; then
          system_clock_ntp_server="pool.ntp.org"
        elif [[ $input_buffer == "6" ]] ; then
          system_clock_ntp_server="0.north-america.pool.ntp.org"
        elif [[ $input_buffer == "7" ]] ; then
          system_clock_ntp_server="0.oceania.pool.ntp.org"
        else
          system_clock_ntp_server="0.south-america.pool.ntp.org"
        fi

        apply_this_setting "System Clock NTP Server" system_clock_ntp_server "$system_clock_ntp_server"
        break
      elif [[ $input_buffer == "9" ]] ; then
        system_clock_ntp_server=

        while [[ $system_clock_ntp_server == "" ]] ; do
          echo -e "Enter in the NTP Server address:"
          print_input_line
          read system_clock_ntp_server
        done

        apply_this_setting "System Clock NTP Server" system_clock_ntp_server "$system_clock_ntp_server"
      else
        print_error_line "ERROR: '$input_buffer' is not a valid option"
      fi
    done
  fi

  input_buffer=

  while [[ $input_buffer != "0" ]] ; do
    print_system_information_header "System Timezone"

    echo -e "Set the system timezone, which currently is: '${c_notice}${system_timezone}${c_reset}'"
    echo -e "(1) Keep Current System Timezone Settings"
    echo -e "(2) UTC"
    echo -e "(3) EST5 (U.S. Eastern)"
    echo -e "(4) CST6 (U.S. Central)"
    echo -e "(5) MST7 (U.S. Mountain)"
    echo -e "(6) PST8 (U.S. Pacific)"
    echo -e "(7) Manual Entry (Advanced)"
    echo -e "(0) Reconfigure System Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      system_timezone="UTC"
      apply_this_setting "System Timezone" system_timezone "$system_timezone"
      break
    elif [[ $input_buffer == "3" || $input_buffer == "4" || $input_buffer == "5"  || $input_buffer == "6" ]] ; then
      local current_option=$input_buffer
      local does_daylight="yes"

      while [[ $input_buffer != "0" ]] ; do
        print_system_information_header "Daylight Savings Time"

        echo -e "Do you follow daylight savings time"
        echo -e "(1) Yes"
        echo -e "(2) No"
        echo -e "(0) Reconfigure System Information"
        echo -e "(-) Restart Configure Process"
        echo
        print_input_line
        read input_buffer

        if [[ $input_buffer == "0" ]] ; then
          return
        elif [[ $input_buffer == "-" ]] ; then
          current_mode=configure
          return
        elif [[ $input_buffer == "1" || $input_buffer == "2" ]] ; then
          does_daylight=$input_buffer

          if [[ $current_option == "3" || $does_daylight == "yes" ]] ; then
            system_timezone="EST5EDT"
          elif [[ $current_option == "3" || $does_daylight == "no" ]] ; then
            system_timezone="EST5"
          elif [[ $current_option == "4" || $does_daylight == "yes" ]] ; then
            system_timezone="CST6CDT"
          elif [[ $current_option == "4" || $does_daylight == "no" ]] ; then
            system_timezone="CST6"
          elif [[ $current_option == "5" || $does_daylight == "yes" ]] ; then
            system_timezone="MST7MDT"
          elif [[ $current_option == "5" || $does_daylight == "no" ]] ; then
            system_timezone="MST7"
          elif [[ $current_option == "6" || $does_daylight == "yes" ]] ; then
            system_timezone="PST8PDT"
          elif [[ $current_option == "6" || $does_daylight == "no" ]] ; then
            system_timezone="PST8"
          fi
          break
        else
          print_error_line "ERROR: '$input_buffer' is not a valid option"
        fi
      done

      apply_this_setting "System Timezone" system_timezone "$system_timezone"
      break
    elif [[ $input_buffer == "7" ]] ; then
      echo
      echo -e "${c_notice}Enter in System Timezone and press enter:${c_reset}"
      print_input_line
      read input_buffer
      system_timezone=$input_buffer

      apply_this_setting "System Timezone" system_timezone "$system_timezone"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" && $installation_type != "quick" ]] ; do
    print_system_information_header "System Keymap"

    echo -e "Would you like to set the System Keymap, which currently is: '${c_notice}${system_keymap}${c_reset}'"
    echo -e "(1) Keep Current System Keymap"
    echo -e "(2) Use qwerty (Recommended)"
    echo -e "(3) Use dvorak"
    echo -e "(4) Use olpc"
    echo -e "(0) Reconfigure System Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" || $input_buffer == "3" || $input_buffer == "4" ]] ; then
      if [[ $input_buffer == "2" ]] ; then
        system_keymap="qwerty"
      elif [[ $input_buffer == "3" ]] ; then
        system_keymap="dvorak"
      elif [[ $input_buffer == "4" ]] ; then
        system_keymap="olpc"
      fi

      apply_this_setting "System Keymap" system_keymap "$system_keymap"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" && $installation_type != "quick" ]] ; do
    print_system_information_header "B43 Firmware Fix"

    echo -e "Attempt to perform b43 firmware fix (requires an internet connection), which currently is: '${c_notice}${b43_firmware_fix}${c_reset}'"
    echo -e "(1) Keep Current B43 Firmware Fix"
    echo -e "(2) Yes"
    echo -e "(3) No"
    echo -e "(0) Reconfigure System Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      b43_firmware_fix="yes"
      apply_this_setting "B43 Firmware Fix" b43_firmware_fix "$b43_firmware_fix"
      break
    elif [[ $input_buffer == "3" ]] ; then
      b43_firmware_fix="no"
      apply_this_setting "B43 Firmware Fix" b43_firmware_fix "$b43_firmware_fix"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done
}

print_user_information_header(){
  clear
  echo
  echo -e "${c_title}User Information Settings${c_reset}"
  echo -e "  ${c_notice}Set $*${c_reset}"
  echo
}

configure_user_information(){
  local root_user_name="$(fss_extended_read -c 0 -n root_user_name ~/$kiwi_settings)"
  local root_user_password="$(fss_extended_read -c 0 -n root_user_password ~/$kiwi_settings)"
  local admin_user_name="$(fss_extended_read -c 0 -n admin_user_name ~/$kiwi_settings)"
  local admin_user_password="$(fss_extended_read -c 0 -n admin_user_password ~/$kiwi_settings)"
  local root_autologin="$(fss_extended_read -c 0 -n root_autologin ~/$kiwi_settings)"
  local admin_autologin="$(fss_extended_read -c 0 -n admin_autologin ~/$kiwi_settings)"
  local additional_users="$(fss_extended_read -c 0 -n additional_users ~/$kiwi_settings)"
  local current_user_name=
  local current_user_group=
  local current_user_password=
  local i=

  # Enforce default settings for required fields
  if [[ $root_user_name == "" ]] ; then
    root_user_name="$(whoami)"
    echo "root_user_name $root_user_name" >> ~/$kiwi_settings
  fi

  if [[ $root_autologin == "" ]] ; then
    root_autologin="no"
    echo "root_autologin $root_autologin" >> ~/$kiwi_settings
  fi

  if [[ $admin_autologin == "" ]] ; then
    admin_autologin="yes"
    echo "admin_autologin $admin_autologin" >> ~/$kiwi_settings
  fi

  if [[ $additional_users == "" ]] ; then
    additional_users=0
    echo "additional_users $additional_users" >> ~/$kiwi_settings
  fi

  input_buffer=

  while [[ $input_buffer != "0" && $installation_type != "quick" ]] ; do
    print_user_information_header "Root User Name"

    echo -e "(Advanced) Would you like to set the Root User Name, which currently is: '${c_notice}${root_user_name}${c_reset}'"
    echo -e "(1) Keep Current Root User Name (Recommended)"
    echo -e "(2) Set a New Root User Name"
    echo -e "(0) Reconfigure User Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      input_buffer=

      while [[ $input_buffer == "" ]] ; do
        echo
        echo -e "${c_notice}Enter in Root User Name and press enter:${c_reset}"
        print_input_line
        read input_buffer
      done

      root_user_name=$(standard_to_lower $(standard_alpha_numeric $input_buffer))
      apply_this_setting "Root User Name" root_user_name "$root_user_name"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" && $installation_type != "quick" ]] ; do
    print_user_information_header "Root User Password"

    echo -e "Would you like to set the Root User Password?"
    echo -e "(1) Keep Current Root User Password"
    echo -e "(2) Set a New Root User Password (Recommended)"
    echo -e "(0) Reconfigure User Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      password_buffer=

      echo
      echo -e "${c_notice}Enter in Root User Password and press enter:${c_reset}"
      add_password_trick

      if [[ $? == "0" ]] ; then
        root_user_password=$password_buffer
        apply_this_setting_dont_show "Root User Password" root_user_password "$root_user_password"
        break
      else
        print_error_line "ERROR: Failed to set password"
      fi
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" && $installation_type != "quick" ]] ; do
    print_user_information_header "Root User Auto-Login"

    echo -e "Should the root user auto-login into the system, which currently is: '${c_notice}${root_autologin}${c_reset}'"
    echo -e "(1) Keep Current Root User Auto-Login Settings"
    echo -e "(2) Yes"
    echo -e "(3) No (Recommended)"
    echo -e "(0) Reconfigure User Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" || $input_buffer == "3" ]] ; then
      if [[ $input_buffer == "2" ]] ; then
        root_autologin=yes
        admin_autologin=no
      else
        root_autologin=no
      fi

      apply_this_setting "Root Auto-Login" root_autologin "$root_autologin"
      apply_this_setting "Admin Auto-Login" admin_autologin "$admin_autologin"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" ]] ; do
    print_user_information_header "Set Admin User (This is not the Root User)"

    echo -e "Would you like to add the admin user, which currently is: '${c_notice}${admin_user_name}${c_reset}'"
    echo -e "(1) Keep Current Administration User Settings"
    echo -e "(2) Add & Configure Administration User (Recommended)"
    echo -e "(3) Do Not Create An Administration User"
    echo -e "(0) Reconfigure User Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      input_buffer=

      while [[ $input_buffer == "" ]] ; do
        echo
        echo -e "${c_notice}Enter in Admin User Name and press enter:${c_reset}"
        print_input_line
        read input_buffer
      done

      admin_user_name=$(standard_to_lower $(standard_alpha_numeric $input_buffer))
      apply_this_setting "Admin User Name" admin_user_name "$admin_user_name"

      input_buffer=

      while [[ $input_buffer != "0" ]] ; do
        print_user_information_header "Admin User Password"

        echo -e "Would you like to set the Admin User Password?"
        echo -e "(1) Keep Current Admin User Password"
        echo -e "(2) Set a New Admin User Password (Recommended)"
        echo -e "(0) Reconfigure User Information"
        echo -e "(-) Restart Configure Process"
        echo
        print_input_line
        read input_buffer

        if [[ $input_buffer == "0" ]] ; then
          return
        elif [[ $input_buffer == "-" ]] ; then
          current_mode=configure
          return
        elif [[ $input_buffer == "1" ]] ; then
          break
        elif [[ $input_buffer == "2" ]] ; then
          password_buffer=

          echo
          echo -e "${c_notice}Enter in Admin User Password and press enter:${c_reset}"
          add_password_trick

          if [[ $? == "0" ]] ; then
            admin_user_password=$password_buffer
            apply_this_setting_dont_show "Admin User Password" admin_user_password "$admin_user_password"

            # quick installation will synchronize the root user password with the admin users password.
            if [[ $installation_type == "quick" ]] ; then
              root_user_password=$password_buffer
              apply_this_setting_dont_show "Root User Password" root_user_password "$root_user_password" 0
            fi
            break
          else
            print_error_line "ERROR: Failed to set password"
          fi
        else
          print_error_line "ERROR: '$input_buffer' is not a valid option"
        fi
      done

      input_buffer=

      if [[ $admin_autologin == "" && $installation_type == "quick" ]] ; then
        admin_autologin=yes
        apply_this_setting_dont_show "Admin Auto-Login" admin_autologin "$admin_autologin" 0
      fi

      while [[ $input_buffer != "0" && $installation_type != "quick" ]] ; do
        print_user_information_header "Admin User Auto-Login"

        echo -e "Should the admin user auto-login into the system, which currently is: '${c_notice}${admin_autologin}${c_reset}'"
        echo -e "(1) Keep Current Admin User Auto-Login Settings"
        echo -e "(2) Yes (Recommended)"
        echo -e "(3) No (Suggested)"
        echo -e "(0) Reconfigure User Information"
        echo -e "(-) Restart Configure Process"
        echo
        print_input_line
        read input_buffer

        if [[ $input_buffer == "0" ]] ; then
          return
        elif [[ $input_buffer == "-" ]] ; then
          current_mode=configure
          return
        elif [[ $input_buffer == "1" ]] ; then
          break
        elif [[ $input_buffer == "2" || $input_buffer == "3" ]] ; then
          if [[ $input_buffer == "2" ]] ; then
            admin_autologin=yes
            root_autologin=no
          else
            admin_autologin=no
          fi

          apply_this_setting "Admin Auto-Login" admin_autologin "$admin_autologin"
          apply_this_setting "Root Auto-Login" root_autologin "$root_autologin"
          break
        else
          print_error_line "ERROR: '$input_buffer' is not a valid option"
        fi
      done

      break
    elif [[ $input_buffer == "3" ]] ; then
      admin_user_name=
      admin_user_password=

      apply_this_setting "Admin User Name" admin_user_name "$admin_user_name"
      apply_this_setting_dont_show "Admin User Password" admin_user_password "$admin_user_password"
      apply_this_setting "Admin Auto-Login" admin_autologin "no"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" ]] ; do
    print_user_information_header "Additional Users"

    echo -e "Would you like to add additional users and how many would you like to add, which currently is: '${c_notice}${additional_users}${c_reset}'"
    echo -e "(1) Keep Current Additional Users Settings"
    echo -e "(2) Do not add any additional users (Suggested)"
    echo -e "(3) Add additional users"
    echo -e "(0) Reconfigure User Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      additional_users=0
      apply_this_setting "Additional Users" additional_users "$additional_users"
      break
    elif [[ $input_buffer == "3" ]] ; then
      input_buffer=

      while [[ $input_buffer == "" || ! $input_buffer -gt 0 ]] ; do
        echo -e "How many additional users would you like to add?"
        echo
        print_input_line
        read input_buffer
      done

      additional_users=$input_buffer
      apply_this_setting "Additional Users" additional_users "$additional_users"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=
  let i=0

  while [[ $input_buffer != "0" && $additional_users -gt 0 && $i -lt $additional_users ]] ; do
    current_user_name="$(fss_extended_read -c 0 -n additional_user_name_$i ~/$kiwi_settings)"
    current_user_group="$(fss_extended_read -c 0 -n additional_user_group_$i ~/$kiwi_settings)"
    current_user_password="$(fss_extended_read -c 0 -n additional_user_password_$i ~/$kiwi_settings)"

    while [[ $input_buffer != "0" ]] ; do
      print_user_information_header "User #$i Name"

      echo -e "What is the name for user #$i, which currently is: '${c_notice}${current_user_name}${c_reset}'"
      echo -e "(1) Keep Current Name for User #$i"
      echo -e "(2) Set a New Name for User #$i"
      echo -e "(0) Reconfigure User Information"
      echo -e "(-) Restart Configure Process"
      echo
      print_input_line
      read input_buffer

      if [[ $input_buffer == "0" ]] ; then
        return
      elif [[ $input_buffer == "-" ]] ; then
        current_mode=configure
        return
      elif [[ $input_buffer == "1" ]] ; then
        break
      elif [[ $input_buffer == "2" ]] ; then
        input_buffer=

        while [[ $input_buffer == "" ]] ; do
          echo
          echo -e "${c_notice}Enter in User #$i Name and press enter:${c_reset}"
          print_input_line
          read input_buffer
        done

        current_user_name=$(standard_to_lower $(standard_alpha_numeric $input_buffer))
        apply_this_setting "User #$i Name" additional_user_name_$i "$current_user_name"
        break
      else
        print_error_line "ERROR: '$input_buffer' is not a valid option"
      fi
    done

    input_buffer=

    while [[ $input_buffer != "0" ]] ; do
      print_user_information_header "User #$i System Group"

      echo -e "What is the system group for user #$i, which currently is: '${c_notice}${current_user_group}${c_reset}'"
      echo -e "(1) Keep Current System Group for User #$i"
      echo -e "(2) Desktop"
      echo -e "(3) Power"
      echo -e "(4) Admin"
      echo -e "(5) Custom (Advanced)"
      echo -e "(0) Reconfigure User Information"
      echo -e "(-) Restart Configure Process"
      echo
      print_input_line
      read input_buffer

      if [[ $input_buffer == "0" ]] ; then
        return
      elif [[ $input_buffer == "-" ]] ; then
        current_mode=configure
        return
      elif [[ $input_buffer == "1" ]] ; then
        break
      elif [[ $input_buffer == "2" || $input_buffer == "3" || $input_buffer == "4" ]] ; then
        if [[ $input_buffer == "2" ]] ; then
          current_user_group="desktop"
        elif [[ $input_buffer == "3" ]] ; then
          current_user_group="power"
        elif [[ $input_buffer == "4" ]] ; then
          current_user_group="admin"
        fi

        apply_this_setting "User #$i System Group" additional_user_group_$i "$current_user_group"
        break
      elif [[ $input_buffer == "5" ]] ; then
        input_buffer=

        while [[ $input_buffer == "" ]] ; do
          echo
          echo -e "${c_notice}Enter in User #$i System Group and press enter:${c_reset}"
          print_input_line
          read input_buffer
        done

        current_user_group=$input_buffer
        apply_this_setting "User #$i System Group" additional_user_group_$i "$current_user_group"
        break
      else
        print_error_line "ERROR: '$input_buffer' is not a valid option"
      fi
    done

    input_buffer=

    while [[ $input_buffer != "0" ]] ; do
      print_user_information_header "User #$i Password"

      echo -e "Would you like to set the User #$i Password?"
      echo -e "(1) Keep Current Password for User #$i"
      echo -e "(2) Set a New Password for User #$i (Recommended)"
      echo -e "(0) Reconfigure User Information"
      echo -e "(-) Restart Configure Process"
      echo
      print_input_line
      read input_buffer

      if [[ $input_buffer == "0" ]] ; then
        return
      elif [[ $input_buffer == "-" ]] ; then
        current_mode=configure
        return
      elif [[ $input_buffer == "1" ]] ; then
        break
      elif [[ $input_buffer == "2" ]] ; then
        password_buffer=

        echo
        echo -e "${c_notice}Enter in User #$i Password and press enter:${c_reset}"
        add_password_trick

        if [[ $? == "0" ]] ; then
          current_user_password=$password_buffer
          apply_this_setting_dont_show "User #$i Password" additional_user_password_$i "$current_user_password"
          break
        else
          print_error_line "ERROR: Failed to set password"
        fi
      else
        print_error_line "ERROR: '$input_buffer' is not a valid option"
      fi
    done

    let i=$i+1
  done
}

print_destination_information_header(){
  clear
  echo
  echo -e "${c_title}Destination Information Settings${c_reset}"
  echo -e "  ${c_notice}Set $*${c_reset}"
  echo
}

print_invalid_variables_header(){
  clear
  echo
  echo -e "${c_title}Invalid Settings Detected${c_reset}"
  echo -e "  ${c_notice}Cannot Install${c_reset}"
  echo
}

print_installation_header(){
  clear
  echo
  echo -e "${c_title}Welcome to the KiWI Installation Screen${c_reset}"
  echo -e "  ${c_notice}$*${c_reset}"
  echo
}

print_installation_error_header(){
  if [[ $1 == "noclear" ]] ; then
    echo
  else
    clear
  fi

  echo
  echo -e "${c_title}Error During Installation${c_reset}"
  echo -e "  ${c_notice}Cannot Install${c_reset}"
  echo
}

configure_destination_information(){
  local destination_schema="$(fss_extended_read -c 0 -n destination_schema ~/$kiwi_settings)"
  local destination_subschema="$(fss_extended_read -c 0 -n destination_subschema ~/$kiwi_settings)"
  local separate_boot_partition="$(fss_extended_read -c 0 -n separate_boot_partition ~/$kiwi_settings)"
  local separate_home_partition="$(fss_extended_read -c 0 -n separate_home_partition ~/$kiwi_settings)"
  local boot_partition="$(fss_extended_read -c 0 -n boot_partition ~/$kiwi_settings)"
  local root_partition="$(fss_extended_read -c 0 -n root_partition ~/$kiwi_settings)"
  local home_partition="$(fss_extended_read -c 0 -n home_partition ~/$kiwi_settings)"
  local root_partition_is_encrypted="$(fss_extended_read -c 0 -n root_partition_is_encrypted ~/$kiwi_settings)"
  local home_partition_is_encrypted="$(fss_extended_read -c 0 -n home_partition_is_encrypted ~/$kiwi_settings)"
  local encrypted_root_partition="$(fss_extended_read -c 0 -n encrypted_root_partition ~/$kiwi_settings)"
  local encrypted_home_partition="$(fss_extended_read -c 0 -n encrypted_home_partition ~/$kiwi_settings)"
  local root_partition_decryption_method="$(fss_extended_read -c 0 -n root_partition_decryption_method ~/$kiwi_settings)"
  local home_partition_decryption_method="$(fss_extended_read -c 0 -n home_partition_decryption_method ~/$kiwi_settings)"
  local install_boot_loader="$(fss_extended_read -c 0 -n install_boot_loader ~/$kiwi_settings)"
  local squish_squash_method="$(fss_extended_read -c 0 -n squish_squash_method ~/$kiwi_settings)"
  local rootfs_subroot_path="$(fss_extended_read -c 0 -n rootfs_subroot_path ~/$kiwi_settings)"
  local squish_squash_path="$(fss_extended_read -c 0 -n squish_squash_path ~/$kiwi_settings)"
  local get_function_result=

  # enforce non-empty defaults for required fields
  if [[ $destination_schema == "" ]] ; then
    if [[ $installation_type == "quick" ]] ; then
      destination_schema=standard
      apply_this_setting_dont_show "Destination Schema" destination_schema "$destination_schema" 0

      separate_boot_partition=yes
      apply_this_setting_dont_show "Separate Boot Partition" separate_boot_partition "$separate_boot_partition" 0

      separate_home_partition=yes
      apply_this_setting_dont_show "Separate Home Partition" separate_home_partition "$separate_home_partition" 0

      squish_squash_method=device
      apply_this_setting_dont_show "Live Method" squish_squash_method "$squish_squash_method" 0

      squish_or_squash=squish
      apply_this_setting_dont_show "Squish / Squash Method" squish_or_squash "$squish_or_squash" 0

      rootfs_subroot_path=.system
      apply_this_setting_dont_show "Rootfs Subroot Path" rootfs_subroot_path "$rootfs_subroot_path" 0

      squish_squash_path=boot/live/
      apply_this_setting_dont_show "Squish / Squash Path" squish_squash_path "$squish_squash_path" 0
    else
      destination_schema=standard
      apply_this_setting_dont_show "Destination Schema" destination_schema "$destination_schema" 0

      separate_boot_partition=no
      apply_this_setting_dont_show "Separate Boot Partition" separate_boot_partition "$separate_boot_partition" 0

      separate_home_partition=no
      apply_this_setting_dont_show "Separate Home Partition" separate_home_partition "$separate_home_partition" 0

      squish_squash_method=device
      apply_this_setting_dont_show "Live Method" squish_squash_method "$squish_squash_method" 0

      squish_or_squash=squish
      apply_this_setting_dont_show "Squish / Squash Method" squish_or_squash "$squish_or_squash" 0

      squish_squash_path=boot/live/
      apply_this_setting_dont_show "Squish / Squash Path" squish_squash_path "$squish_squash_path" 0
    fi
  fi

  if [[ $root_partition_is_encrypted == "" ]] ; then
    root_partition_is_encrypted=no
    echo "root_partition_is_encrypted $root_partition_is_encrypted" >> ~/$kiwi_settings
  fi

  if [[ $home_partition_is_encrypted == "" ]] ; then
    home_partition_is_encrypted=no
    echo "home_partition_is_encrypted $home_partition_is_encrypted" >> ~/$kiwi_settings
  fi

  if [[ $install_boot_loader == "" ]] ; then
    install_boot_loader=all
    echo "install_boot_loader $install_boot_loader" >> ~/$kiwi_settings
  fi

  if [[ $squish_squash_method == "" ]] ; then
    squish_squash_method=device
    echo "squish_squash_method $squish_squash_method" >> ~/$kiwi_settings
  fi

  if [[ $squish_or_squash == "" ]] ; then
    squish_or_squash=squish
    echo "squish_or_squash $squish_or_squash" >> ~/$kiwi_settings
  fi

  input_buffer=

  while [[ $input_buffer != "0" && $installation_type != "quick" ]] ; do
    print_destination_information_header "Destination Schema"

    echo -e "What destination schema do you wish to use, which currently is: '${c_notice}${destination_schema}${c_reset}'"
    echo -e "(1) Keep Current Destination Schema"
    echo -e "(2) Use Standard Schema (Recommended)"
    echo -e "(3) Use Classic Schema"
    echo -e "(4) Use Simple Schema (Suggested)"
    echo -e "(5) Use Custom Schema (Advanced)"
    echo -e "(0) Reconfigure Destination Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" || $input_buffer == "3" || $input_buffer == "4" || $input_buffer == "5" ]] ; then
     if [[ $input_buffer == "2" ]] ; then
        destination_schema=standard
        separate_boot_partition=yes
        separate_home_partition=yes
      elif [[ $input_buffer == "3" ]] ; then
        destination_schema=classic
        separate_boot_partition=yes
        separate_home_partition=yes
      elif [[ $input_buffer == "4" ]] ; then
        destination_schema=simple
        separate_boot_partition=no
        separate_home_partition=no
      elif [[ $input_buffer == "5" ]] ; then
        destination_schema=custom
      fi

      apply_this_setting "Schema" destination_schema "$destination_schema"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" ]] ; do
    print_destination_information_header "Live Method"

    echo -e "What live method do you want to use, which currently is: '${c_notice}${squish_squash_method}${c_reset}'"
    echo -e "(1) Keep Current Live Method Setting"
    echo -e "(2) None"
    echo -e "(3) Device (Recommended)"
    echo -e "(4) Memory (Suggested)"
    echo -e "(5) Extract"
    echo -e "(0) Reconfigure Destination Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      squish_squash_method=none
      apply_this_setting "Live Method" squish_squash_method "$squish_squash_method"
      break
    elif [[ $input_buffer == "3" || $input_buffer == "4" || $input_buffer == "5" ]] ; then
      if [[ $input_buffer == "3" ]] ; then
        squish_squash_method=device
      elif [[ $input_buffer == "4" ]] ; then
        squish_squash_method=memory
      elif [[ $input_buffer == "5" ]] ; then
        squish_squash_method=extract
      fi

      apply_this_setting "Live Method" squish_squash_method "$squish_squash_method"

      input_buffer=

      while [[ $input_buffer != "0" ]] ; do
        print_destination_information_header "Squish / Squash Method"

        echo -e "Do you want to use squish method or the squash method, which currently is: '${c_notice}${squish_or_squash}${c_reset}'"
        echo -e "(1) Keep Current Squish / Squash Method Setting"
        echo -e "(2) Use Squish Method"
        echo -e "(3) Use Squash Method"
        echo -e "(0) Reconfigure Destination Information"
        echo -e "(-) Restart Configure Process"
        echo
        print_input_line
        read input_buffer

        if [[ $input_buffer == "0" ]] ; then
          return
        elif [[ $input_buffer == "-" ]] ; then
          current_mode=configure
          return
        elif [[ $input_buffer == "1" ]] ; then
          break
        elif [[ $input_buffer == "2" ]] ; then
          squish_or_squash=squish
          apply_this_setting "Squish / Squash Method" squish_or_squash "$squish_or_squash"
          break
        elif [[ $input_buffer == "3" ]] ; then
          squish_or_squash=squash
          apply_this_setting "Squish / Squash Method" squish_or_squash "$squish_or_squash"
          break
        else
          print_error_line "ERROR: '$input_buffer' is not a valid option"
        fi
      done

      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  if [[ $destination_schema == "custom" && $installation_type != "quick" ]] ; then
    input_buffer=

    while [[ $input_buffer != "0" ]] ; do
      print_destination_information_header "Separate Boot Partition"

      echo -e "Will you be using a separate boot partition, which currently is: '${c_notice}${separate_boot_partition}${c_reset}'"
      echo -e "(1) Keep Current Separate Boot Partition Setting"
      echo -e "(2) Yes"
      echo -e "(3) No"
      echo -e "(0) Reconfigure Destination Information"
      echo -e "(-) Restart Configure Process"
      echo
      print_input_line
      read input_buffer

      if [[ $input_buffer == "0" ]] ; then
        return
      elif [[ $input_buffer == "-" ]] ; then
        current_mode=configure
        return
      elif [[ $input_buffer == "1" ]] ; then
        break
      elif [[ $input_buffer == "2" ]] ; then
        separate_boot_partition=yes
        apply_this_setting "Separate Boot Partition" separate_boot_partition "$separate_boot_partition"
        break
      elif [[ $input_buffer == "3" ]] ; then
        separate_boot_partition=no
        apply_this_setting "Separate Boot Partition" separate_boot_partition "$separate_boot_partition"
        break
      else
        print_error_line "ERROR: '$input_buffer' is not a valid option"
      fi
    done

    input_buffer=

    while [[ $input_buffer != "0" ]] ; do
      print_destination_information_header "Separate Home Partition"

      echo -e "Will you be using a separate home partition, which currently is: '${c_notice}${separate_home_partition}${c_reset}'"
      echo -e "(1) Keep Current Separate Home Partition Setting"
      echo -e "(2) Yes"
      echo -e "(3) No"
      echo -e "(0) Reconfigure Destination Information"
      echo -e "(-) Restart Configure Process"
      echo
      print_input_line
      read input_buffer

      if [[ $input_buffer == "0" ]] ; then
        return
      elif [[ $input_buffer == "-" ]] ; then
        current_mode=configure
        return
      elif [[ $input_buffer == "1" ]] ; then
        break
      elif [[ $input_buffer == "2" ]] ; then
        separate_home_partition=yes
        apply_this_setting "Separate Home Partition" separate_home_partition "$separate_home_partition"
        break
      elif [[ $input_buffer == "3" ]] ; then
        separate_home_partition=no
        apply_this_setting "Separate Home Partition" separate_home_partition "$separate_home_partition"
        break
      else
        print_error_line "ERROR: '$input_buffer' is not a valid option"
      fi
    done
  fi

  if [[ $separate_boot_partition == "yes" ]] ; then
    get_function_result=
    get_partition_information "Boot" boot "$boot_partition"

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer != "1" ]] ; then
      boot_partition=$get_function_result
      apply_this_setting "Boot Partition" boot_partition "$boot_partition"
    fi
  fi

  if [[ $separate_home_partition == "yes" && $destination_schema != "standard" ]] ; then
    get_function_result=
    get_partition_information "Home" home "$home_partition"

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer != "1" ]] ; then
      home_partition=$get_function_result
      apply_this_setting "Home Partition" home_partition "$home_partition"
    fi

    input_buffer=

    while [[ $input_buffer != "0" ]] ; do
      print_destination_information_header "Home Partition is Encrypted"

      echo -e "Will your home partition be encrypted, which currently is: '${c_notice}${home_partition_is_encrypted}${c_reset}'"
      echo -e "(1) Keep Home Partition is Encrypted Setting"
      echo -e "(2) Yes"
      echo -e "(3) No"
      echo -e "(0) Reconfigure Destination Information"
      echo -e "(-) Restart Configure Process"
      echo
      print_input_line
      read input_buffer

      if [[ $input_buffer == "0" ]] ; then
        return
      elif [[ $input_buffer == "-" ]] ; then
        current_mode=configure
        return
      elif [[ $input_buffer == "1" ]] ; then
        break
      elif [[ $input_buffer == "2" ]] ; then
        home_partition_is_encrypted=yes
        apply_this_setting "Home Partition is Encrypted" home_partition_is_encrypted "$home_partition_is_encrypted"

        get_function_result=
        get_partition_information "Encrypted Home" "encrypted home" "$encrypted_home_partition"

        if [[ $input_buffer == "0" ]] ; then
          return
        elif [[ $input_buffer == "-" ]] ; then
          current_mode=configure
          return
        elif [[ $input_buffer != "1" ]] ; then
          encrypted_home_partition=$get_function_result
          apply_this_setting "Encrypted Home Partition" encrypted_home_partition "$encrypted_home_partition"
        fi

        get_function_result=
        get_encryption_information "Home" home "$home_partition_decryption_method"

        if [[ $input_buffer == "0" ]] ; then
          return
        elif [[ $input_buffer == "-" ]] ; then
          current_mode=configure
          return
        elif [[ $input_buffer != "1" ]] ; then
          home_partition_decryption_method=$get_function_result
          apply_this_setting "Home Partition Decryption Method" home_partition_decryption_method "$home_partition_decryption_method"
        fi

        break
      elif [[ $input_buffer == "3" ]] ; then
        home_partition_is_encrypted=no
        apply_this_setting "Home Partition is Encrypted" home_partition_is_encrypted "$home_partition_is_encrypted"
        break
      else
        print_error_line "ERROR: '$input_buffer' is not a valid option"
      fi
    done
  fi

  get_function_result=
  get_partition_information "Root" root "$root_partition"

  if [[ $input_buffer == "0" ]] ; then
    return
  elif [[ $input_buffer == "-" ]] ; then
    current_mode=configure
    return
  elif [[ $input_buffer != "1" ]] ; then
    root_partition=$get_function_result
    apply_this_setting "Root Partition" root_partition "$root_partition"

    if [[ $destination_schema == "standard" ]] ; then
      home_partition=$get_function_result
      apply_this_setting_dont_show "Home Partition" home_partition "$home_partition" 0
    fi
  fi

  input_buffer=

  while [[ $input_buffer != "0" ]] ; do
    print_destination_information_header "Root Partition is Encrypted"

    echo -e "Will your root partition be encrypted, which currently is: '${c_notice}${root_partition_is_encrypted}${c_reset}'"
    echo -e "(1) Keep Root Partition is Encrypted Setting"
    echo -e "(2) Yes"
    echo -e "(3) No"
    echo -e "(0) Reconfigure Destination Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      root_partition_is_encrypted=yes
      apply_this_setting "Root Partition is Encrypted" root_partition_is_encrypted "$root_partition_is_encrypted"

      if [[ $destination_schema == "standard" ]] ; then
        home_partition_is_encrypted=yes
        apply_this_setting_dont_show "Home Partition is Encrypted" home_partition_is_encrypted "$home_partition_is_encrypted" 0
      fi

      get_function_result=
      get_partition_information "Encrypted Root" "encrypted root" "$encrypted_root_partition"

      if [[ $input_buffer == "0" ]] ; then
        return
      elif [[ $input_buffer == "-" ]] ; then
        current_mode=configure
        return
      elif [[ $input_buffer != "1" ]] ; then
        encrypted_root_partition=$get_function_result
        apply_this_setting "Encrypted Root Partition" encrypted_root_partition "$encrypted_root_partition"

        if [[ $destination_schema == "standard" ]] ; then
          encrypted_home_partition=$get_function_result
          apply_this_setting_dont_show "Encrypted Home Partition" encrypted_home_partition "$encrypted_home_partition" 0
        fi
      fi

      get_function_result=
      get_encryption_information "Root" root "$root_partition_decryption_method"

      if [[ $input_buffer == "0" ]] ; then
        return
      elif [[ $input_buffer == "-" ]] ; then
        current_mode=configure
        return
      elif [[ $input_buffer != "1" ]] ; then
        root_partition_decryption_method=$get_function_result
        apply_this_setting "Root Partition Decryption Method" root_partition_decryption_method "$root_partition_decryption_method"

        if [[ $destination_schema == "standard" ]] ; then
          home_partition_decryption_method=$get_function_result
          apply_this_setting_dont_show "Home Partition Decryption Method" home_partition_decryption_method "$home_partition_decryption_method" 0
        fi
      fi

      break
    elif [[ $input_buffer == "3" ]] ; then
      root_partition_is_encrypted=no
      apply_this_setting "Root Partition is Encrypted" root_partition_is_encrypted "$root_partition_is_encrypted"

      if [[ $destination_schema == "standard" ]] ; then
        home_partition_is_encrypted=no
        apply_this_setting_dont_show "Home Partition is Encrypted" home_partition_is_encrypted "$home_partition_is_encrypted" 0
      fi

      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" && $installation_type != "quick" ]] ; do
    print_destination_information_header "Rootfs Subroot Path"

    echo -e "Is your system installed in a subroot on the rootfs, which currently is: '${c_notice}${rootfs_subroot_path}${c_reset}'"
    echo -e "(1) Keep Current Rootfs Subroot Path Setting"
    echo -e "(2) Yes"
    echo -e "(3) No"
    echo -e "(0) Reconfigure Destination Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      input_buffer=

      while [[ $input_buffer == "" ]] ; do
        echo
        echo -e "${c_notice}Enter in the subroot path and press enter:${c_reset}"
        read input_buffer
        rootfs_subroot_path=$(echo $input_buffer | sed -e 's|^/*||' -e 's|/*$|/|')
      done

      if [[ $rootfs_subroot_path == "/" ]] ; then
        rootfs_subroot_path=
      fi

      apply_this_setting "Rootfs Subroot Path" rootfs_subroot_path "$rootfs_subroot_path"
      break
    elif [[ $input_buffer == "3" ]] ; then
      rootfs_subroot_path=
      apply_this_setting "Rootfs Subroot Path" rootfs_subroot_path "$rootfs_subroot_path"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" && $installation_type != "quick" && $squish_squash_method != "none" ]] ; do
    print_destination_information_header "Squish/Squash Path"

    echo -e "Where should your squish/squash files be placed, which currently is: '${c_notice}${squish_squash_path}${c_reset}'"
    echo -e "(1) Keep Current Squish/Squash Path Setting"
    echo -e "(2) Change Squish/Squash Path (Advanced)"
    echo -e "(0) Reconfigure Destination Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      input_buffer=

      while [[ $input_buffer == "" ]] ; do
        echo
        echo -e "${c_notice}Enter in the squish/squash path and press enter:${c_reset}"
        read input_buffer
        squish_squash_path=$(echo $input_buffer | sed -e 's|^/*||' -e 's|/*$|/|')
      done

      if [[ $squish_squash_path == "/" ]] ; then
        squish_squash_path=boot/live/
      fi

      apply_this_setting "Squish/Squash Path" squish_squash_path "$squish_squash_path"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  input_buffer=

  while [[ $input_buffer != "0" ]] ; do
    print_destination_information_header "Install Boot Loader"

    echo -e "Do you want the boot loader to be installed, which currently is: '${c_notice}${install_boot_loader}${c_reset}'"
    echo -e "(1) Keep Boot Loader Setting"
    echo -e "(2) All Boot Loader Settings (Recommended)"
    echo -e "(3) Only Grub Boot Loader"
    echo -e "(4) Only Boot Loader Files"
    echo -e "(5) Neither Boot Loader nor Boot Loader Files (Advanced)"
    echo -e "(0) Reconfigure Destination Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "2" ]] ; then
      install_boot_loader=all
      apply_this_setting "Install Boot Loader" install_boot_loader "$install_boot_loader"
      break
    elif [[ $input_buffer == "3" ]] ; then
      install_boot_loader=grub
      apply_this_setting "Install Boot Loader" install_boot_loader "$install_boot_loader"
      break
    elif [[ $input_buffer == "4" ]] ; then
      install_boot_loader=files
      apply_this_setting "Install Boot Loader" install_boot_loader "$install_boot_loader"
      break
    elif [[ $input_buffer == "5" ]] ; then
      install_boot_loader=none
      apply_this_setting "Install Boot Loader" install_boot_loader "$install_boot_loader"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done
}

get_partition_information(){
  local partition_label=$1
  local partition_name=$2
  local partition_data=$3
  local partition_input=
  input_buffer=

  while [[ $input_buffer != "0" ]] ; do
    print_destination_information_header "$partition_label Partition"

    echo -e "What will be the $partition_name partition, which currently is: '${c_notice}${partition_data}${c_reset}'"
    echo -e "(1) Keep Current $partition_label Partition"
    echo -e "(2) Specify By Path (Advanced)"
    echo -e "(3) Specify By Label (Recommended)"
    echo -e "(4) Specify By UUID"
    echo -e "(0) Reconfigure Destination Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      if [[ $partition_data != "" ]] ; then
        get_function_result=$partition_data
        break
      fi

      print_error_line "ERROR: Current partition settings for $partition_name partition is empty and cannot be empty, therefore you cannot use the current setting."
    elif [[ $input_buffer == "2" ]] ; then
      echo
      echo -e "${c_notice}Enter in $partition_label Partition Path and press enter:${c_reset}"
      read partition_input
      get_function_result=$partition_input
      break
    elif [[ $input_buffer == "3" ]] ; then
      echo
      echo -e "${c_notice}Enter in $partition_label Partition Label and press enter:${c_reset}"
      read partition_input
      get_function_result="$partition_input"
      break
    elif [[ $input_buffer == "4" ]] ; then
      echo
      echo -e "${c_notice}Enter in $partition_label Partition UUID and press enter:${c_reset}"
      read partition_input
      get_function_result="$partition_input"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done
}

get_encryption_information(){
  local partition_label=$1
  local partition_name=$2
  local partition_data=$3
  local partition_input=
  input_buffer=

  while [[ $input_buffer != "0" ]] ; do
    print_destination_information_header "$partition_label Partition Decryption Method"

    echo -e "What method of decryption will be used on the $partition_name partition, current setting is: '${c_notice}${partition_data}${c_reset}'"
    echo -e "(1) Keep Current $partition_label Decryption Method"
    echo -e "(2) Use Key File"
    echo -e "(3) Use Password (Recommended)"
    echo -e "(0) Reconfigure Destination Information"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "0" ]] ; then
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    elif [[ $input_buffer == "1" ]] ; then
      if [[ $partition_date != "" ]] ; then
        get_function_result="$partition_data"
        break
      fi

      print_error_line "ERROR: Current decryption method for $partition_name device is empty and cannot be empty, therefore you cannot use the current setting."
    elif [[ $input_buffer == "2" ]] ; then
      echo
      echo -e "${c_notice}Enter in $partition_label device decryption file name and press enter:${c_reset}"
      read partition_input
      get_function_result="use_file=$partition_input"
      break
    elif [[ $input_buffer == "3" ]] ; then
      get_function_result="use_password"
      break
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done
}

perform_install(){
  # mark the current step
  echo "install" > $current_step_file

  # ensure that a settings file exists
  touch ~/$kiwi_settings

  # load all settings
  local system_name="$(standard_to_lower $(fss_extended_read -c 0 -n system_name ~/$kiwi_settings))"
  local system_clock="$(fss_extended_read -c 0 -n system_clock ~/$kiwi_settings)"
  local system_timezone="$(fss_extended_read -c 0 -n system_timezone ~/$kiwi_settings)"
  local system_clock_ntp_server="$(fss_extended_read -c 0 -n system_clock_ntp_server ~/$kiwi_settings)"
  local destination_schema="$(fss_extended_read -c 0 -n destination_schema ~/$kiwi_settings)"
  local root_user_name="$(standard_to_lower $(standard_alpha_numeric $(fss_extended_read -c 0 -n root_user_name ~/$kiwi_settings)))"
  local root_user_password="$(fss_extended_read -c 0 -n root_user_password ~/$kiwi_settings)"
  local root_autologin="$(fss_extended_read -c 0 -n root_autologin ~/$kiwi_settings)"
  local admin_user_name="$(standard_to_lower $(standard_alpha_numeric $(fss_extended_read -c 0 -n admin_user_name ~/$kiwi_settings)))"
  local admin_user_password="$(fss_extended_read -c 0 -n admin_user_password ~/$kiwi_settings)"
  local admin_autologin="$(fss_extended_read -c 0 -n admin_autologin ~/$kiwi_settings)"
  local separate_boot_partition="$(fss_extended_read -c 0 -n separate_boot_partition ~/$kiwi_settings)"
  local separate_home_partition="$(fss_extended_read -c 0 -n separate_home_partition ~/$kiwi_settings)"
  local boot_partition="$(fss_extended_read -c 0 -n boot_partition ~/$kiwi_settings)"
  local root_partition="$(fss_extended_read -c 0 -n root_partition ~/$kiwi_settings)"
  local home_partition="$(fss_extended_read -c 0 -n home_partition ~/$kiwi_settings)"
  local root_partition_is_encrypted="$(fss_extended_read -c 0 -n root_partition_is_encrypted ~/$kiwi_settings)"
  local home_partition_is_encrypted="$(fss_extended_read -c 0 -n home_partition_is_encrypted ~/$kiwi_settings)"
  local encrypted_root_partition="$(fss_extended_read -c 0 -n encrypted_root_partition ~/$kiwi_settings)"
  local encrypted_home_partition="$(fss_extended_read -c 0 -n encrypted_home_partition ~/$kiwi_settings)"
  local root_partition_decryption_method="$(fss_extended_read -c 0 -n root_partition_decryption_method ~/$kiwi_settings)"
  local home_partition_decryption_method="$(fss_extended_read -c 0 -n home_partition_decryption_method ~/$kiwi_settings)"
  local install_boot_loader="$(fss_extended_read -c 0 -n install_boot_loader ~/$kiwi_settings)"
  local squish_squash_method="$(fss_extended_read -c 0 -n squish_squash_method ~/$kiwi_settings)"
  local squish_or_squash="$(fss_extended_read -c 0 -n squish_or_squash ~/$kiwi_settings)"
  local rootfs_subroot_path="$(fss_extended_read -c 0 -n rootfs_subroot_path ~/$kiwi_settings | sed -e 's|^/*||' -e 's|/*$|/|')"
  local squish_squash_path="$(fss_extended_read -c 0 -n squish_squash_path ~/$kiwi_settings | sed -e 's|^/*||' -e 's|/*$|/|')"
  local additional_users="$(fss_extended_read -c 0 -n additional_users ~/$kiwi_settings)"
  local system_keymap="$(fss_extended_read -c 0 -n system_keymap ~/$kiwi_settings)"
  local b43_firmware_fix="$(fss_extended_read -c 0 -n b43_firmware_fix ~/$kiwi_settings)"
  local current_user_name=
  local current_user_group=
  local current_user_password=
  local i=

  local kiwi_mount_path=/installation/destination/
  local kiwi_rootfs_path=
  local invalid=
  local installation_files=/installation/
  local failure=
  local decrypt_root_keyfile=
  local decrypt_home_keyfile=
  local root_partition_device_path=
  local boot_partition_device_path=
  local home_partition_device_path=
  local encrypted_root_partition_device_path=
  local encrypted_home_partition_device_path=
  local converted_device_path=
  local broadcom_version=4.178.10.4
  local broadcom_file=broadcom-wl-$broadcom_version.tar.bz2
  local broadcom_extracted=broadcom-wl-$broadcom_version
  local broadcom_url=http://downloads.openwrt.org/sources/$broadcom_file
  local firmware_sfs_format=
  local existing_decrypted=

  if [[ $root_user_password == "" ]] ; then
    root_user_password=x;
  fi

  if [[ $rootfs_subroot_path == "/" ]] ; then
    rootfs_subroot_path=
  fi

  if [[ $squish_squash_path == "" || $squish_squash_path == "/" ]] ; then
    if [[ $separate_boot_partition == "yes" ]] ; then
      squish_squash_path=live/
    else
      squish_squash_path=boot/live/
    fi
  fi

  # validate variables here and on error allow the user to correct the error by going back to the configure process
  validate_variables

  if [[ $invalid != "" ]] ; then
    current_mode=configure
    echo "configure" > $current_step_file

    print_invalid_variables_header
    echo "The following variables are invalid:"
    echo -e "$invalid"
    echo
    echo -e "${c_notice}Press enter to return to the configure process${c_reset}"
    read input_buffer

    return
  fi

  while [[ $input_buffer != "0" ]] ; do
    print_installation_header "Now Ready to Begin Install"

    echo -e "You may now begin the installation or you may go back to the configure process:"
    echo -e "(1) Begin Installation"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "1" ]] ; then
      break
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done

  if [[ ! -f ${installation_files}lib.sfs && ! -f ${installation_files}live/lib.sfs ]] ; then
    print_installation_error_header
    print_error_line_nosleep "Cannot find installation files at '$installation_files' or at '${installation_files}live'"

    echo -e "${c_notice}Press enter to restart the installer${c_reset}"
    read input_buffer

    return
  fi

  # Decrypt root and home partitions
  if [[ $root_partition_is_encrypted == "yes" ]] ; then
    echo -e "${c_notice}Now attempting to decrypt the root partition $encrypted_root_partition${c_reset}"

    converted_device_path=
    convert_to_device_path $encrypted_root_partition
    encrypted_root_partition_device_path=$converted_device_path

    cryptsetup isLuks $encrypted_root_partition_device_path

    if [[ $? -ne 0 ]] ; then
      print_installation_error_header noclear
      print_error_line_nosleep "The root partition '$encrypted_root_partition' is not a valid LUKS encrypted partition or cannot be found"

      echo -e "${c_notice}Press enter to restart the installer${c_reset}"
      read input_buffer

      return
    fi

    if [[ $root_partition_decryption_method == "use_password" ]] ; then
      cryptsetup luksOpen $encrypted_root_partition_device_path kiwi_decrypted_rootfs

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Failed to decrypt the root partition '$encrypted_root_partition'"

        echo -e "${c_notice}Press enter to restart the installer${c_reset}"
        read input_buffer

        return
      fi
    else
      decrypt_root_keyfile=$(echo $root_partition_decryption_method | sed -e "s|^use_file=||");

      cryptsetup luksOpen $encrypted_root_partition_device_path kiwi_decrypted_rootfs -d ~/$decrypt_root_keyfile

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Failed to decrypt the root partition '$encrypted_root_partition' with the keyfile '$decrypt_root_keyfile'"

        echo -e "${c_notice}Press enter to restart the installer${c_reset}"
        read input_buffer

        return
      fi
    fi

    existing_decrypted="$encrypted_root_partition $encrypted_root_partition_device_path"
  fi

  if [[ $home_partition_is_encrypted == "yes" && $(echo $existing_decrypted | grep -s -o "\<$encrypted_home_partition\>") == "" ]] ; then
    echo -e "${c_notice}Now attempting to decrypt the home partition $encrypted_home_partition${c_reset}"

    converted_device_path=
    convert_to_device_path $encrypted_home_partition
    encryped_home_partition_device_path=$converted_device_path

    cryptsetup isLuks $encryped_home_partition_device_path

    if [[ $? -ne 0 ]] ; then
      print_installation_error_header noclear
      print_error_line_nosleep "The home partition '$encrypted_home_partition' is not a valid LUKS encrypted partition or cannot be found"

      if [[ $root_partition_is_encrypted == "yes" ]] ; then
        cryptsetup luksClose kiwi_decrypted_rootfs
      fi

      echo -e "${c_notice}Press enter to restart the installer${c_reset}"
      read input_buffer

      return
    fi

    if [[ $home_partition_decryption_method == "use_password" ]] ; then
      cryptsetup luksOpen $encryped_home_partition_device_path kiwi_decrypted_home

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Failed to decrypt the home partition '$encrypted_home_partition'"

        if [[ $root_partition_is_encrypted == "yes" ]] ; then
          cryptsetup luksClose kiwi_decrypted_rootfs
        fi

        echo -e "${c_notice}Press enter to restart the installer${c_reset}"
        read input_buffer

        return
      fi
    else
      decrypt_home_keyfile=$(echo $home_partition_decryption_method | sed -e "s|^use_file=||");

      cryptsetup luksOpen $encrypted_home_partition kiwi_decrypted_home -d ~/$decrypt_home_keyfile

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Failed to decrypt the home partition '$encrypted_home_partition' with the keyfile '$decrypt_home_keyfile'"

        if [[ $root_partition_is_encrypted == "yes" ]] ; then
          cryptsetup luksClose kiwi_decrypted_rootfs
        fi

        echo -e "${c_notice}Press enter to restart the installer${c_reset}"
        read input_buffer

        return
      fi
    fi
  fi

  converted_device_path=
  convert_to_device_path $root_partition
  root_partition_device_path=$converted_device_path

  if [[ $separate_home_partition == "yes" ]] ; then
    converted_device_path=
    convert_to_device_path $home_partition
    home_partition_device_path=$converted_device_path
  fi

  if [[ $separate_boot_partition == "yes" ]] ; then
    converted_device_path=
    convert_to_device_path $boot_partition
    boot_partition_device_path=$converted_device_path
  fi

  # mount the devices
  if [[ ! -d $kiwi_mount_path ]] ; then
    mkdir -p $kiwi_mount_path

    if [[ $? -ne 0 ]] ; then
      print_installation_error_header noclear
      print_error_line_nosleep "Cannot create the directory '$kiwi_mount_path'"

      if [[ $home_partition_is_encrypted == "yes" ]] ; then
        cryptsetup luksClose kiwi_decrypted_home
      fi

      if [[ $root_partition_is_encrypted == "yes" ]] ; then
        cryptsetup luksClose kiwi_decrypted_rootfs
      fi

      echo -e "${c_notice}Press enter to restart the installer${c_reset}"
      read input_buffer

      return
    fi
  fi

  if [[ $(mount | grep -s -o " on $(echo $kiwi_mount_path | sed -e 's|/$||') ") == "" ]] ; then
    mount $root_partition_device_path $kiwi_mount_path

    if [[ $? -ne 0 ]] ; then
      print_installation_error_header noclear
      print_error_line_nosleep "Cannot mount '$root_partition_device_path' on the directory '$kiwi_mount_path'"

      if [[ $home_partition_is_encrypted == "yes" ]] ; then
        cryptsetup luksClose kiwi_decrypted_home
      fi

      if [[ $root_partition_is_encrypted == "yes" ]] ; then
        cryptsetup luksClose kiwi_decrypted_rootfs
      fi

      echo -e "${c_notice}Press enter to restart the installer${c_reset}"
      read input_buffer

      return
    fi
  fi

  kiwi_rootfs_path=$kiwi_mount_path$rootfs_subroot_path

  if [[ $rootfs_subroot_path != "" ]] ; then
    mkdir -p $kiwi_rootfs_path
  fi

  if [[ $separate_boot_partition == "yes" && ( $install_boot_loader == "all" || $install_boot_loader == "files" ) ]] ; then
    if [[ ! -d ${kiwi_rootfs_path}boot ]] ; then
      mkdir -p ${kiwi_rootfs_path}boot

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Cannot create the directory '${kiwi_rootfs_path}boot'"

        umount -l $kiwi_mount_path

        if [[ $home_partition_is_encrypted == "yes" ]] ; then
          cryptsetup luksClose kiwi_decrypted_home
        fi

        if [[ $root_partition_is_encrypted == "yes" ]] ; then
          cryptsetup luksClose kiwi_decrypted_rootfs
        fi

        echo -e "${c_notice}Press enter to restart the installer${c_reset}"
        read input_buffer

        return
      fi
    fi

    if [[ $(mount | grep -s -o " on ${kiwi_rootfs_path}boot ") == "" ]] ; then
      mkdir -p ${kiwi_rootfs_path}boot
      mount $boot_partition_device_path ${kiwi_rootfs_path}boot

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Cannot mount '$boot_partition_device_path' on the directory '${kiwi_rootfs_path}boot'"

        umount -l $kiwi_mount_path

        if [[ $home_partition_is_encrypted == "yes" ]] ; then
          cryptsetup luksClose kiwi_decrypted_home
        fi

        if [[ $root_partition_is_encrypted == "yes" ]] ; then
          cryptsetup luksClose kiwi_decrypted_rootfs
        fi

        echo -e "${c_notice}Press enter to restart the installer${c_reset}"
        read input_buffer

        return
      fi
    fi

    chgrp d_boot ${kiwi_rootfs_path}boot
    chmod 2750 ${kiwi_rootfs_path}boot
  fi

  if [[ $separate_home_partition == "yes" ]] ; then
    if [[ ! -d ${kiwi_rootfs_path}home ]] ; then
      mkdir -p ${kiwi_rootfs_path}home

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Cannot create the directory '${kiwi_rootfs_path}home'"

        if [[ $separate_boot_partition == "yes" && -d ${kiwi_rootfs_path}boot ]] ; then
          umount -l ${kiwi_rootfs_path}boot
        fi

        umount -l $kiwi_mount_path

        if [[ $home_partition_is_encrypted == "yes" ]] ; then
          cryptsetup luksClose kiwi_decrypted_home
        fi

        if [[ $root_partition_is_encrypted == "yes" ]] ; then
          cryptsetup luksClose kiwi_decrypted_rootfs
        fi

        echo -e "${c_notice}Press enter to restart the installer${c_reset}"
        read input_buffer

        return
      fi
    fi

    if [[ $(mount | grep -s -o " on ${kiwi_rootfs_path}home ") == "" ]] ; then
      mount $home_partition_device_path ${kiwi_rootfs_path}home

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Cannot mount '$home_partition_device_path' on the directory '${kiwi_rootfs_path}home'"

        if [[ $separate_boot_partition == "yes" && -d ${kiwi_rootfs_path}boot ]] ; then
          umount -l ${kiwi_rootfs_path}boot
        fi

        umount -l $kiwi_mount_path

        if [[ $home_partition_is_encrypted == "yes" ]] ; then
          cryptsetup luksClose kiwi_decrypted_home
        fi

        if [[ $root_partition_is_encrypted == "yes" ]] ; then
          cryptsetup luksClose kiwi_decrypted_rootfs
        fi

        echo -e "${c_notice}Press enter to restart the installer${c_reset}"
        read input_buffer

        return
      fi
    fi

    chgrp d_home ${kiwi_rootfs_path}home
    chmod 2751 ${kiwi_rootfs_path}home
  fi

  # extract the system contents
  mkdir -p $squish_squash_path

  if [[ $separate_boot_partition == "yes" ]] ; then
    if [[ $squish_squash_method == "none" ]] ; then
      extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -n -m all
    else
      if [[ $squish_or_squash == "squash" ]] ; then
        extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -n -m minimal -e etc -e home && extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -m all -e boot -e dev -e documentation -e var -e checksum -e bin -e lib -e sbin -e share -e toolchain -e proc -e sys -e tmp -e mnt -e  modules -e firmware -e kernel_modules
      else
        extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -n -m core
      fi
    fi
  else
    if [[ $squish_squash_method == "none" ]] ; then
      extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -m all
    else
      if [[ $squish_or_squash == "squash" ]] ; then
        extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -m minimal -e etc -e home && extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -m all -e boot -e dev -e documentation -e var -e checksum -e bin -e lib -e sbin -e share -e toolchain -e proc -e sys -e tmp -e mnt -e  modules -e firmware -e kernel_modules
      else
        extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -m core
      fi
    fi
  fi

  if [[ $? -ne 0 ]] ; then
    print_error_line_nosleep "Something went wrong during the system extraction process"

    echo -e "${c_notice}Press enter to restart the installer${c_reset}"
    read input_buffer

    return
  fi

  # make all changes to the system
  failure=

  # create the boot settings files
  mkdir -p ${kiwi_rootfs_path}boot/settings/default/

  if [[ $? -ne 0 ]] ; then
    print_installation_error_header noclear
    print_error_line_nosleep "Failed to create boot settings directory at: ${kiwi_rootfs_path}boot/settings/default/"

    echo -e "${c_notice}Press enter to restart the installer${c_reset}"
    read input_buffer

    return
  fi

  echo $root_partition > ${kiwi_rootfs_path}boot/settings/default/rootfs.device

  if [[ $? -ne 0 ]] ; then
    print_installation_error_header noclear
    print_error_line_nosleep "Failed to create boot settings rootfs device file at: ${kiwi_rootfs_path}boot/settings/default/rootfs.device"

    echo -e "${c_notice}Press enter to restart the installer${c_reset}"
    read input_buffer

    return
  fi

  if [[ $separate_home_partition == "yes" ]] ; then
    echo $home_partition > ${kiwi_rootfs_path}boot/settings/default/home.device

    if [[ $? -ne 0 ]] ; then
      print_installation_error_header noclear
      print_error_line_nosleep "Failed to create boot settings home device file at: ${kiwi_rootfs_path}boot/settings/default/home.device"

      echo -e "${c_notice}Press enter to restart the installer${c_reset}"
      read input_buffer

      return
    fi
  fi

  if [[ $root_partition_is_encrypted == "yes" || $home_partition_is_encrypted == "yes" ]] ; then
    if [[ $? -ne 0 ]] ; then
      print_installation_error_header noclear
      print_error_line_nosleep "Failed to create decryption boot settings directory at: ${kiwi_rootfs_path}boot/settings/default/"

      echo -e "${c_notice}Press enter to restart the installer${c_reset}"
      read input_buffer

      return
    fi

    if [[ $root_partition_is_encrypted == "yes" ]] ; then
      echo $encrypted_root_partition > ${kiwi_rootfs_path}boot/settings/default/rootfs.encrypted

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Failed to create decryption settings rootfs device file at: ${kiwi_rootfs_path}boot/settings/default/rootfs.encrypted"

        echo -e "${c_notice}Press enter to restart the installer${c_reset}"
        read input_buffer

        return
      fi

      if [[ $decrypt_root_keyfile == "" ]] ; then
        touch ${kiwi_rootfs_path}boot/settings/default/rootfs.ask

        if [[ $? -ne 0 ]] ; then
          print_installation_error_header noclear
          print_error_line_nosleep "Failed to create decryption settings rootfs decryption key file at: ${kiwi_rootfs_path}boot/settings/default/rootfs.ask"

          echo -e "${c_notice}Press enter to restart the installer${c_reset}"
          read input_buffer

          return
        fi
      else
        cp -v ~/$decrypt_root_keyfile ${kiwi_rootfs_path}boot/settings/default/rootfs.key

        if [[ $? -ne 0 ]] ; then
          print_installation_error_header noclear
          print_error_line_nosleep "Failed to create decryption settings rootfs decryption key file at: ${kiwi_rootfs_path}boot/settings/default/rootfs.key"

          echo -e "${c_notice}Press enter to restart the installer${c_reset}"
          read input_buffer

          return
        fi
      fi
    fi

    if [[ $home_partition_is_encrypted == "yes" && $root_partition_device_path != $home_partition_device_path ]] ; then
      echo $encrypted_home_partition > ${kiwi_rootfs_path}boot/settings/default/home.encrypted

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Failed to create decryption settings home device file at: ${kiwi_rootfs_path}boot/settings/default/home.encrypted"

        echo -e "${c_notice}Press enter to restart the installer${c_reset}"
        read input_buffer

        return
      fi

      if [[ $decrypt_home_keyfile == "" ]] ; then
        touch ${kiwi_rootfs_path}boot/settings/default/home.ask

        if [[ $? -ne 0 ]] ; then
          print_installation_error_header noclear
          print_error_line_nosleep "Failed to create decryption settings home decryption key file at: ${kiwi_rootfs_path}boot/settings/default/home.ask"

          echo -e "${c_notice}Press enter to restart the installer${c_reset}"
          read input_buffer

          return
        fi
      else
        cp -v ~/$decrypt_home_keyfile ${kiwi_rootfs_path}boot/settings/default/home.key

        if [[ $? -ne 0 ]] ; then
          print_installation_error_header noclear
          print_error_line_nosleep "Failed to create decryption settings home decryption key file at: ${kiwi_rootfs_path}boot/settings/default/home.key"

          echo -e "${c_notice}Press enter to restart the installer${c_reset}"
          read input_buffer

          return
        fi
      fi
    fi
  fi

  echo $system_name > ${kiwi_rootfs_path}etc/network/hostname || failure="${failure}system_name "
  echo "127.0.0.1 localhost" > ${kiwi_rootfs_path}etc/network/hosts || failure="${failure}system_name_hosts "
  echo "127.0.0.1 $system_name $(echo $system_name | grep -P -s -o '^(\d|\w)(\d|\w|-|_|)*')" >> ${kiwi_rootfs_path}etc/network/hosts || failure="${failure}system_name_hosts "
  echo "#::1 localhost" >> ${kiwi_rootfs_path}etc/network/hosts || failure="${failure}system_name_hosts "
  echo $system_timezone > ${kiwi_rootfs_path}etc/timezone || failure="${failure}system_timezone "
  echo -e "# fss-0000\n\nmode $system_clock" > ${kiwi_rootfs_path}etc/clock || failure="${failure}system_clock "

  echo -e "# fss-0000\n\n#unicode force\nunicode\n\n#clear no\nclear yes\n\n" > ${kiwi_rootfs_path}etc/keymap || failure="${failure}system_keymap "

  if [[ $system_keymap == "dvorak" ]] ; then
    echo -e "keymap dvorak\n#keymap olpc\n#keymap us\n" > ${kiwi_rootfs_path}etc/keymap || failure="${failure}system_keymap "
  elif [[ $system_keymap == "olpc" ]] ; then
    echo -e "#keymap dvorak\keymap olpc\n#keymap us\n" > ${kiwi_rootfs_path}etc/keymap || failure="${failure}system_keymap "
  else
    echo -e "#keymap dvorak\n#keymap olpc\keymap us\n" > ${kiwi_rootfs_path}etc/keymap || failure="${failure}system_keymap "
  fi

  if [[ $system_clock_ntp_server == "" ]] ; then
    echo "#server " >> ${kiwi_rootfs_path}etc/clock
  else
    echo "server $system_clock_ntp_server" >> ${kiwi_rootfs_path}etc/clock || failure="${failure}system_clock_ntp_server "
  fi

  cp ${kiwi_rootfs_path}etc/qingy/settings{-default,} || failure="${failure}qingy_default_settings "

  local old_root_user=$(grep -s -m 1 -o '^\<[^:]*\>:[^:]*:0:0:' ${kiwi_rootfs_path}etc/passwd | sed -e 's|:x:0:0:$||');
  echo "$root_user_name 0 1 2 3 4" > ${kiwi_rootfs_path}etc/qingy/AllowedSessions || failure="${failure}root_user_name_qingy_allowed_sessions "
  sed -i -e "s|^\<[^:]*\>:[^:]*:0:0:|$root_user_name:x:0:0:|" ${kiwi_rootfs_path}etc/passwd || failure="${failure}configure_root_user_password "
  sed -i -e "s|:/home/users/$old_root_user:|:/home/users/$root_user_name:|" ${kiwi_rootfs_path}etc/passwd || failure="${failure}configure_root_user_password "
  sed -i -e "s|^$old_root_user:.*\$|$root_user_name:$root_user_password:14877:0:99999:7:::|" ${kiwi_rootfs_path}etc/shadow || failure="${failure}configure_root_user_shadow "
  sed -i -e "s|^$old_root_user:x:0|u_$root_user_name:x:0|" ${kiwi_rootfs_path}etc/group || failure="${failure}configure_root_user_group "

  if [[ $old_root_user != $root_user_name ]] ; then
    mv ${kiwi_rootfs_path}home/users/{$old_root_user,$root_user_name} || failure="${failure}configure_root_user_directory "

    for i in wpa_supplicant.conf bluetooth.conf ; do
      if [[ -e ${kiwi_rootfs_path}home/services/dbus/settings/system.d/$i ]] ; then
        sed -i -e "s|user=\"${old_root_user}\"|user=\"${root_user_name}\"|g" ${kiwi_rootfs_path}home/services/dbus/settings/system.d/$i || failure="${failure}configure_root_user_dbus_files "
      fi
    done

    if [[ -e ${kiwi_rootfs_path}home/services/samba/settings/smb.conf ]] ; then
      sed -i -e "s|invalid users = ${old_root_user} |invalid users = ${root_user_name} |" ${kiwi_rootfs_path}home/services/samba/settings/smb.conf || failure="${failure}configure_root_user_samba_files "
    fi

    if [[ -e ${kiwi_rootfs_path}etc/quotagrpadmins ]] ; then
      sed -i -e "s|users: ${old_root_user}|users: ${root_user_name}|" ${kiwi_rootfs_path}etc/quotagrpadmins || failure="${failure}configure_root_user_quota_files "
    fi
  fi

  if [[ $root_autologin == "yes" ]] ; then
    setup_qingy_autologin_settings $root_user_name ${kiwi_rootfs_path}etc/qingy/settings || failure="${failure}setup_qingy_autologin_settings "
  elif [[ $admin_autologin == "yes" ]] ; then
    setup_qingy_autologin_settings $admin_user_name ${kiwi_rootfs_path}etc/qingy/settings || failure="${failure}setup_qingy_autologin_settings "
  fi

  if [[ $failure != "" ]] ; then
    if [[ $(echo $failure | grep -s -o '\<system_name\>') != "" ]] ; then
      print_error_line_nosleep "Failed to setup hostname: '$system_name' > ${kiwi_rootfs_path}etc/network/hostname"
    fi

    if [[ $(echo $failure | grep -s -o '\<system_name_hosts\>') != "" ]] ; then
      print_error_line_nosleep "Failed to populate hosts file: ${kiwi_rootfs_path}etc/network/hosts"
    fi

    if [[ $(echo $failure | grep -s -o '\<system_timezone\>') != "" ]] ; then
      print_error_line_nosleep "Failed to setup system timezone: '$system_timezone' > ${kiwi_rootfs_path}etc/timezone"
    fi

    if [[ $(echo $failure | grep -s -o '\<system_clock\>') != "" ]] ; then
      print_error_line_nosleep "Failed to setup system clock: 'mode $system_clock' > ${kiwi_rootfs_path}etc/clock"
    fi

    if [[ $(echo $failure | grep -s -o '\<system_clock_ntp_server\>') != "" ]] ; then
      print_error_line_nosleep "Failed to setup system clock NTP server: 'server $system_clock_ntp_server' >> ${kiwi_rootfs_path}etc/clock"
    fi

    if [[ $(echo $failure | grep -s -o '\<system_keymap\>') != "" ]] ; then
      print_error_line_nosleep "Failed to setup system keymap: ${kiwi_rootfs_path}etc/keymap"
    fi

    if [[ $(echo $failure | grep -s -o '\<qingy_default_settings\>') != "" ]] ; then
      print_error_line_nosleep "Failed to setup default qingy settings: ${kiwi_rootfs_path}etc/qingy/settings{-default,}"
    fi

    if [[ $(echo $failure | grep -s -o '\<root_user_name_qingy_allowed_sessions\>') != "" ]] ; then
      print_error_line_nosleep "Failed to add user to qingy allowed sessions file: '$root_user_name 0 1 2 3 4' > ${kiwi_rootfs_path}etc/qingy/AllowedSessions"
    fi

    if [[ $(echo $failure | grep -s -o '\<configure_root_user_password\>') != "" ]] ; then
      print_error_line_nosleep "Failed to update root user settings for password file: ${kiwi_rootfs_path}etc/passwd"
    fi

    if [[ $(echo $failure | grep -s -o '\<configure_root_user_shadow\>') != "" ]] ; then
      print_error_line_nosleep "Failed to update root user settings for shadow file: ${kiwi_rootfs_path}etc/shadow"
    fi

    if [[ $(echo $failure | grep -s -o '\<configure_root_user_group\>') != "" ]] ; then
      print_error_line_nosleep "Failed to update root user settings for group file: ${kiwi_rootfs_path}etc/group"
    fi

    if [[ $(echo $failure | grep -s -o '\<configure_root_user_directory\>') != "" ]] ; then
      print_error_line_nosleep "Failed to rename root user home directory: ${kiwi_rootfs_path}home/users/{$old_root_user,$root_user_name}"
    fi

    if [[ $(echo $failure | grep -s -o '\<configure_root_user_dbus_files\>') != "" ]] ; then
      print_error_line_nosleep "Failed to rename root user name for dbus files in: ${kiwi_rootfs_path}home/services/dbus/settings/system.d/"
    fi

    if [[ $(echo $failure | grep -s -o '\<configure_root_user_samba_files\>') != "" ]] ; then
      print_error_line_nosleep "Failed to rename root user name for the samba file: ${kiwi_rootfs_path}home/services/samba/settings/smb.conf"
    fi

    if [[ $(echo $failure | grep -s -o '\<configure_root_user_quota_files\>') != "" ]] ; then
      print_error_line_nosleep "Failed to rename root user name for the quota file: ${kiwi_rootfs_path}etc/quotagrpadmins"
    fi

    if [[ $(echo $failure | grep -s -o '\<setup_qingy_autologin_settings\>') != "" ]] ; then
      print_error_line_nosleep "Failed to setup the autologin settings in: ${kiwi_rootfs_path}etc/qingy/settings"
    fi

    failure=

    echo
    echo -e "${c_notice}Press enter to continue${c_reset}"
    read input_buffer
  fi


  if [[ $b43_firmware_fix == "yes" ]] ; then
    echo -e "${c_notice}Now attempting to perform b43 firmware fix${c_reset}"

    cd ${kiwi_rootfs_path}
    wget -T 3 $broadcom_url

    if [[ -f $broadcom_file ]] ; then
      tar -xf $broadcom_file

      if [[ -d $broadcom_extracted ]] ; then
        rm -f $broadcom_file

        if [[ $squish_squash_method != "none" ]] ; then
          if [[ -f $kiwi_rootfs_path${squish_squash_path}firmware.sfs ]] ; then
            # preserve the compression format
            firmware_sfs_format=$(unsquashfs -s $kiwi_rootfs_path${squish_squash_path}firmware.sfs | grep -s -o '^Compression \<.*\>$' | sed -e 's|^Compression ||')

            unsquashfs -n $kiwi_rootfs_path${squish_squash_path}firmware.sfs

            if [[ $? -eq 0 && -d squashfs-root ]] ; then
              mv -n squashfs-root/* firmware/
              rm -Rf squashfs-root
              mkdir -p firmware/b43

              find $broadcom_extracted -name wl_apsta.o -exec b43-fwcutter -w ${kiwi_rootfs_path}firmware/ '{}' ';'
              find $broadcom_extracted -name wl_apsta_micro.o -exec b43-fwcutter -w ${kiwi_rootfs_path}firmware/ '{}' ';'
              find $broadcom_extracted -name wl_prebuilt.o -exec b43-fwcutter -w ${kiwi_rootfs_path}firmware/ '{}' ';'

              rm -Rf $broadcom_extracted
            else
              cd $OLDPWD
              print_error_line_nosleep "Failed to unsquash firmware: ${c_notice}${kiwi_rootfs_path}${squish_squash_path}firmware.sfs${c_error}"
              echo
              echo -e "${c_notice}Press enter to continue${c_reset}"
              read input_buffer
            fi
          else
            cd $OLDPWD
            print_error_line_nosleep "Unable to find firmware at: ${c_notice}${kiwi_rootfs_path}${squish_squash_path}firmware.sfs${c_error}"
            echo
            echo -e "${c_notice}Press enter to continue${c_reset}"
            read input_buffer
          fi

          echo -e "${c_notice}Now recompressing firmware${c_reset}"
          mksquashfs firmware{,.sfs} -processors 1 -comp $firmware_sfs_format

          if [[ $? -eq 0 ]] ; then
            rm -Rf firmware/*

            mv firmware.sfs ${kiwi_rootfs_path}${squish_squash_path}firmware.sfs

            if [[ $? -eq 0 ]] ; then
              cd $OLDPWD
            else
              cd $OLDPWD
              print_error_line_nosleep "Failed to move compressed firmware to: ${c_notice}${kiwi_rootfs_path}${squish_squash_path}firmware.sfs${c_error}"
              echo
              echo -e "${c_notice}Press enter to continue${c_reset}"
              read input_buffer
            fi
          else
            cd $OLDPWD
            print_error_line_nosleep "Failed to recompress firmware: ${c_notice}firmware.sfs${c_error}"
            echo
            echo -e "${c_notice}Press enter to continue${c_reset}"
            read input_buffer
          fi

          cd $OLDPWD
        else
          mkdir -p ${kiwi_rootfs_path}firmware/b43

          find $broadcom_extracted -name wl_apsta.o -exec b43-fwcutter -w ${kiwi_rootfs_path}firmware/ '{}' ';'
          find $broadcom_extracted -name wl_apsta_micro.o -exec b43-fwcutter -w ${kiwi_rootfs_path}firmware/ '{}' ';'
          find $broadcom_extracted -name wl_prebuilt.o -exec b43-fwcutter -w ${kiwi_rootfs_path}firmware/ '{}' ';'

          rm -Rf $broadcom_extracted
        fi
      else
        cd $OLDPWD
        print_error_line_nosleep "Failed to extract the B43 firmware file: ${c_notice}$broadcom_file${c_error}"
        echo
        echo -e "${c_notice}Press enter to continue${c_reset}"
        read input_buffer
      fi
    else
      cd $OLDPWD
      print_error_line_nosleep "Failed to download the B43 firmware from: ${c_notice}$broadcom_url${c_error}"
      echo
      echo -e "${c_notice}Press enter to continue${c_reset}"
      read input_buffer
    fi
  fi

  if [[ $squish_squash_method != "none" ]] ; then
    failure=
    temporary_mount_system

    if [[ $failure != "" ]] ; then
      temporary_unmount_system

      print_error_line_nosleep "Unable to temporarily mount the system, reason: $failure"

      echo -e "${c_notice}Press enter to restart installer${c_reset}"
      read input_buffer
      return
    fi
  fi

  if [[ $admin_user_name != "" ]] ; then
    chroot ${kiwi_rootfs_path} adduser -g admin -n $admin_user_name

    if [[ $? -ne 0 ]] ; then
      print_installation_error_header noclear
      print_error_line_nosleep "Failed to add the admin user: $admin_user_name"

      echo -e "${c_notice}Press enter to continue${c_reset}"
      read input_buffer
    fi


    if [[ $admin_user_password != "" ]] ; then
      sed -i -e "s|^$admin_user_name:.*\$|$admin_user_name:$admin_user_password:14877:0:99999:7:::|" ${kiwi_rootfs_path}etc/shadow

      if [[ $? -ne 0 ]] ; then
        print_error_line_nosleep "Failed to setup the password for the admin user '$admin_user_name' in: ${kiwi_rootfs_path}etc/shadow"

        echo
        echo -e "${c_notice}Press enter to continue${c_reset}"
        read input_buffer
      fi
    fi
  fi

  let i=0

  while [[ $additional_users -gt 0 && $i -lt $additional_users ]] ; do
    current_user_name="$(standard_to_lower $(standard_alpha_numeric $(fss_extended_read -c 0 -n additional_user_name_$i ~/$kiwi_settings)))"
    current_user_group="$(fss_extended_read -c 0 -n additional_user_group_$i ~/$kiwi_settings)"
    current_user_password="$(fss_extended_read -c 0 -n additional_user_password_$i ~/$kiwi_settings)"

    if [[ $current_user_name != "" && $current_user_group != "" ]] ; then
      chroot ${kiwi_rootfs_path} adduser -g $current_user_group -n $current_user_name

      if [[ $? -ne 0 ]] ; then
        print_installation_error_header noclear
        print_error_line_nosleep "Failed to add user #$i: $current_user_name"

        echo -e "${c_notice}Press enter to continue${c_reset}"
        read input_buffer
      fi

      if [[ $current_user_password != "" ]] ; then
        sed -i -e "s|^$current_user_name:.*\$|$current_user_name:$current_user_password:14877:0:99999:7:::|" ${kiwi_rootfs_path}etc/shadow

        if [[ $? -ne 0 ]] ; then
          print_error_line_nosleep "Failed to setup the password for user #$i '$current_user_name' in: ${kiwi_rootfs_path}etc/shadow"

          echo
          echo -e "${c_notice}Press enter to continue${c_reset}"
          read input_buffer
        fi
      fi
    else
      print_error_line_nosleep "Unable to add the user #$i, both the username '$current_user_name' and the system group '$current_user_group' must not be empty."

      echo
      echo -e "${c_notice}Press enter to continue${c_reset}"
      read input_buffer
    fi

    let i=$i+1
  done

  temporary_unmount_system

  # update boot loader files and optionally install grub
  local boot_device=
  local disk_number=
  local partition_number=
  local converted_device_path=

  if [[ $separate_boot_partition == "yes" ]] ; then
    convert_to_device_path $boot_partition
  else
    convert_to_device_path $root_partition
  fi

  boot_device=$converted_device_path

  if [[ -d ${kiwi_rootfs_path}boot/grub ]] ; then
    if [[ $separate_boot_partition == "yes" ]] ; then
      sed -i -e 's|/boot||g' ${kiwi_rootfs_path}boot/grub/menu.lst
    fi

    if [[ $(echo $boot_device | grep -s -o 'sd[[:alpha:]][[:digit:]]') == "" ]] ; then
      if [[ $boot_device == "" ]] ; then
        print_error_line_nosleep "Could not find the boot device.\nYou will have to manually install the boot loader yourself"
      else
        print_error_line_nosleep "The automated installer is not designed to safely install to a boot device of '$boot_device'\nYou will have to manually install the boot loader yourself."
      fi

      echo
      echo -e "${c_notice}Press enter to continue${c_reset}"
      read input_buffer
    else
      convert_partition_into_grub_format

      if [[ $disk_number == "" || $disk_number -lt 0 || $disk_number -gt 25 ]] ; then
        print_error_line_nosleep "The converted disk_number '$disk_number' is invalid.\nYou will have to manually install the boot loader yourself"

        echo
        echo -e "${c_notice}Press enter to continue${c_reset}"
        read input_buffer
      elif [[ $partition_number == "" || $partition_number -lt 0 ]] ; then
        print_error_line_nosleep "The converted partition_number '$partition_number' is invalid.\nYou will have to manually install the boot loader yourself"

        echo
        echo -e "${c_notice}Press enter to continue${c_reset}"
        read input_buffer
      else
        update_boot_loader_settings

        if [[ $install_boot_loader == "all" || $install_boot_loader == "grub" ]] ; then
          grub --batch << EOF
root (hd$disk_number,$partition_number)
EOF

          if [[ $? -eq 0 ]] ; then
            grub --batch << EOF
root (hd$disk_number,$partition_number)
setup (hd$disk_number)
EOF

            if [[ $? -ne 0 ]] ; then
              print_error_line_nosleep "Failed to install bootloader to device '(hd$disk_number)'"

              echo
              echo -e "${c_notice}Press enter to restart the installer${c_reset}"
              read input_buffer

              return
            fi
          else
            print_error_line_nosleep "Error preparing root partition '(hd$disk_number,$partition_number)' while trying to install the boot loader"

            echo
            echo -e "${c_notice}Press enter to restart the installer${c_reset}"
            read input_buffer

            return
          fi
        fi
      fi
    fi
  elif [[ $install_boot_loader == "all" || $install_boot_loader == "grub" ]] ; then
    print_error_line_nosleep "Unable to find or access the path to the boot loader files: ${kiwi_rootfs_path}boot/grub"

    echo
    echo -e "${c_notice}Press enter to continue${c_reset}"
    read input_buffer
  fi

  if [[ $separate_boot_partition == "yes" ]] ; then
    failure=

    if [[ -d ${kiwi_rootfs_path}boot ]] ; then
      umount -l ${kiwi_rootfs_path}boot
      rmdir ${kiwi_rootfs_path}boot || failure=yes
    fi

    if [[ $failure != "yes" ]] ; then
      if [[ $squish_squash_method == "none" ]] ; then
        extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -o -m all
      else
        if [[ $squish_or_squash == "squash" ]] ; then
          extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -o -m minimal -e etc -e home && extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -m all -e boot -e dev -e documentation -e var -e checksum -e bin -e lib -e sbin -e share -e toolchain -e proc -e sys -e tmp -e mnt -e  modules -e firmware -e kernel_modules
        else
          extract_system -p $squish_squash_path -s $installation_files -d $kiwi_rootfs_path -o -m core
        fi
      fi
    fi

    if [[ $failure == "yes" ]] ; then
      print_error_line_nosleep "Something went wrong while copying the squish/squash files to '$squish_squash_path', you will have to manually copy the files over."

      echo
      echo -e "${c_notice}Press enter to continue${c_reset}"
      read input_buffer
    fi
  fi

  if [[ $separate_home_partition == "yes" ]] ; then
    umount -l ${kiwi_rootfs_path}home
  fi

  # compress the customized etc and home directories for squash mode and then empty out the directories
  if [[ $squish_squash_method != "none" ]] ; then
    pushd $kiwi_rootfs_path

    if [[ $? == 0 ]] ; then
      if [[ $squish_or_squash == "squash" ]] ; then
        mksquashfs etc /tmp/etc.sfs -processors 1 -comp xz && rm -Rf etc/* && mv /tmp/etc.sfs ${squish_squash_path}/ || failure="${failure}mksquashfs_etc "
      else
        mksquashfs etc /tmp/etc.sfs -processors 1 -comp xz && mv /tmp/etc.sfs ${squish_squash_path}/ || failure="${failure}mksquashfs_etc "
      fi

      if [[ $root_partition_device_path != $home_partition_device_path ]] ; then
        if [[ $squish_or_squash == "squash" ]] ; then
          mksquashfs home /tmp/home.sfs -processors 1 -comp xz && rm -Rf home/* && mv /tmp/home.sfs ${squish_squash_path}/ || failure="${failure}mksquashfs_home "
        else
          mksquashfs home /tmp/home.sfs -processors 1 -comp xz && mv /tmp/home.sfs ${squish_squash_path}/ || failure="${failure}mksquashfs_home "
        fi
      fi

      if [[ $failure != "" ]] ; then
        if [[ $(echo $failure | grep -s -o '\<mksquashfs_etc\>') != "" ]] ; then
          print_error_line_nosleep "Failed to regenerate the squash file: etc.sfs"
        fi

        if [[ $(echo $failure | grep -s -o '\<mksquashfs_home\>') != "" ]] ; then
          print_error_line_nosleep "Failed to regenerate the squash file: home.sfs"
        fi

        failure=

        echo
        echo -e "${c_notice}Press enter to continue${c_reset}"
        read input_buffer
      fi

      popd
    fi
  fi

  echo "Now flushing all buffers to their appropriate device."
  sync

  if [[ $home_partition_is_encrypted == "yes" ]] ; then
    cryptsetup luksClose kiwi_decrypted_home
  fi

  if [[ $root_partition_is_encrypted == "yes" ]] ; then
    cryptsetup luksClose kiwi_decrypted_rootfs
  fi

  cd

  umount -l $kiwi_mount_path

  # mark the next step
  echo "finished" > $current_step_file
  current_mode="finished"
}

update_boot_loader_settings(){
  local extra="quiet"

  if [[ $squish_squash_method != "none" ]] ; then
    if [[ $squish_org_squash == "squish" ]] ; then
      extra="$extra squishboot=$squish_squash_method"
    else
      extra="$extra squashboot=$squish_squash_method"
    fi

    if [[ $squish_squash_path != "boot/live/" ]] ; then
      extra="$extra squashpath=$squish_squash_path"
    fi
  fi

  if [[ $separate_boot_partition == "yes" ]] ; then
    extra="$extra settings=$boot_partition"
  else
    extra="$extra settings=$root_partition"
  fi

  # TODO: add an option for changing the settingsname
  extra="$extra settingsname=default"

  if [[ $rootfs_subroot_path != "" ]] ; then
    extra="$extra subroot=$rootfs_subroot_path"

    if [[ $separate_boot_partition == "no" ]] ; then
      sed -i -e "s|boot/|${rootfs_subroot_path}boot/|g" ${kiwi_rootfs_path}boot/grub/menu.lst

      if [[ $? != "0" ]] ; then
        print_error_line_nosleep "An error occurred while trying to add the subroot path to the boot load settings file: ${kiwi_rootfs_path}boot/grub/menu.lst"

        echo
        echo -e "${c_notice}Press enter to continue${c_reset}"
        read input_buffer
      fi
    fi
  fi

  sed -i -e "s|(hd0,0)|(hd0,$partition_number)|g" -e "s|\<quiet finalroot=LABEL=turtle_/|$extra|g" ${kiwi_rootfs_path}boot/grub/menu.lst

  if [[ $? != "0" ]] ; then
    print_error_line_nosleep "An error occurred while trying to update the boot load settings file: ${kiwi_rootfs_path}boot/grub/menu.lst"

    echo
    echo -e "${c_notice}Press enter to continue${c_reset}"
    read input_buffer
  fi

  sed -i -e "s|\<quiet squishboot=device finalroot=LABEL=turtle-sd-olpc|quiet $extra|g" -e "s|\<quiet squishboot=device finalroot=LABEL=turtle-usb-olpc|quiet $extra|g" ${kiwi_rootfs_path}boot/olpc.fth

  if [[ $? != "0" ]] ; then
    print_error_line_nosleep "An error occurred while trying to update the boot load settings file: ${kiwi_rootfs_path}boot/olpc.fth"

    echo
    echo -e "${c_notice}Press enter to continue${c_reset}"
    read input_buffer
  fi
}

convert_partition_into_grub_format(){
  local disk_letter=
  local number=

  disk_letter=$(echo $boot_device | grep -s -o '/sd..$' | sed -e 's|^/sd||' -e 's|.$||')

  let number=0

  for i in a b c d e f g h i j k l m n o p q r s t u v w x y z ; do
    if [[ $disk_letter == $i ]] ; then
      disk_number=$number
      break
    fi

    let number=$number+1
  done

  partition_number=$(echo $boot_device | grep -s -o '/sd..$' | sed -e "s|^/sd.||")

  let partition_number=$partition_number+-1
}

convert_to_device_path(){
  converted_device_path=$(blkid -l -o device -U $1)

  if [[ $converted_device_path == "" ]] ; then
    converted_device_path=$(blkid -l -o device -L $1)
  fi

  if [[ $converted_device_path == "" ]] ; then
    converted_device_path=$1
  fi
}

temporary_mount_system(){
  local squash_files=

  if [[ $separate_boot_partition == "yes" ]] ; then
    if [[ ! -f ${installation_files}bin.sfs ]] ; then
     if [[ -f ${installation_files}live/bin.sfs ]] ; then
       squash_files=${installation_files}live/
     elif [[ -f ${installation_files}boot/live/bin.sfs ]] ; then
       squash_files=${installation_files}boot/live/
     fi
    fi
  else
    squash_files=$kiwi_rootfs_path${squish_squash_path}/
  fi

  if [[ $squash_files == "" || ! -d $squash_files ]] ; then
    failure="Could not find directories where squash files should exist"
  fi

  if [[ $failure == "" ]] ; then
    if [[ -e ${squash_files}bin.sfs ]] ; then
      for i in bin sbin lib share ; do
        mount -o loop $squash_files$i.sfs $kiwi_rootfs_path$i

        if [[ $? -ne 0 ]] ; then
          failure="Could not mount '$squash_files$i.sfs' to '$kiwi_rootfs_path$i'"
          break;
        fi
      done
    else
      failure="Could not find squash files at path: $squash_files"
    fi
  fi
}

temporary_unmount_system(){
  umount -l ${kiwi_rootfs_path}bin
  umount -l ${kiwi_rootfs_path}sbin
  umount -l ${kiwi_rootfs_path}lib
  umount -l ${kiwi_rootfs_path}share
  umount -l ${kiwi_rootfs_path}python
  umount -l ${kiwi_rootfs_path}perl
}

setup_qingy_autologin_settings(){
 echo "" >> $2
 echo "tty = 4" >> $2
 echo "{" >> $2
 echo "  autologin" >> $2
 echo "  {" >> $2
 echo "    username = \"$1\"" >> $2
 echo "    session  = \"Xorg\"" >> $2
 echo "    relogin = no" >> $2
 echo "  }" >> $2
 echo "}" >> $2
}

perform_finished(){
  inpuy_buffer=

  while [[ $input_buffer != "0" ]] ; do
    print_installation_header "Installation Complete"

    echo -e "What do you want to do now?"
    echo -e "(1) Reboot System"
    echo -e "(2) Exit This Program"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "1" ]] ; then
      echo "reboot" > $current_step_file
      current_mode="reboot"
      return
    elif [[ $input_buffer == "2" ]] ; then
      echo "exit" > $current_step_file
      current_mode="exit"
      return
    elif [[ $input_buffer == "-" ]] ; then
      current_mode=configure
      return
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done
}

perform_reboot(){
  input_buffer=

  while [[ $input_buffer != "0" ]] ; do
    print_installation_header "Confirm Reboot"

    echo -e "What do you want to do now?"
    echo -e "(1) Yes"
    echo -e "(2) No"
    echo -e "(-) Restart Configure Process"
    echo
    print_input_line
    read input_buffer

    if [[ $input_buffer == "1" ]] ; then
      reboot
    elif [[ $input_buffer == "2" ]] ; then
      echo "finished" > $current_step_file
      current_mode="finished"
      return
    elif [[ $input_buffer == "-" ]] ; then
      echo "configure" > $current_step_file
      current_mode=configure
      return
    else
      print_error_line "ERROR: '$input_buffer' is not a valid option"
    fi
  done
}

apply_this_setting(){
  local text=$1
  local object=$2
  local content=$3
  local sleep=$4
  local current="$(fss_extended_read -c 0 -n object ~/$kiwi_settings)"

  echo
  echo -e "${c_highlight}Setting ${text} to:${c_reset} ${c_notice}${content}${c_reset}"

  sed -i -e "/^${object}\>/d" ~/$kiwi_settings
  echo "${object} ${content}" >> ~/$kiwi_settings

  if [[ $sleep == "" ]] ; then
    sleep 0.5
  elif [[ $sleep != 0 ]] ; then
    sleep $sleep
  fi
}

apply_this_setting_dont_show(){
  local text=$1
  local object=$2
  local content=$3
  local sleep=$4
  local current="$(fss_extended_read -c 0 -n object ~/$kiwi_settings)"

  echo
  echo -e "${c_highlight}Setting ${text}${c_reset}"
  echo

  sed -i -e "/^${object}\>/d" ~/$kiwi_settings
  echo "${object} ${content}" >> ~/$kiwi_settings

  if [[ $sleep == "" ]] ; then
    sleep 0.5
  elif [[ $sleep != 0 ]] ; then
    sleep $sleep
  fi
}

add_password_trick(){
  local results="0"
  if [[ $($(type -p grep) -or '^\<kiwi_tmp_user\>:' /etc/passwd) == "" ]] ; then
    adduser -g minimal -n kiwi_tmp_user &> /dev/null
    results=$?
  fi

  if [[ $results == 0 ]] ; then
    passwd -q kiwi_tmp_user
    results=$?
  fi

  if [[ $results == 0 ]] ; then
    password_buffer=$($(type -p grep) -o '^\<kiwi_tmp_user\>:[^:]*:' /etc/shadow | sed -e 's|^\<kiwi_tmp_user\>:||' -e 's|:$||')
    deluser kiwi_tmp_user &> /dev/null
    results=$?
  fi

  return $results
}

validate_variables(){
  invalid=

  validate_variables_is_empty system_name $system_name
  validate_variables_is_empty system_timezone $system_timezone
  validate_variables_is_empty root_user_name $root_user_name

  if [[ $system_clock != "utc" && $system_clock != "local" && $system_clock != "ntpdate" && $system_clock != "ntp" ]] ; then
    report_invalid_variables system_clock "is not one of: utc, local, ntpdate, or ntp"
  fi

  if [[ $system_keymap != "qwerty" && $system_keymap != "dvorak" && $system_keymap != "olpc" ]] ; then
    report_invalid_variables "system_keymap" "The system keymap can only be qwerty, dvorak, or olpc."
  fi

  validate_variables_is_yes_or_no b43_firmware_fix $b43_firmware_fix

  if [[ $destination_schema != "standard" && $destination_schema != "classic" && $destination_schema != "simple" && $destination_schema != "custom" ]] ; then
    report_invalid_variables destination_schema "is not one of: standard, classic, simple, custom"
  fi

  validate_variables_is_yes_or_no root_autologin $root_autologin
  validate_variables_is_yes_or_no admin_autologin $admin_autologin
  validate_variables_is_yes_or_no separate_boot_partition $separate_boot_partition
  validate_variables_is_yes_or_no separate_home_partition $separate_home_partition
  validate_variables_is_yes_or_no root_partition_is_encrypted $root_partition_is_encrypted
  validate_variables_is_yes_or_no home_partition_is_encrypted $home_partition_is_encrypted

  if [[ $install_boot_loader != "all" && $install_boot_loader != "grub" && $install_boot_loader != "files" && $install_boot_loader != "none" ]] ; then
    report_invalid_variables "install_boot_loader" "The install boot loader method can only be all, grub, files, or none."
  fi

  if [[ $root_partition_is_encrypted == "yes" ]] ; then
    validate_variables_is_decryption_method root_partition_decryption_method $root_partition_decryption_method
  fi

  if [[ $home_partition_is_encrypted == "yes" ]] ; then
    validate_variables_is_decryption_method home_partition_decryption_method $home_partition_decryption_method
  fi

  if [[ $admin_autologin == "yes" && $root_autologin == "yes" ]] ; then
    report_invalid_variables "root_autologin, admin_autologin" "Both root autologin and admin autologin cannot be enabled, choose one or the other."
  fi

  if [[ $squish_squash_method != "none" && $squish_squash_method != "device" && $squish_squash_method != "memory" && $squish_squash_method != "extract" ]] ; then
    report_invalid_variables "squish_squash_method" "The squish/squash method can only be none, device, memory, or extract."
  fi

  if [[ $squish_squash_method != "none" ]] ; then
    if [[ $squish_or_squash != "squish" && $squish_or_squash != "squash" ]] ; then
      report_invalid_variables "squish_or_squash" "The 'squish or squash' can only be squish or squash."
    fi
  fi

  if [[ $(echo $system_name | grep -P -s -o '^(\d|\w)(\d|\w|-|_|)*((\.)(\d|\w)(\d|\w|-|_|)*)*') == "" ]] ; then
    report_invalid_variables "System Name" "Only letters, numbers, decimals, underscores, and dashes are allowed."
  fi

  # TODO: conditionally check: boot_partition root_partition home_partition, depending on schemas
}

validate_variables_is_empty(){
  if [[ $2 == "" ]] ; then
    report_invalid_variables $1 "is empty"
  fi
}

validate_variables_is_yes_or_no(){
  if [[ $2 != "yes" && $2 != "no" ]] ; then
    report_invalid_variables $1 "is not one of: yes, no"
  fi
}

validate_variables_is_decryption_method(){
  if [[ $2 != "use_password" && $(echo $2 | grep -s -o "^use_file=") == "" ]] ; then
    report_invalid_variables $1 "is not one of: use_password, use_file="
  elif [[ $(echo $2 | grep -s -o "^use_file=") != "" && $2 == "use_file=" ]] ; then
    report_invalid_variables $1 "is use_file=, but a filename must be specified (such as: use_file=myfile)"
  fi
}

report_invalid_variables(){
  invalid="${invalid}  ${c_error}ERROR: ${c_notice}$1${c_error} $2${c_reset}\n"
}

print_input_line(){
  echo -e -n "${c_notice}#${c_reset} "
}

print_error_line(){
  echo
  print_error_line_nosleep $*
  sleep 3
}

print_error_line_nosleep(){
  echo -e "${c_error}$*${c_reset}"
}

cleanup_main(){
  standard_unset

  unset print_error_line_nosleep
  unset print_error_line
  unset print_input_line
  unset report_invalid_variables
  unset validate_variables_is_decryption_method
  unset validate_variables_is_yes_or_no
  unset validate_variables_is_empty
  unset validate_variables
  unset add_password_trick
  unset apply_this_setting_dont_show
  unset apply_this_setting
  unset perform_reboot
  unset perform_finished
  unset setup_qingy_autologin_settings
  unset temporary_unmount_system
  unset temporary_mount_system
  unset convert_to_device_path
  unset convert_partition_into_grub_format
  unset update_boot_loader_settings
  unset perform_install
  unset get_encryption_information
  unset get_partition_information
  unset configure_destination_information
  unset print_installation_error_header
  unset print_installation_header
  unset print_invalid_variables_header
  unset print_destination_information_header
  unset configure_user_information
  unset print_user_information_header
  unset configure_system_information
  unset print_system_information_header
  unset configure_system_prompt_installation_type
  unset configure_system_prompt_installation_type_header
  unset perform_configure
  unset perform_graphical_start
  unset show_help
  unset main
  unset cleanup_main
}

OLD_PATH=$PATH
PATH=/tkis//tools/lib/scripts/turtle_kevux/:$PATH
source $(type -p turtle_kevux_scripts-standard)
PATH=$OLD_PATH
unset OLD_PATH

# populate main_input variable
main_input=
main_size=$#
c1=0
c2=

while [[ $c1 -lt $main_size ]] ; do
  let c2=$c1+1
  main_input[$c1]=${!c2}
  let c1=$c1+1
done

unset c1 c2

# execute the program
standard_main_execute=main
standard_main
cleanup_main
unset main_input main_size
