From 7e8e1049647ef0fa905de404052c100c5fc8ac38 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Thu, 21 Aug 2014 17:19:22 +0000 Subject: [PATCH] when asking for a CSR country code, give the user a list --- setup/csr_country_codes.tsv | 253 ++++++++++++++++++++++++++++++++++++ setup/functions.sh | 11 ++ setup/start.sh | 18 +-- 3 files changed, 273 insertions(+), 9 deletions(-) create mode 100644 setup/csr_country_codes.tsv diff --git a/setup/csr_country_codes.tsv b/setup/csr_country_codes.tsv new file mode 100644 index 00000000..3f8f6586 --- /dev/null +++ b/setup/csr_country_codes.tsv @@ -0,0 +1,253 @@ +# This list is derived from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2. +# The columns are ISO_3166-1_alpha-2 code, display name, Wikipedia page name. +# The top 20 countries by number of Internet users are grouped first, see +# https://en.wikipedia.org/wiki/List_of_countries_by_number_of_Internet_users. +BR Brazil +CA Canada +CN China +EG Egypt +FR France +DE Germany +IN India +ID Indonesia +IT Italy +JP Japan +MX Mexico +NG Nigeria +PH Philippines +RU Russian Federation Russia +ES Spain +KR South Korea +TR Turkey +GB United Kingdom +US United States +VN Vietnam +AD Andorra +AE United Arab Emirates +AF Afghanistan +AG Antigua and Barbuda +AI Anguilla +AL Albania +AM Armenia +AO Angola +AQ Antarctica +AR Argentina +AS American Samoa +AT Austria +AU Australia +AW Aruba +AX Åland Islands +AZ Azerbaijan +BA Bosnia and Herzegovina +BB Barbados +BD Bangladesh +BE Belgium +BF Burkina Faso +BG Bulgaria +BH Bahrain +BI Burundi +BJ Benin +BL Saint Barthélemy +BM Bermuda +BN Brunei +BO Bolivia +BQ Bonaire, Sint Eustatius and Saba Caribbean Netherlands +BS Bahamas The Bahamas +BT Bhutan +BV Bouvet Island +BW Botswana +BY Belarus +BZ Belize +CC Cocos (Keeling) Islands +CD Congo, the Democratic Republic of the Democratic Republic of the Congo +CF Central African Republic +CG Congo Republic of the Congo +CH Switzerland +CI Côte d'Ivoire +CK Cook Islands +CL Chile +CM Cameroon +CO Colombia +CR Costa Rica +CU Cuba +CV Cabo Verde +CW Curaçao +CX Christmas Island +CY Cyprus +CZ Czech Republic +DJ Djibouti +DK Denmark +DM Dominica +DO Dominican Republic +DZ Algeria +EC Ecuador +EE Estonia +EH Western Sahara +ER Eritrea +ET Ethiopia +FI Finland +FJ Fiji +FK Falkland Islands (Malvinas) Falkland Islands +FM Federated States of Micronesia +FO Faroe Islands +GA Gabon +GD Grenada +GE Georgia Georgia (country) +GF French Guiana +GG Guernsey +GH Ghana +GI Gibraltar +GL Greenland +GM Gambia The Gambia +GN Guinea +GP Guadeloupe +GQ Equatorial Guinea +GR Greece +GS South Georgia and the South Sandwich Islands +GT Guatemala +GU Guam +GW Guinea-Bissau +GY Guyana +HK Hong Kong +HM Heard Island and McDonald Islands +HN Honduras +HR Croatia +HT Haiti +HU Hungary +IE Ireland Republic of Ireland +IL Israel +IM Isle of Man +IO British Indian Ocean Territory +IQ Iraq +IR Iran +IS Iceland +JE Jersey +JM Jamaica +JO Jordan +KE Kenya +KG Kyrgyzstan +KH Cambodia +KI Kiribati +KM Comoros +KN Saint Kitts and Nevis +KP North Korea +KW Kuwait +KY Cayman Islands +KZ Kazakhstan +LA Laos +LB Lebanon +LC Saint Lucia +LI Liechtenstein +LK Sri Lanka +LR Liberia +LS Lesotho +LT Lithuania +LU Luxembourg +LV Latvia +LY Libya +MA Morocco +MC Monaco +MD Moldova +ME Montenegro +MF Saint Martin (French part) Collectivity of Saint Martin +MG Madagascar +MH Marshall Islands +MK Macedonia Republic of Macedonia +ML Mali +MM Myanmar +MN Mongolia +MO Macao Macau +MP Northern Mariana Islands +MQ Martinique +MR Mauritania +MS Montserrat +MT Malta +MU Mauritius +MV Maldives +MW Malawi +MY Malaysia +MZ Mozambique +NA Namibia +NC New Caledonia +NE Niger +NF Norfolk Island +NI Nicaragua +NL Netherlands +NO Norway +NP Nepal +NR Nauru +NU Niue +NZ New Zealand +OM Oman +PA Panama +PE Peru +PF French Polynesia +PG Papua New Guinea +PK Pakistan +PL Poland +PM Saint Pierre and Miquelon +PN Pitcairn Pitcairn Islands +PR Puerto Rico +PS Palestine State of Palestine +PT Portugal +PW Palau +PY Paraguay +QA Qatar +RE Réunion +RO Romania +RS Serbia +RW Rwanda +SA Saudi Arabia +SB Solomon Islands +SC Seychelles +SD Sudan +SE Sweden +SG Singapore +SH Saint Helena, Ascension and Tristan da Cunha +SI Slovenia +SJ Svalbard and Jan Mayen +SK Slovakia +SL Sierra Leone +SM San Marino +SN Senegal +SO Somalia +SR Suriname +SS South Sudan +ST Sao Tome and Principe +SV El Salvador +SX Sint Maarten (Dutch part) Sint Maarten +SY Syria +SZ Swaziland +TC Turks and Caicos Islands +TD Chad +TF French Southern Territories French Southern and Antarctic Lands +TG Togo +TH Thailand +TJ Tajikistan +TK Tokelau +TL Timor-Leste East Timor +TM Turkmenistan +TN Tunisia +TO Tonga +TT Trinidad and Tobago +TV Tuvalu +TW Taiwan +TZ Tanzania +UA Ukraine +UG Uganda +UM United States Minor Outlying Islands +UY Uruguay +UZ Uzbekistan +VA Vatican City +VC Saint Vincent and the Grenadines +VE Venezuela +VG Virgin Islands, British British Virgin Islands +VI Virgin Islands, U.S. United States Virgin Islands +VU Vanuatu +WF Wallis and Futuna +WS Samoa +YE Yemen +YT Mayotte +ZA South Africa +ZM Zambia +ZW Zimbabwe diff --git a/setup/functions.sh b/setup/functions.sh index 67272336..78e67eda 100644 --- a/setup/functions.sh +++ b/setup/functions.sh @@ -142,3 +142,14 @@ function input_box { result=$(dialog --stdout --title "$1" --inputbox "$2" 0 0 "$3") result_code=$? } + +function input_menu { + # input_menu "title" "prompt" "tag item tag item" VARIABLE + # The user's input will be stored in the variable VARIABLE. + # The exit code from dialog will be stored in VARIABLE_EXITCODE. + declare -n result=$4 + declare -n result_code=$4_EXITCODE + local IFS=^$'\n' + result=$(dialog --stdout --title "$1" --menu "$2" 0 0 0 $3) + result_code=$? +} diff --git a/setup/start.sh b/setup/start.sh index 92326f96..8260ca38 100755 --- a/setup/start.sh +++ b/setup/start.sh @@ -213,16 +213,16 @@ if [ ! -z "$DEFAULT_STORAGE_ROOT" ] && [ ! -z "$DEFAULT_CSR_COUNTRY" ] && [ -f $ fi if [ -z "$CSR_COUNTRY" ]; then - #if [ -z "$DEFAULT_CSR_COUNTRY" ]; then - # # set a default on first run - # DEFAULT_CSR_COUNTRY=...? - #fi + # Get a list of country codes. Separate codes from country names with a ^. + # The input_menu function modifies shell word expansion to ignore spaces + # (since country names can have spaces) and use ^ instead. + country_code_list=$(grep -v "^#" setup/csr_country_codes.tsv | sed "s/\(..\)\t\([^\t]*\).*/\1^\2/") - input_box "Country Code" \ -"Enter the two-letter, uppercase country code for where you live or where your -organization is based. (This is used to create an SSL certificate.) -\n\nCountry Code:" \ - $DEFAULT_CSR_COUNTRY \ + input_menu "Country Code" \ + "Choose the country where you live or where your organization is based. + \n\n(This is used to create an SSL certificate.) + \n\nCountry Code:" \ + "$country_code_list" \ CSR_COUNTRY if [ -z "$CSR_COUNTRY" ]; then