#!/usr/bin/env bash
# Load functions and variables
. /usr/bin/common

export NEWT_COLORS='root=,black
border=white,black
title=white,black
roottext=red,black
window=red,black
textbox=white,black
button=black,green
compactbutton=white,black
listbox=white,black
actlistbox=black,white
actsellistbox=black,green
checkbox=green,black
actcheckbox=black,green
'

whiptail_height="$(($(tput lines) - 6))"
whiptail_width="$(($(tput cols) - 20))"

while true; do
  CHOICE="$(whiptail --nocancel --title "palen1x | use arrow keys" --menu '' $whiptail_height $whiptail_width 9 \
    '1' 'palera1n' \
    '2' 'SSH' \
    '3' 'Shell' \
    '4' 'Shut down' \
    '5' 'Exit recovery' \
    '6' 'Reboot' 3>&1 1>&2 2>&3)"
  case "$CHOICE" in
    1)
      clear
      /usr/bin/palera1n_menu
      ;;
    2)
      clear
      /usr/bin/ssh_into_ios
      ;;
    3)
      clear
      /bin/bash -i && exit
      ;;
    4)
      palen1x_logo
      sleep 2
      /sbin/poweroff
      ;;
    5)
      clear
      /usr/bin/palera1n -n
      sleep 2
      echo ""
      echo "# Your device should now boot back into normal mode."
      enter_to_quit
      /usr/bin/palen1x_menu
      ;;
    6)
      palen1x_logo
      sleep 2
      /sbin/reboot
      ;;
  esac
done
