#!/bin/bash

## Copyright (C) 2012 - 2020 ENCRYPTED SUPPORT LP <adrelanos@riseup.net>
## See the file COPYING for copying conditions.

## Debugging
#set -x

set -o pipefail

error_handler() {
   local MSG="\
###########################################################
## Something went wrong. Please report this bug!
##
## BASH_COMMAND: $BASH_COMMAND
###########################################################\
"
   echo "$MSG"
   exit 1
}

trap "error_handler" ERR

MENU_TITLE="whonixsetup - Connection Wizard"

MENU_TEXT="Before we let Tor connect, we need to know about your Internet connection.

Which of the following applies to you?

(Please scroll down using the arrow keys.)"

exec 3>&1

trap "" ERR

dialog_output=$(\
   dialog \
      --title "$MENU_TITLE" \
      --menu "$MENU_TEXT" \
         100 120 20 \
         "1" "I'm ready to enable Tor." \
         "2" "I want to disable Tor." \
         "3" "Tor is censored or dangerous in my area." \
         "4" "I use proxy or firewall settings to connect to the internet." \
         2>&1 1>&3)

dialog_exit_code="$?"

trap "error_handler" ERR

exec 3>&-;

if [ "$dialog_output" = "" ]; then
   true "INFO: Cancel button was pressed."
   dialog_output="0"
fi

exit "$dialog_output"
