#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## 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

source "/usr/libexec/setup-dist/shared"

MENU_TITLE="setup-dist - 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.)"

if tty --quiet ; then
   exec 3>&1

   trap "" ERR

   dialog_wrapper_output=$(\
      dialog_wrapper \
         --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_wrapper_exit_code="$?"

   trap "error_handler" ERR

   exec 3>&-;
else
   echo "$MENU_TITLE"
   echo "$MENU_TEXT"
   echo "1" "I'm ready to enable Tor."
   echo "2" "I want to disable Tor."
   echo "3" "Tor is censored or dangerous in my area."
   echo "4" "I use proxy or firewall settings to connect to the internet."

   dialog_wrapper_output="$@"
fi

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

echo "chosen: $dialog_wrapper_output"

exit "$dialog_wrapper_output"
