#!/bin/bash

ME=${0##*/}

ZDIR=/usr/share/zoneinfo
SDIR=/etc/apt/sources.list.d

MIRROR_PREFIXES="ec gr la nl nz ut tw"
HOST_PREFIXES="$MIRROR_PREFIXES old_us"
HOST_TYPES="AX MX MP"
US_HOST_LIST="la ut"

ut_AX_HOST=http://antix.daveserver.info
ut_MP_HOST=http://mxrepo.com/mepiscr
ut_MX_HOST=http://mxrepo.com/mx

la_AX_HOST=http://iso.mxrepo.com/antix
la_MP_HOST=http://iso.mxrepo.com/mepiscr
la_MX_HOST=http://iso.mxrepo.com/mx

gr_AX_HOST=http://ftp.cc.uoc.gr/mirrors/linux/mx/antix
gr_MP_HOST=http://ftp.cc.uoc.gr/mirrors/linux/mx/mepiscr
gr_MX_HOST=http://ftp.cc.uoc.gr/mirrors/linux/mx/mx

nl_AX_HOST=http://nl.mxrepo.com/antix
nl_MP_HOST=http://nl.mxrepo.com/mepiscr
nl_MX_HOST=http://nl.mxrepo.com/mx

nz_AX_HOST=http://mx.debian.nz/antix
nz_MP_HOST=http://mx.debian.nz/mepiscr
nz_MX_HOST=http://mx.debian.nz/mx

ec_AX_HOST=http://mirror.cedia.org.ec/mx-workspace/antix
ec_MP_HOST=http://mirror.cedia.org.ec/mx-workspace/mepiscr
ec_MX_HOST=http://mirror.cedia.org.ec/mx-workspace/mx

tw_AX_HOST=http://ftp.yzu.edu.tw/Linux/mx-workspace/antix
tw_MP_HOST=http://ftp.yzu.edu.tw/Linux/mx-workspace/mepiscr
tw_MX_HOST=http://ftp.yzu.edu.tw/Linux/mx-workspace/mx

old_us_AX_HOST=http://antix.daveserver.info
old_us_MP_HOST=http://main.mepis-deb.org/mepiscr
old_us_MX_HOST=http://main.mepis-deb.org/mx

de_AX_HOST=http://de.mirror.vinzv.de/mxlinux/packages/antix
de_MP_HOST=http://de.mirror.vinzv.de/mxlinux/packages/mepiscr
de_MX_HOST=http://de.mirror.vinzv.de/mxlinux/packages/mx

fr_AX_HOST=http://fr.mirror.vinzv.de/mxlinux/packages/antix
fr_MP_HOST=http://fr.mirror.vinzv.de/mxlinux/packages/mepiscr
fr_MX_HOST=http://fr.mirror.vinzv.de/mxlinux/packages/mx

usage() {
    local ret=${1:-0}
    cat<<Usage
Usage: $me [options] <timezone|country-code|"default">

Update the mirrors in the *.list files under $SDIR/
with the closest mirrors based on timezone city or two-letter
country code.  If "default" is given then use the timezone
in the /etc/timezone file.

Options:
    -c --codes          Only display codes for the servers that would
                        be used for the given timezone
    -d --dir=<dir>      Use <dir> instead of $SDIR
    -h --help           Show this help
    -H --hosts          Only show the hosts that would be used for the
                        given timezone
    -i --ignore=<list>  Comma delimited list of MX/antiX mirrors to ignore
                        Codes: $MIRROR_PREFIXES
    -p --pretend        Don't do anything just show what would be done
    -r --random         When a US city is closest, use any US mirror at random
    -q --quiet          Print less
    -v --verbose        Print more
Usage

    exit $ret
}

main() {
    local param val short_stack="cdhHipqrv"
    while [ $# -gt 0 -a -n "$1" -a -z "${1##-*}" ]; do
        param=${1#-}
        shift

        case $param in
            [$short_stack][$short_stack]*)
                if [ -z "${param//[$short_stack]/}" ]; then
                    set -- $(echo $param | sed -r 's/([a-zA-Z])/ -\1 /g') "$@"
                    continue
                fi;;
        esac

        case $param in
          -dir|-ignore|[di]) [ $# -lt 1 ] && fatal "Expected a parameter after: -$param"
                    val=$1
                    [ -n "$val" -a -z "${val##-*}" ] \
                        && fatal "Suspicious parameter after -$param: $val"

                    shift           ;;
              *=*)  val=${param#*=} ;;
                *)  val="???"       ;;
        esac

        case $param in
          -ignore|i) IGNORE=$val                       ;;
      -ignore=*|i=*) IGNORE=$val                       ;;
           -codes|c) CODES_ONLY=true                   ;;
         -dir=*|d=*) SDIR=$val                         ;;
             -dir|d) SDIR=$val                         ;;
            -help|h) usage                             ;;
           -hosts|H) HOSTS_ONLY=true                   ;;
         -pretend|p) PRETEND=true                      ;;
           -quiet|q) QUIET=true                        ;;
          -random|r) RANDOMIZE=true                       ;;
         -verbose|v) VERBOSE=true                      ;;
                  *) fatal "Unknown argument: -$param" ;;
        esac
    done

    [ $# -lt 1 ] && usage
    [ $# -gt 1 ] && fatal "Only expected one command line argument"

    local tz=$1

    case $tz in
        */UTC) not_setting $tz ;;
    esac

    local tz_file=/etc/timezone
    if [ "$tz" = "default" ]; then
        test -r $tz_file || fatal "Could not find file $tz_file"
        read tz 2>/dev/null <$tz_file
        vsay "Current timezone: $tz"
    fi

    [ ${#tz} -lt 1 ] && fatal "Timezone or country code too short: $tz"

    case $tz in
        [a-zA-Z][a-zA-Z]) country_code_to_timezone $tz
                          tz=$NEW_TZ ;;
    esac

    local deb_code mx_order
    get_codes $tz

    vsay "deb mirror: $deb_code"
    [ ${#deb_code} -eq 0 ] && fatal "No country code found for timezone: $tz"
    [ ${#mx_order} -eq 0 ] && fatal "No MX/antiX mirrors found for timezone: $tz"

    [ "$CODES_ONLY" ] && echo -e "MX/aX code: $mx_order\n  Deb code: $deb_code"

    if [ ${#IGNORE} -gt 0 ]; then
        bl_regex=${IGNORE//,/|}
        # Remove blacklisted codes and leading commas
        mx_order=$(echo $mx_order         | sed -r -e "s/\<($bl_regex)\>//g" -e "s/^,+//" )
        US_HOST_LIST=$(echo $US_HOST_LIST | sed -r -e "s/\<($bl_regex)\>//g" -e "s/^,+//" )
    fi

    # Remove the first comma and everything after it
    local mx_code=${mx_order%%,*}

    if [ "$RANDOMIZE" ]; then
        case $mx_code in 
            la|ut) mx_code=$(random_element $US_HOST_LIST) ;;
        esac
    fi

    if [ "$HOSTS_ONLY" ]; then
        local type host
        for type in $HOST_TYPES; do
            eval host=\$${mx_code}_${type}_HOST
            echo " $type: $host"
        done
        echo "deb: ftp.$deb_code.debian.org/debian"
    fi

    [ -n "$CODES_ONLY" -o -n "$HOSTS_ONLY" ] && exit 0


    # Only update if the mirror is different from the one we want
    SED_EXPR="-e /ftp\.$deb_code\.debian\.org/!s=(http://ftp\.)[a-z][a-z](\.debian.org/debian/)=\1$deb_code\2="
    SED_EXPR_P="${SED_EXPR}p"

    assign_exprs $mx_code

    [ -d "$SDIR" ] || fatal "'$SDIR' is not a directory"

    local file fcnt=0
    for file in $(find $SDIR -maxdepth 1 -name "*.list"); do

        # Use diff to see if there would be any change to the file
        local diff=$(sed -r $SED_EXPR $file | diff -q $file -)
        [ "$diff" ] || continue

        fcnt=$((fnct + 1))
        if [ "$PRETEND" -o "$VERBOSE" ]; then
            echo "File: $(basename $file)"
            sed -n -r $SED_EXPR_P $file
        fi

        [ "$PRETEND" ] && continue

        [ -z "$VERBOSE" ] && qsay "File: $(basename $file)"
        sed -i -r $SED_EXPR $file
    done
}

# Add "-e $REGEX" and add "-e ${REGEX}p" to SED_EXPR and SED_EXPR_P.
# Totally data-driven.  Add more mirror sets and/or more mirrors by merely
# adding (and adding to) variables.  Relies on no spaces or tabs in the
# hostnames.  If this is violated then we could migrate to Bash lists.

assign_exprs() {
    local prefix=$1  type host
    for type in $HOST_TYPES; do
        eval host=\$${prefix}_${type}_HOST
        local oprefix ohost_list= ohost
        for oprefix in $HOST_PREFIXES; do
            [ "$oprefix" = "$prefix" ] && continue
            eval ohost=\$${oprefix}_${type}_HOST
            ohost_list=$ohost_list${ohost_list:+|}$ohost
        done
        ohost_list=$(echo $ohost_list | sed 's/\./\\\./g')
        local sed="s=($ohost_list)/=$host/="
        #echo SED_$type=$sed
        SED_EXPR="$SED_EXPR -e $sed"
        SED_EXPR_P="$SED_EXPR_P -e ${sed}p"
    done
}
# Output one of the input arguments at random
random_element() {
    local cnt=$#
    local rand=$(($RANDOM % cnt))
    shift $rand
    echo $1
}


find_zonetab_file() {
    local z dir=${1:-$ZDIR}

    ZONE_TAB=
    for z in zone.tab zone1970.tab; do
        test -r $dir/$z || continue
        ZONE_TAB=$dir/$z
        return 0
    done
    return 1
}

country_code_to_timezone() {
    local ccode=$1

    case $ccode in
        uk) ccode=gb ;;
    esac

    find_zonetab_file || fatal "Could not find zone.tab file"

    NEW_TZ=$(ccode_to_tz $ccode)
    [ -z "$NEW_TZ" ] && fatal "Could not find a timezone for country: $ccode"
    vsay "Found timezone: $NEW_TZ for country code: $ccode"
}

ccode_to_tz() {
    local code=$1
    cut -s -f1,3 $ZONE_TAB | grep -i "^$code\s" | head -n1 | cut -f2
}

error() {
    echo "$ME Error: $*" >&2
}

fatal() {
    echo "$ME Fatal Error: $*" >&2
    exit 5
}

not_setting() {
    local tz=$1
    printf "Not setting repository mirrors based on %s timezone\n"  "$tz"
    exit 0
}

vsay() {
    [ "$VERBOSE" ] || return
    echo "$*"
}

qsay() {
    [ "$QUIET" ] && return
    echo "$*"
}

get_codes() {
    local tz=$1
    case $tz in
                       Africa/Dakar) deb_code=pt ; mx_order=fr,nl,gr,de,ut,ec,la,tw,nz ;;
                      Africa/Banjul) deb_code=pt ; mx_order=fr,nl,gr,de,ut,ec,la,tw,nz ;;
                  Africa/Nouakchott) deb_code=pt ; mx_order=fr,nl,gr,de,ut,ec,la,tw,nz ;;
                      Africa/Bissau) deb_code=pt ; mx_order=fr,gr,nl,de,ec,ut,la,tw,nz ;;
                     Africa/Conakry) deb_code=br ; mx_order=fr,gr,nl,de,ec,ut,la,tw,nz ;;
                    Africa/Freetown) deb_code=br ; mx_order=fr,gr,nl,de,ec,ut,la,tw,nz ;;
                    Africa/El_Aaiun) deb_code=pt ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                    Africa/Monrovia) deb_code=br ; mx_order=fr,gr,nl,de,ec,ut,la,tw,nz ;;
                      Africa/Bamako) deb_code=pt ; mx_order=fr,gr,nl,de,ut,ec,la,tw,nz ;;
                  Africa/Casablanca) deb_code=pt ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                       Africa/Ceuta) deb_code=pt ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                     Africa/Abidjan) deb_code=br ; mx_order=gr,fr,nl,de,ec,ut,la,tw,nz ;;
                 Africa/Ouagadougou) deb_code=pt ; mx_order=gr,fr,nl,de,ut,ec,la,tw,nz ;;
                       Africa/Accra) deb_code=pt ; mx_order=gr,fr,nl,de,ec,ut,la,tw,nz ;;
                        Africa/Lome) deb_code=pt ; mx_order=gr,fr,nl,de,ut,ec,la,tw,nz ;;
                      Africa/Niamey) deb_code=pt ; mx_order=gr,fr,nl,de,ut,ec,la,tw,nz ;;
                       Africa/Porto) deb_code=pt ; mx_order=gr,fr,nl,de,ut,ec,la,tw,nz ;;
                     Africa/Algiers) deb_code=es ; mx_order=fr,nl,gr,de,ut,ec,la,tw,nz ;;
                       Africa/Lagos) deb_code=pt ; mx_order=gr,fr,nl,de,ut,ec,la,tw,nz ;;
                    Africa/Sao_Tome) deb_code=pt ; mx_order=gr,fr,nl,de,ec,ut,tw,la,nz ;;
                      Africa/Malabo) deb_code=gr ; mx_order=gr,fr,nl,de,ut,ec,tw,la,nz ;;
                  Africa/Libreville) deb_code=gr ; mx_order=gr,fr,nl,de,ec,ut,tw,la,nz ;;
                      Africa/Douala) deb_code=gr ; mx_order=gr,fr,nl,de,ut,ec,tw,la,nz ;;
                       Africa/Tunis) deb_code=it ; mx_order=gr,fr,de,nl,ut,ec,tw,la,nz ;;
                     Africa/Tripoli) deb_code=it ; mx_order=gr,fr,de,nl,ut,ec,tw,la,nz ;;
                      Africa/Luanda) deb_code=br ; mx_order=gr,fr,de,nl,ec,ut,tw,nz,la ;;
                    Africa/Ndjamena) deb_code=gr ; mx_order=gr,fr,de,nl,ut,ec,tw,la,nz ;;
                 Africa/Brazzaville) deb_code=gr ; mx_order=gr,fr,de,nl,ec,ut,tw,la,nz ;;
                    Africa/Kinshasa) deb_code=gr ; mx_order=gr,fr,de,nl,ec,ut,tw,la,nz ;;
                    Africa/Windhoek) deb_code=br ; mx_order=gr,fr,de,nl,ec,ut,tw,nz,la ;;
                      Africa/Bangui) deb_code=gr ; mx_order=gr,fr,de,nl,ut,ec,tw,la,nz ;;
                    Africa/Gaborone) deb_code=br ; mx_order=gr,fr,de,nl,ec,tw,nz,ut,la ;;
                  Africa/Lubumbashi) deb_code=gr ; mx_order=gr,fr,de,nl,tw,ec,ut,nz,la ;;
                      Africa/Maseru) deb_code=br ; mx_order=gr,fr,de,nl,ec,nz,tw,ut,la ;;
                Africa/Johannesburg) deb_code=br ; mx_order=gr,fr,de,nl,ec,tw,nz,ut,la ;;
                      Africa/Lusaka) deb_code=gr ; mx_order=gr,fr,de,nl,tw,ec,ut,nz,la ;;
                   Africa/Bujumbura) deb_code=gr ; mx_order=gr,fr,de,nl,tw,ut,ec,nz,la ;;
                      Africa/Kigali) deb_code=gr ; mx_order=gr,fr,de,nl,tw,ut,ec,nz,la ;;
                      Africa/Harare) deb_code=gr ; mx_order=gr,fr,de,nl,tw,ec,nz,ut,la ;;
                     Africa/Mbabane) deb_code=gr ; mx_order=gr,fr,de,nl,tw,nz,ec,ut,la ;;
                       Africa/Cairo) deb_code=gr ; mx_order=gr,de,fr,nl,tw,ut,ec,la,nz ;;
                        Africa/Juba) deb_code=gr ; mx_order=gr,de,fr,nl,tw,ut,ec,nz,la ;;
                     Africa/Kampala) deb_code=gr ; mx_order=gr,de,fr,nl,tw,ut,ec,nz,la ;;
                    Africa/Khartoum) deb_code=gr ; mx_order=gr,de,fr,nl,tw,ut,ec,la,nz ;;
                      Africa/Maputo) deb_code=ir ; mx_order=gr,fr,de,nl,tw,nz,ec,ut,la ;;
                    Africa/Blantyre) deb_code=ir ; mx_order=gr,fr,de,nl,tw,nz,ec,ut,la ;;
                     Africa/Nairobi) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,ec,nz,la ;;
                 Africa/Addis_Ababa) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,ec,nz,la ;;
                      Africa/Asmara) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,ec,nz,la ;;
               Africa/Dar_es_Salaam) deb_code=ir ; mx_order=gr,de,fr,nl,tw,nz,ut,ec,la ;;
                    Africa/Djibouti) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,nz,ec,la ;;
                   Africa/Mogadishu) deb_code=ir ; mx_order=gr,de,fr,nl,tw,nz,ut,ec,la ;;
                       America/Adak) deb_code=us ; mx_order=la,tw,ut,de,nl,fr,nz,gr,ec ;;
                       America/Nome) deb_code=us ; mx_order=la,ut,tw,nl,de,fr,gr,ec,nz ;;
                  America/Anchorage) deb_code=us ; mx_order=la,ut,nl,de,tw,fr,ec,gr,nz ;;
                    America/Yakutat) deb_code=us ; mx_order=la,ut,nl,de,fr,tw,ec,gr,nz ;;
                     America/Dawson) deb_code=ca ; mx_order=la,ut,nl,de,fr,tw,ec,gr,nz ;;
                      America/Sitka) deb_code=us ; mx_order=la,ut,nl,de,fr,ec,tw,gr,nz ;;
                 America/Whitehorse) deb_code=ca ; mx_order=la,ut,nl,de,fr,ec,tw,gr,nz ;;
                     America/Juneau) deb_code=us ; mx_order=la,ut,nl,de,fr,ec,tw,gr,nz ;;
                     America/Inuvik) deb_code=ca ; mx_order=la,ut,nl,de,fr,tw,gr,ec,nz ;;
                 America/Metlakatla) deb_code=us ; mx_order=la,ut,nl,ec,de,fr,tw,gr,nz ;;
                  America/Vancouver) deb_code=ca ; mx_order=la,ut,ec,nl,fr,de,tw,gr,nz ;;
                America/Fort_Nelson) deb_code=ca ; mx_order=la,ut,nl,de,fr,ec,gr,tw,nz ;;
               America/Dawson_Creek) deb_code=ca ; mx_order=la,ut,nl,de,fr,ec,gr,tw,nz ;;
                America/Los_Angeles) deb_code=us ; mx_order=la,ut,ec,nl,fr,de,tw,gr,nz ;;
                    America/Tijuana) deb_code=mx ; mx_order=la,ut,ec,nl,fr,de,tw,gr,nz ;;
                    America/Creston) deb_code=ca ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
                      America/Boise) deb_code=us ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
                America/Yellowknife) deb_code=ca ; mx_order=la,ut,nl,de,fr,ec,gr,tw,nz ;;
                   America/Edmonton) deb_code=ca ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
                    America/Phoenix) deb_code=us ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
                 America/Hermosillo) deb_code=mx ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
              America/Swift_Current) deb_code=ca ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
                   America/Mazatlan) deb_code=mx ; mx_order=la,ut,ec,nl,fr,de,gr,nz,tw ;;
                  America/Chihuahua) deb_code=mx ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
             America/Bahia_Banderas) deb_code=mx ; mx_order=la,ut,ec,nl,fr,de,gr,nz,tw ;;
              America/Cambridge_Bay) deb_code=ca ; mx_order=ut,la,nl,de,fr,gr,ec,tw,nz ;;
                     America/Denver) deb_code=us ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
                     America/Regina) deb_code=ca ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
                    America/Ojinaga) deb_code=mx ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
        America/North_Dakota/Beulah) deb_code=us ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
     America/North_Dakota/New_Salem) deb_code=us ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
        America/North_Dakota/Center) deb_code=us ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
                  America/Monterrey) deb_code=mx ; mx_order=la,ut,ec,nl,fr,de,gr,nz,tw ;;
                America/Mexico_City) deb_code=mx ; mx_order=la,ec,ut,fr,nl,de,gr,nz,tw ;;
                  America/Matamoros) deb_code=mx ; mx_order=la,ut,ec,nl,fr,de,gr,tw,nz ;;
                   America/Winnipeg) deb_code=ca ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
                   America/Resolute) deb_code=ca ; mx_order=ut,la,nl,de,fr,gr,ec,tw,nz ;;
                America/Rainy_River) deb_code=ca ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
               America/Rankin_Inlet) deb_code=ca ; mx_order=ut,la,nl,fr,de,ec,gr,tw,nz ;;
                   America/Atikokan) deb_code=ca ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
                  America/Guatemala) deb_code=sv ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                     America/Merida) deb_code=mx ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                America/Thunder_Bay) deb_code=ca ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
                America/El_Salvador) deb_code=sv ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                    America/Nipigon) deb_code=ca ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
                     America/Belize) deb_code=mx ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                    America/Chicago) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
                  America/Menominee) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
          America/Indiana/Vincennes) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
         America/Indiana/Petersburg) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
                America/Tegucigalpa) deb_code=sv ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                     America/Cancun) deb_code=mx ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
          America/Indiana/Tell_City) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
               America/Indiana/Knox) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
            America/Indiana/Winamac) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
            America/Indiana/Marengo) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
                    America/Managua) deb_code=sv ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
       America/Indiana/Indianapolis) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
        America/Kentucky/Louisville) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
              America/Indiana/Vevay) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
        America/Kentucky/Monticello) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
                 America/Costa_Rica) deb_code=sv ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                    America/Detroit) deb_code=us ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
                     America/Havana) deb_code=mx ; mx_order=ut,ec,la,fr,nl,de,gr,tw,nz ;;
                     America/Cayman) deb_code=mx ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                  America/Guayaquil) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                     America/Panama) deb_code=sv ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                    America/Toronto) deb_code=ca ; mx_order=ut,la,ec,nl,fr,de,gr,tw,nz ;;
                     America/Nassau) deb_code=mx ; mx_order=ut,ec,la,fr,nl,de,gr,tw,nz ;;
                       America/Lima) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                    America/Jamaica) deb_code=mx ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                     America/Bogota) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                   America/New_York) deb_code=us ; mx_order=ut,la,ec,fr,nl,de,gr,tw,nz ;;
                       America/Port) deb_code=mx ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                 America/Grand_Turk) deb_code=mx ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                   America/Santiago) deb_code=cl ; mx_order=ec,ut,la,fr,nz,nl,de,gr,tw ;;
                      America/Aruba) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
              America/Santo_Domingo) deb_code=mx ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                   America/Eirunepe) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
     America/Argentina/Rio_Gallegos) deb_code=cl ; mx_order=ec,ut,nz,la,fr,gr,nl,de,tw ;;
                    America/Curacao) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
          America/Argentina/Mendoza) deb_code=cl ; mx_order=ec,ut,la,fr,nl,nz,gr,de,tw ;;
                      America/Thule) deb_code=ca ; mx_order=nl,ut,de,fr,la,gr,ec,tw,nz ;;
         America/Argentina/San_Juan) deb_code=cl ; mx_order=ec,ut,la,fr,nl,nz,de,gr,tw ;;
                    America/Iqaluit) deb_code=ca ; mx_order=ut,nl,fr,de,la,gr,ec,tw,nz ;;
          America/Argentina/Ushuaia) deb_code=cl ; mx_order=ec,nz,ut,la,fr,gr,nl,de,tw ;;
                 America/Kralendijk) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                     America/La_Paz) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                 America/Rio_Branco) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                    America/Caracas) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
         America/Argentina/La_Rioja) deb_code=cl ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
         America/Argentina/San_Luis) deb_code=cl ; mx_order=ec,ut,la,fr,nl,nz,gr,de,tw ;;
                America/Puerto_Rico) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
        America/Argentina/Catamarca) deb_code=cl ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                America/Pangnirtung) deb_code=ca ; mx_order=ut,nl,fr,de,la,gr,ec,tw,nz ;;
            America/Argentina/Salta) deb_code=cl ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
            America/Argentina/Jujuy) deb_code=cl ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
          America/Argentina/Tucuman) deb_code=cl ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                  America/St_Thomas) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                    America/Moncton) deb_code=ca ; mx_order=ut,la,ec,fr,nl,de,gr,tw,nz ;;
                    America/Tortola) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
          America/Argentina/Cordoba) deb_code=cl ; mx_order=ec,ut,la,fr,nl,gr,de,nz,tw ;;
                America/Porto_Velho) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                    America/Halifax) deb_code=ca ; mx_order=ut,ec,la,fr,nl,de,gr,tw,nz ;;
                    America/Marigot) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                   America/Anguilla) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
              America/Lower_Princes) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
              America/St_Barthelemy) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                   America/St_Kitts) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                 America/Montserrat) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                    America/Antigua) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                    America/Grenada) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                 America/Guadeloupe) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
              America/Port_of_Spain) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                   America/Dominica) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                 America/St_Vincent) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                 America/Martinique) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                   America/St_Lucia) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
                  America/Boa_Vista) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                  America/Goose_Bay) deb_code=ca ; mx_order=ut,nl,fr,de,la,ec,gr,tw,nz ;;
                     America/Manaus) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                  America/Glace_Bay) deb_code=ca ; mx_order=ut,fr,nl,ec,la,de,gr,tw,nz ;;
                   America/Barbados) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,tw,nz ;;
     America/Argentina/Buenos_Aires) deb_code=cl ; mx_order=ec,ut,la,fr,nl,gr,de,nz,tw ;;
                     America/Guyana) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                   America/Asuncion) deb_code=br ; mx_order=ec,ut,la,fr,nl,gr,de,nz,tw ;;
                      America/Blanc) deb_code=ca ; mx_order=ut,nl,fr,de,la,ec,gr,tw,nz ;;
                   America/Miquelon) deb_code=ca ; mx_order=ut,fr,nl,de,ec,la,gr,tw,nz ;;
                 America/Montevideo) deb_code=cl ; mx_order=ec,ut,la,fr,nl,gr,de,nz,tw ;;
                     America/Cuiaba) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                 America/Paramaribo) deb_code=br ; mx_order=ec,ut,fr,la,nl,de,gr,nz,tw ;;
                   America/Santarem) deb_code=br ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
               America/Campo_Grande) deb_code=br ; mx_order=ec,ut,la,fr,nl,gr,de,nz,tw ;;
                   America/St_Johns) deb_code=ca ; mx_order=ut,fr,nl,de,ec,la,gr,tw,nz ;;
                    America/Cayenne) deb_code=br ; mx_order=ec,ut,fr,nl,la,de,gr,nz,tw ;;
                    America/Godthab) deb_code=ca ; mx_order=ut,nl,fr,de,la,gr,ec,tw,nz ;;
                      America/Belem) deb_code=br ; mx_order=ec,ut,fr,nl,de,la,gr,nz,tw ;;
                  America/Araguaina) deb_code=br ; mx_order=ec,ut,fr,nl,la,de,gr,nz,tw ;;
                  America/Sao_Paulo) deb_code=br ; mx_order=ec,ut,fr,nl,la,gr,de,nz,tw ;;
                      America/Bahia) deb_code=br ; mx_order=ec,ut,fr,nl,gr,de,la,nz,tw ;;
                  America/Fortaleza) deb_code=br ; mx_order=ec,ut,fr,nl,gr,de,la,nz,tw ;;
                     America/Maceio) deb_code=br ; mx_order=ec,ut,fr,nl,gr,de,la,nz,tw ;;
                     America/Recife) deb_code=br ; mx_order=ec,ut,fr,nl,gr,de,la,nz,tw ;;
                    America/Noronha) deb_code=br ; mx_order=ec,ut,fr,nl,gr,de,la,tw,nz ;;
               America/Scoresbysund) deb_code=ca ; mx_order=nl,de,fr,ut,gr,la,ec,tw,nz ;;
               America/Danmarkshavn) deb_code=ca ; mx_order=nl,de,fr,gr,ut,la,tw,ec,nz ;;
                 Antarctica/Rothera) deb_code=au ; mx_order=ec,nz,ut,la,gr,fr,nl,de,tw ;;
                  Antarctica/Palmer) deb_code=au ; mx_order=ec,nz,ut,la,gr,fr,nl,de,tw ;;
                   Antarctica/Troll) deb_code=au ; mx_order=nz,ec,gr,fr,tw,ut,nl,de,la ;;
                   Antarctica/Syowa) deb_code=au ; mx_order=nz,ec,gr,tw,fr,de,nl,ut,la ;;
                  Antarctica/Mawson) deb_code=au ; mx_order=nz,tw,gr,ec,fr,de,nl,ut,la ;;
                   Antarctica/Davis) deb_code=au ; mx_order=nz,tw,ec,gr,fr,de,nl,la,ut ;;
                  Antarctica/Vostok) deb_code=au ; mx_order=nz,tw,ec,gr,la,fr,de,ut,nl ;;
                   Antarctica/Casey) deb_code=au ; mx_order=nz,tw,ec,gr,la,de,fr,nl,ut ;;
          Antarctica/DumontDUrville) deb_code=au ; mx_order=nz,tw,ec,la,gr,ut,de,fr,nl ;;
               Antarctica/Macquarie) deb_code=au ; mx_order=nz,tw,la,ec,ut,gr,de,fr,nl ;;
                 Antarctica/McMurdo) deb_code=au ; mx_order=nz,ec,tw,la,ut,gr,fr,de,nl ;;
                Arctic/Longyearbyen) deb_code=is ; mx_order=de,nl,fr,gr,ut,la,tw,ec,nz ;;
                       Asia/Nicosia) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,ec,la,nz ;;
                          Asia/Gaza) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,ec,la,nz ;;
                        Asia/Hebron) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,ec,la,nz ;;
                     Asia/Jerusalem) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,ec,la,nz ;;
                        Asia/Beirut) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,ec,la,nz ;;
                         Asia/Amman) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,ec,la,nz ;;
                      Asia/Damascus) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,ec,la,nz ;;
                       Asia/Baghdad) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,ec,la,nz ;;
                       Asia/Yerevan) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,la,ec,nz ;;
                       Asia/Tbilisi) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,la,ec,nz ;;
                          Asia/Aden) deb_code=ir ; mx_order=gr,de,fr,nl,tw,ut,nz,ec,la ;;
                        Asia/Riyadh) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,nz,ec,la ;;
                        Asia/Kuwait) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,ec,la,nz ;;
                          Asia/Baku) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,la,ec,nz ;;
                         Asia/Aqtau) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,la,ec,nz ;;
                       Asia/Bahrain) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,nz,ec,la ;;
                          Asia/Oral) deb_code=ru ; mx_order=de,gr,nl,fr,tw,ut,la,ec,nz ;;
                        Asia/Tehran) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,la,nz,ec ;;
                         Asia/Qatar) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,nz,ec,la ;;
                         Asia/Dubai) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,nz,la,ec ;;
                        Asia/Aqtobe) deb_code=ru ; mx_order=gr,de,nl,fr,tw,ut,la,ec,nz ;;
                      Asia/Ashgabat) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,la,nz,ec ;;
                        Asia/Muscat) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,nz,la,ec ;;
                 Asia/Yekaterinburg) deb_code=ru ; mx_order=de,gr,nl,fr,tw,ut,la,ec,nz ;;
                     Asia/Qyzylorda) deb_code=ru ; mx_order=gr,de,nl,fr,tw,ut,la,nz,ec ;;
                     Asia/Samarkand) deb_code=ir ; mx_order=gr,de,nl,fr,tw,ut,nz,la,ec ;;
                       Asia/Karachi) deb_code=ir ; mx_order=gr,tw,de,nl,fr,nz,ut,la,ec ;;
                      Asia/Dushanbe) deb_code=ir ; mx_order=gr,de,nl,tw,fr,ut,nz,la,ec ;;
                         Asia/Kabul) deb_code=ir ; mx_order=gr,de,tw,nl,fr,ut,nz,la,ec ;;
                      Asia/Tashkent) deb_code=cn ; mx_order=gr,de,nl,tw,fr,ut,nz,la,ec ;;
                          Asia/Omsk) deb_code=ru ; mx_order=de,gr,nl,fr,tw,ut,la,nz,ec ;;
                       Asia/Bishkek) deb_code=cn ; mx_order=gr,de,tw,nl,fr,ut,nz,la,ec ;;
                        Asia/Almaty) deb_code=ru ; mx_order=gr,tw,de,nl,fr,ut,nz,la,ec ;;
                       Asia/Colombo) deb_code=th ; mx_order=tw,gr,de,nl,fr,nz,ut,la,ec ;;
                   Asia/Novosibirsk) deb_code=ru ; mx_order=de,tw,gr,nl,fr,ut,la,nz,ec ;;
                       Asia/Barnaul) deb_code=ru ; mx_order=tw,de,gr,nl,fr,ut,la,nz,ec ;;
                     Asia/Kathmandu) deb_code=cn ; mx_order=tw,gr,de,nl,fr,nz,ut,la,ec ;;
                  Asia/Novokuznetsk) deb_code=ru ; mx_order=tw,de,gr,nl,fr,ut,la,nz,ec ;;
                        Asia/Urumqi) deb_code=cn ; mx_order=tw,gr,de,nl,fr,nz,ut,la,ec ;;
                       Asia/Kolkata) deb_code=th ; mx_order=tw,gr,de,nl,fr,nz,ut,la,ec ;;
                       Asia/Thimphu) deb_code=cn ; mx_order=tw,gr,de,nl,fr,nz,ut,la,ec ;;
                         Asia/Dhaka) deb_code=th ; mx_order=tw,gr,de,nl,fr,nz,ut,la,ec ;;
                          Asia/Hovd) deb_code=cn ; mx_order=tw,de,gr,nl,fr,ut,nz,la,ec ;;
                   Asia/Krasnoyarsk) deb_code=ru ; mx_order=tw,de,nl,gr,fr,ut,la,nz,ec ;;
                       Asia/Rangoon) deb_code=th ; mx_order=tw,gr,nz,de,nl,fr,la,ut,ec ;;
                       Asia/Bangkok) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                  Asia/Kuala_Lumpur) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                     Asia/Vientiane) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                     Asia/Singapore) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                       Asia/Irkutsk) deb_code=ru ; mx_order=tw,de,nl,gr,fr,la,ut,nz,ec ;;
                    Asia/Phnom_Penh) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                   Asia/Ho_Chi_Minh) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                       Asia/Jakarta) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                   Asia/Ulaanbaatar) deb_code=ru ; mx_order=tw,de,gr,nl,fr,nz,la,ut,ec ;;
                     Asia/Pontianak) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                       Asia/Kuching) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                         Asia/Chita) deb_code=ru ; mx_order=tw,de,nl,gr,fr,la,nz,ut,ec ;;
                         Asia/Macau) deb_code=hk ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                     Asia/Hong_Kong) deb_code=hk ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                    Asia/Choibalsan) deb_code=ru ; mx_order=tw,de,nl,gr,fr,nz,la,ut,ec ;;
                        Asia/Brunei) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                      Asia/Makassar) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                        Asia/Manila) deb_code=hk ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                      Asia/Shanghai) deb_code=cn ; mx_order=tw,nz,de,gr,nl,fr,la,ut,ec ;;
                        Asia/Taipei) deb_code=tw ; mx_order=tw,nz,de,gr,nl,fr,la,ut,ec ;;
                          Asia/Dili) deb_code=hk ; mx_order=nz,tw,gr,de,nl,la,fr,ut,ec ;;
                     Asia/Pyongyang) deb_code=kr ; mx_order=tw,nz,de,gr,nl,fr,la,ut,ec ;;
                         Asia/Seoul) deb_code=kr ; mx_order=tw,nz,de,gr,nl,fr,la,ut,ec ;;
                       Asia/Yakutsk) deb_code=ru ; mx_order=tw,de,nl,fr,gr,la,ut,nz,ec ;;
                   Asia/Vladivostok) deb_code=ru ; mx_order=tw,de,nz,nl,gr,fr,la,ut,ec ;;
                      Asia/Khandyga) deb_code=ru ; mx_order=tw,de,nl,fr,gr,la,ut,nz,ec ;;
                         Asia/Tokyo) deb_code=jp ; mx_order=tw,nz,la,de,nl,gr,fr,ut,ec ;;
                      Asia/Jayapura) deb_code=tw ; mx_order=nz,tw,la,gr,de,nl,fr,ut,ec ;;
                      Asia/Sakhalin) deb_code=ru ; mx_order=tw,la,de,nz,nl,fr,gr,ut,ec ;;
                           Asia/Ust) deb_code=ru ; mx_order=tw,de,nl,fr,la,gr,ut,nz,ec ;;
                       Asia/Magadan) deb_code=ru ; mx_order=tw,la,de,nl,fr,gr,ut,nz,ec ;;
                 Asia/Srednekolymsk) deb_code=ru ; mx_order=tw,de,nl,la,fr,ut,gr,nz,ec ;;
                     Asia/Kamchatka) deb_code=ru ; mx_order=tw,la,de,nl,ut,fr,nz,gr,ec ;;
                        Asia/Anadyr) deb_code=ru ; mx_order=la,tw,ut,de,nl,fr,gr,nz,ec ;;
                   Atlantic/Bermuda) deb_code=pt ; mx_order=ut,ec,la,fr,nl,de,gr,tw,nz ;;
                   Atlantic/Stanley) deb_code=pt ; mx_order=ec,ut,nz,la,fr,gr,nl,de,tw ;;
             Atlantic/South_Georgia) deb_code=pt ; mx_order=ec,nz,ut,gr,fr,nl,la,de,tw ;;
                    Atlantic/Azores) deb_code=pt ; mx_order=fr,nl,de,ut,gr,ec,la,tw,nz ;;
                Atlantic/Cape_Verde) deb_code=pt ; mx_order=fr,nl,gr,de,ec,ut,la,tw,nz ;;
                 Atlantic/Reykjavik) deb_code=is ; mx_order=nl,fr,de,gr,ut,la,ec,tw,nz ;;
                   Atlantic/Madeira) deb_code=pt ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                    Atlantic/Canary) deb_code=pt ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                     Atlantic/Faroe) deb_code=is ; mx_order=nl,de,fr,gr,ut,la,ec,tw,nz ;;
                 Atlantic/St_Helena) deb_code=pt ; mx_order=gr,fr,nl,de,ec,ut,la,tw,nz ;;
                    Australia/Perth) deb_code=au ; mx_order=nz,tw,gr,de,nl,fr,la,ec,ut ;;
                    Australia/Eucla) deb_code=au ; mx_order=nz,tw,gr,la,de,nl,fr,ec,ut ;;
                   Australia/Darwin) deb_code=au ; mx_order=nz,tw,gr,la,de,nl,fr,ut,ec ;;
                 Australia/Adelaide) deb_code=au ; mx_order=nz,tw,la,gr,ec,de,nl,fr,ut ;;
              Australia/Broken_Hill) deb_code=au ; mx_order=nz,tw,la,gr,ec,de,nl,fr,ut ;;
                   Australia/Currie) deb_code=au ; mx_order=nz,tw,la,ec,gr,de,nl,fr,ut ;;
                Australia/Melbourne) deb_code=au ; mx_order=nz,tw,la,ec,gr,de,nl,ut,fr ;;
                   Australia/Hobart) deb_code=au ; mx_order=nz,tw,la,ec,gr,de,ut,nl,fr ;;
                 Australia/Lindeman) deb_code=au ; mx_order=nz,tw,la,gr,de,ec,nl,ut,fr ;;
                   Australia/Sydney) deb_code=au ; mx_order=nz,tw,la,ec,gr,ut,de,nl,fr ;;
                 Australia/Brisbane) deb_code=au ; mx_order=nz,tw,la,ec,gr,ut,de,nl,fr ;;
                Australia/Lord_Howe) deb_code=au ; mx_order=nz,tw,la,ec,ut,gr,de,nl,fr ;;
                      Europe/Lisbon) deb_code=pt ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                      Europe/Dublin) deb_code=ie ; mx_order=nl,fr,de,gr,ut,ec,la,tw,nz ;;
                   Europe/Gibraltar) deb_code=pt ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                 Europe/Isle_of_Man) deb_code=ie ; mx_order=nl,fr,de,gr,ut,ec,la,tw,nz ;;
                      Europe/Madrid) deb_code=es ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                    Europe/Guernsey) deb_code=uk ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                      Europe/Jersey) deb_code=uk ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                      Europe/London) deb_code=uk ; mx_order=nl,fr,de,gr,ut,ec,la,tw,nz ;;
                     Europe/Andorra) deb_code=es ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                       Europe/Paris) deb_code=fr ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                    Europe/Brussels) deb_code=be ; mx_order=nl,fr,de,gr,ut,ec,la,tw,nz ;;
                   Europe/Amsterdam) deb_code=nl ; mx_order=nl,fr,de,gr,ut,ec,la,tw,nz ;;
                  Europe/Luxembourg) deb_code=be ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                      Europe/Monaco) deb_code=ch ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                      Europe/Zurich) deb_code=ch ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                    Europe/Busingen) deb_code=de ; mx_order=fr,nl,de,gr,ut,ec,la,tw,nz ;;
                       Europe/Vaduz) deb_code=ch ; mx_order=fr,de,nl,gr,ut,ec,tw,la,nz ;;
                        Europe/Oslo) deb_code=no ; mx_order=de,nl,fr,gr,ut,la,tw,ec,nz ;;
                     Europe/Vatican) deb_code=it ; mx_order=gr,fr,de,nl,ut,ec,tw,la,nz ;;
                  Europe/San_Marino) deb_code=it ; mx_order=fr,de,nl,gr,ut,ec,tw,la,nz ;;
                        Europe/Rome) deb_code=it ; mx_order=gr,fr,de,nl,ut,ec,tw,la,nz ;;
                  Europe/Copenhagen) deb_code=dk ; mx_order=de,nl,fr,gr,ut,tw,la,ec,nz ;;
                      Europe/Berlin) deb_code=de ; mx_order=de,nl,fr,gr,ut,tw,la,ec,nz ;;
                      Europe/Prague) deb_code=cz ; mx_order=de,nl,fr,gr,ut,tw,ec,la,nz ;;
                       Europe/Malta) deb_code=it ; mx_order=gr,fr,de,nl,ut,ec,tw,la,nz ;;
                   Europe/Ljubljana) deb_code=si ; mx_order=de,fr,nl,gr,ut,tw,ec,la,nz ;;
                      Europe/Zagreb) deb_code=hr ; mx_order=de,fr,gr,nl,ut,tw,ec,la,nz ;;
                      Europe/Vienna) deb_code=at ; mx_order=de,nl,fr,gr,ut,tw,ec,la,nz ;;
                  Europe/Bratislava) deb_code=sk ; mx_order=de,nl,fr,gr,ut,tw,ec,la,nz ;;
                   Europe/Stockholm) deb_code=se ; mx_order=de,nl,fr,gr,ut,tw,la,ec,nz ;;
                    Europe/Sarajevo) deb_code=hr ; mx_order=gr,de,fr,nl,ut,tw,ec,la,nz ;;
                    Europe/Budapest) deb_code=hu ; mx_order=de,gr,nl,fr,ut,tw,ec,la,nz ;;
                   Europe/Podgorica) deb_code=bg ; mx_order=gr,de,fr,nl,ut,tw,ec,la,nz ;;
                      Europe/Tirane) deb_code=bg ; mx_order=gr,de,fr,nl,ut,tw,ec,la,nz ;;
                   Europe/Mariehamn) deb_code=se ; mx_order=de,nl,fr,gr,ut,tw,la,ec,nz ;;
                    Europe/Belgrade) deb_code=hu ; mx_order=gr,de,nl,fr,ut,tw,ec,la,nz ;;
                 Europe/Kaliningrad) deb_code=ru ; mx_order=de,nl,fr,gr,ut,tw,la,ec,nz ;;
                      Europe/Warsaw) deb_code=pl ; mx_order=de,nl,fr,gr,ut,tw,la,ec,nz ;;
                      Europe/Skopje) deb_code=bg ; mx_order=gr,de,fr,nl,ut,tw,ec,la,nz ;;
                    Europe/Uzhgorod) deb_code=ua ; mx_order=de,gr,nl,fr,ut,tw,la,ec,nz ;;
                       Europe/Sofia) deb_code=bg ; mx_order=gr,de,fr,nl,ut,tw,ec,la,nz ;;
                      Europe/Athens) deb_code=gr ; mx_order=gr,de,fr,nl,ut,tw,ec,la,nz ;;
                        Europe/Riga) deb_code=lt ; mx_order=de,nl,fr,gr,ut,tw,la,ec,nz ;;
                     Europe/Tallinn) deb_code=ee ; mx_order=de,nl,fr,gr,ut,tw,la,ec,nz ;;
                    Europe/Helsinki) deb_code=fi ; mx_order=de,nl,fr,gr,ut,tw,la,ec,nz ;;
                     Europe/Vilnius) deb_code=lt ; mx_order=de,nl,fr,gr,ut,tw,la,ec,nz ;;
                   Europe/Bucharest) deb_code=ro ; mx_order=gr,de,nl,fr,ut,tw,ec,la,nz ;;
                       Europe/Minsk) deb_code=by ; mx_order=de,nl,gr,fr,ut,tw,la,ec,nz ;;
                    Europe/Chisinau) deb_code=ro ; mx_order=gr,de,nl,fr,ut,tw,la,ec,nz ;;
                    Europe/Istanbul) deb_code=tr ; mx_order=gr,de,nl,fr,ut,tw,ec,la,nz ;;
                        Europe/Kiev) deb_code=ua ; mx_order=de,gr,nl,fr,ut,tw,la,ec,nz ;;
                  Europe/Simferopol) deb_code=ru ; mx_order=gr,de,nl,fr,tw,ut,la,ec,nz ;;
                  Europe/Zaporozhye) deb_code=ua ; mx_order=gr,de,nl,fr,tw,ut,la,ec,nz ;;
                      Europe/Moscow) deb_code=ru ; mx_order=de,nl,gr,fr,tw,ut,la,ec,nz ;;
                   Europe/Volgograd) deb_code=ru ; mx_order=gr,de,nl,fr,tw,ut,la,ec,nz ;;
                   Europe/Astrakhan) deb_code=ru ; mx_order=gr,de,nl,fr,tw,ut,la,ec,nz ;;
                   Europe/Ulyanovsk) deb_code=ru ; mx_order=de,gr,nl,fr,tw,ut,la,ec,nz ;;
                      Europe/Samara) deb_code=ru ; mx_order=de,gr,nl,fr,tw,ut,la,ec,nz ;;
                      Indian/Comoro) deb_code=ir ; mx_order=gr,de,fr,nl,tw,nz,ec,ut,la ;;
                     Indian/Mayotte) deb_code=ir ; mx_order=gr,de,fr,nl,tw,nz,ec,ut,la ;;
                Indian/Antananarivo) deb_code=ir ; mx_order=gr,de,fr,nl,tw,nz,ec,ut,la ;;
                     Indian/Reunion) deb_code=au ; mx_order=gr,tw,de,fr,nl,nz,ec,ut,la ;;
                        Indian/Mahe) deb_code=ir ; mx_order=gr,de,fr,tw,nl,nz,ut,ec,la ;;
                   Indian/Mauritius) deb_code=au ; mx_order=gr,tw,de,fr,nl,nz,ec,ut,la ;;
                   Indian/Kerguelen) deb_code=au ; mx_order=nz,tw,gr,de,fr,nl,ec,ut,la ;;
                      Indian/Chagos) deb_code=th ; mx_order=tw,gr,de,nz,nl,fr,ut,ec,la ;;
                    Indian/Maldives) deb_code=th ; mx_order=tw,gr,de,nl,fr,nz,ut,la,ec ;;
                       Indian/Cocos) deb_code=th ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                   Indian/Christmas) deb_code=au ; mx_order=tw,nz,gr,de,nl,fr,la,ut,ec ;;
                     Pacific/Midway) deb_code=us ; mx_order=la,tw,nz,ut,de,ec,nl,fr,gr ;;
                    Pacific/Chatham) deb_code=nz ; mx_order=nz,tw,la,ec,ut,gr,de,nl,fr ;;
                     Pacific/Wallis) deb_code=nc ; mx_order=nz,tw,la,ec,ut,de,nl,fr,gr ;;
                  Pacific/Tongatapu) deb_code=nc ; mx_order=nz,tw,la,ec,ut,de,nl,fr,gr ;;
                       Pacific/Apia) deb_code=nc ; mx_order=nz,la,tw,ec,ut,de,nl,fr,gr ;;
                    Pacific/Fakaofo) deb_code=nc ; mx_order=nz,la,tw,ec,ut,de,nl,fr,gr ;;
                  Pacific/Enderbury) deb_code=us ; mx_order=nz,la,tw,ec,ut,de,nl,fr,gr ;;
                  Pacific/Pago_Pago) deb_code=nc ; mx_order=nz,la,tw,ec,ut,nl,de,fr,gr ;;
                       Pacific/Niue) deb_code=nz ; mx_order=nz,la,tw,ec,ut,nl,de,fr,gr ;;
                   Pacific/Johnston) deb_code=us ; mx_order=la,nz,tw,ut,ec,nl,de,fr,gr ;;
                  Pacific/Rarotonga) deb_code=nz ; mx_order=nz,la,ec,tw,ut,nl,de,fr,gr ;;
                   Pacific/Honolulu) deb_code=us ; mx_order=la,nz,ut,tw,ec,nl,de,fr,gr ;;
                 Pacific/Kiritimati) deb_code=us ; mx_order=la,nz,tw,ec,ut,nl,de,fr,gr ;;
                     Pacific/Tahiti) deb_code=nz ; mx_order=nz,la,ec,ut,tw,nl,fr,de,gr ;;
                  Pacific/Marquesas) deb_code=cl ; mx_order=la,nz,ec,ut,tw,nl,fr,de,gr ;;
                    Pacific/Gambier) deb_code=cl ; mx_order=la,nz,ec,ut,tw,nl,fr,de,gr ;;
                   Pacific/Pitcairn) deb_code=cl ; mx_order=la,ec,nz,ut,tw,fr,nl,de,gr ;;
                     Pacific/Easter) deb_code=cl ; mx_order=ec,la,ut,nz,fr,nl,de,tw,gr ;;
                  Pacific/Galapagos) deb_code=cl ; mx_order=ec,ut,la,fr,nl,de,gr,nz,tw ;;
                      Pacific/Palau) deb_code=nc ; mx_order=tw,nz,la,gr,de,nl,fr,ut,ec ;;
                       Pacific/Guam) deb_code=nc ; mx_order=tw,nz,la,de,gr,nl,fr,ut,ec ;;
                     Pacific/Saipan) deb_code=nc ; mx_order=tw,nz,la,de,gr,nl,fr,ut,ec ;;
               Pacific/Port_Moresby) deb_code=nc ; mx_order=nz,tw,la,gr,de,nl,fr,ut,ec ;;
                      Pacific/Chuuk) deb_code=nc ; mx_order=tw,nz,la,de,gr,nl,ut,fr,ec ;;
               Pacific/Bougainville) deb_code=nc ; mx_order=nz,tw,la,ut,de,gr,nl,ec,fr ;;
                    Pacific/Pohnpei) deb_code=nc ; mx_order=nz,tw,la,ut,de,nl,gr,fr,ec ;;
                Pacific/Guadalcanal) deb_code=nc ; mx_order=nz,tw,la,ut,ec,de,gr,nl,fr ;;
                     Pacific/Kosrae) deb_code=nc ; mx_order=nz,tw,la,ut,de,nl,ec,gr,fr ;;
                     Pacific/Noumea) deb_code=nc ; mx_order=nz,tw,la,ec,ut,de,gr,nl,fr ;;
                       Pacific/Wake) deb_code=us ; mx_order=tw,nz,la,ut,de,nl,fr,gr,ec ;;
                      Pacific/Nauru) deb_code=nc ; mx_order=nz,tw,la,ut,ec,de,nl,gr,fr ;;
                  Pacific/Kwajalein) deb_code=nc ; mx_order=nz,tw,la,ut,de,nl,ec,fr,gr ;;
                    Pacific/Norfolk) deb_code=nc ; mx_order=nz,tw,la,ec,ut,gr,de,nl,fr ;;
                      Pacific/Efate) deb_code=nc ; mx_order=nz,tw,la,ec,ut,de,nl,gr,fr ;;
                     Pacific/Majuro) deb_code=nc ; mx_order=nz,tw,la,ut,ec,de,nl,fr,gr ;;
                     Pacific/Tarawa) deb_code=nc ; mx_order=nz,tw,la,ut,ec,de,nl,fr,gr ;;
                   Pacific/Auckland) deb_code=nz ; mx_order=nz,tw,la,ec,ut,gr,de,nl,fr ;;
                       Pacific/Fiji) deb_code=nc ; mx_order=nz,tw,la,ec,ut,de,nl,fr,gr ;;
                   Pacific/Funafuti) deb_code=nc ; mx_order=nz,tw,la,ec,ut,de,nl,fr,gr ;;
    esac
}

main "$@"
