config_query_list STUNNEL_THREADS "Select threading model:" \
                                  pthread \
                                  fork \
                                  ucontext &&

config_query_option STUNNEL_OPTS \
                    "Enable IPv6?" y \
                    "--enable-ipv6" \
                    "--disable-ipv6" &&

get_info_from_user()
{
message "${MESSAGE_COLOR}
You are about to be asked to enter information that will be incorporated into
your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank.
For some fields there will be a default value.${DEFAULT_COLOR}\n" &&

  config_query_string COUNTRY_NAME "Country Name (2 letter code)" "PL" &&

  config_query_string PROVINCE_NAME \
      "State or Province Name (full name)"  "Some-State" &&

  config_query_string LOCALITY_NAME "Locality Name (eg, city)" &&

  config_query_string ORG_NAME \
        "Organization Name (eg, company)" "Stunnel Developers Ltd" &&

  config_query_string ORG_UNIT_NAME "Organizational Unit Name (eg, section)" &&

  config_query_string COMMON_NAME \
        "Common Name (FQDN of your server)" "localhost"
}

if [ -f /etc/stunnel.pem ] ; then
  mv /etc/stunnel.pem /etc/ssl/certs/
fi &&

# Heh
if [ -f /etc/ssl/certs/stunnel.pem ] ; then
  mv /etc/ssl/certs/stunnel.pem /etc/stunnel/
fi &&

persistent_add CERTIFICATE &&

if [ ! -f /etc/stunnel/stunnel.pem ] ; then
  get_info_from_user &&

  CERTIFICATE="y"
elif [[ $CERTIFICATE == "" ]] &&
      query "Generate a self signed certificate?" n ; then
  get_info_from_user &&

  CERTIFICATE="y"
else
  CERTIFICATE="n"
fi &&

unset get_info_from_user
