summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2018-04-22 23:49:54 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2020-03-27 19:32:36 -0400
commitaad5fe1604829626e55ef8c5db231bce65baab04 (patch)
treec189fba6b3e4fb0dd7e1a257615f78d9bf84a276
parent95d09a997e195536b86511c333efe4960068ef63 (diff)
refactor language and keymap selection
-rwxr-xr-xconfigs/profile/root-image/root/.language.sh270
1 files changed, 144 insertions, 126 deletions
diff --git a/configs/profile/root-image/root/.language.sh b/configs/profile/root-image/root/.language.sh
index 6537d9c..c394093 100755
--- a/configs/profile/root-image/root/.language.sh
+++ b/configs/profile/root-image/root/.language.sh
@@ -1,148 +1,166 @@
#!/bin/bash
-declare -a languages=('en_US.UTF-8' "English" \
- 'eo' "Esperanto" \
- 'es_ES.UTF-8' "Spanish" \
- 'fr_FR.UTF-8' "French" \
- 'gl_ES.UTF-8' "Galego" \
- 'it_IT.UTF-8' "Italian" \
- 'pl_PL.UTF-8' "Polish" \
- 'pt_BR.UTF-8' "Brazilian Portuguese")
-declare -a keymaps=('af' "Afrikaans-lang" \
- 'al' "Albanian" \
- 'am' "Amharic" \
- 'ara' "Arabic" \
- 'at' "at" \
- 'au' "au" \
- 'az' "Azerbaijani" \
- 'ba' "Bashkir" \
- 'be' "Belarusian" \
- 'bg' "Bulgarian" \
- 'bn' "Bihari-languages" \
- 'br' "Breton" \
- 'brai' "brai" \
- 'bt' "bt" \
- 'bw' "bw" \
- 'by' "by" \
- 'ca' "Catalan" \
- 'cd' "cd" \
- 'ch' "Chamorro" \
- 'cm' "cm" \
- 'cn' "cn" \
- 'cz' "Czech" \
- 'de' "German" \
- 'dk' "dk" \
- 'dz' "Dzongkha" \
- 'ee' "Ewe" \
- 'epo' "Esperanto" \
- 'es' "Spanish" \
- 'et' "Estonian" \
- 'fi' "Finnish" \
- 'fo' "Faroese" \
- 'fr' "French" \
- 'gb' "gb" \
- 'ge' "ge" \
- 'gh' "gh" \
- 'gn' "GuaranĂ­" \
- 'gr' "gr" \
- 'hr' "Croatian" \
- 'hu' "Hungarian" \
- 'id' "Indonesian" \
- 'ie' "Interlingue" \
- 'il' "il" \
- 'in' "in" \
- 'iq' "iq" \
- 'ir' "ir" \
- 'is' "Icelandic" \
- 'it' "Italian" \
- 'jp' "Japanese" \
- 'ke' "ke" \
- 'kg' "Kongo" \
- 'kh' "kh" \
- 'kr' "Kanuri" \
- 'kz' "kz" \
- 'la' "Latin" \
- 'latam' "Latin-American" \
- 'lk' "lk" \
- 'lt' "Lithuanian" \
- 'lv' "Latvian" \
- 'ma' "ma" \
- 'mao' "Maori" \
- 'md' "md" \
- 'me' "me" \
- 'mk' "Macedonian" \
- 'ml' "Malayalam" \
- 'mm' "mm" \
- 'mn' "Mongolian" \
- 'mt' "Maltese" \
- 'mv' "mv" \
- 'my' "Burmese" \
- 'nec_vndr/jp' "nec_vndr/jp" \
- 'ng' "Ndonga" \
- 'nl' "Dutch" \
- 'no' "Norwegian" \
- 'np' "np" \
- 'ph' "ph" \
- 'pk' "pk" \
- 'pl' "Polish" \
- 'pt' "Portuguese" \
- 'ro' "Romanian" \
- 'rs' "rs" \
- 'ru' "Russian" \
- 'se' "Northern-Sami" \
- 'si' "Sinhala" \
- 'sk' "Slovak" \
- 'sn' "Shona" \
- 'sy' "sy" \
- 'tg' "Tajik" \
- 'th' "Thai" \
- 'tj' "tj" \
- 'tm' "tm" \
- 'tr' "Turkish" \
- 'tw' "Twi" \
- 'tz' "tz" \
- 'ua' "ua" \
- 'us' "English" \
- 'uz' "Uzbek" \
- 'vn' "vn" \
- 'za' "Zhuang" )
-
-
-### Comprobe if language was selected ###
+readonly TIMEOUT=30
+readonly H=15
+readonly W=40
+readonly N_ITEMS=10
+readonly DEFAULT_LANG='en_US.UTF-8'
+readonly LANG_TITLE="System language selection"
+readonly LANG_PROMPT="Choose your language:"
+readonly DEFAULT_KEYMAP='us'
+readonly KEYMAP_TITLE="System keymap selection"
+readonly KEYMAP_PROMPT="Choose your keymap:"
+readonly -a LANGUAGES=('en_US.UTF-8' "English" \
+ 'eo' "Esperanto" \
+ 'es_ES.UTF-8' "Spanish" \
+ 'fr_FR.UTF-8' "French" \
+ 'gl_ES.UTF-8' "Galego" \
+ 'it_IT.UTF-8' "Italian" \
+ 'pl_PL.UTF-8' "Polish" \
+ 'pt_BR.UTF-8' "Brazilian-Portuguese")
+readonly -a KEYMAPS=('af' "Afrikaans-Lang" \
+ 'al' "Albanian" \
+ 'am' "Amharic" \
+ 'ara' "Arabic" \
+ 'at' "at" \
+ 'au' "au" \
+ 'az' "Azerbaijani" \
+ 'ba' "Bashkir" \
+ 'be' "Belarusian" \
+ 'bg' "Bulgarian" \
+ 'bn' "Bihari-Languages" \
+ 'br' "Breton" \
+ 'brai' "brai" \
+ 'bt' "bt" \
+ 'bw' "bw" \
+ 'by' "by" \
+ 'ca' "Catalan" \
+ 'cd' "cd" \
+ 'ch' "Chamorro" \
+ 'cm' "cm" \
+ 'cn' "cn" \
+ 'cz' "Czech" \
+ 'de' "German" \
+ 'dk' "dk" \
+ 'dz' "Dzongkha" \
+ 'ee' "Ewe" \
+ 'epo' "Esperanto" \
+ 'es' "Spanish" \
+ 'et' "Estonian" \
+ 'fi' "Finnish" \
+ 'fo' "Faroese" \
+ 'fr' "French" \
+ 'gb' "gb" \
+ 'ge' "ge" \
+ 'gh' "gh" \
+ 'gn' "GuaranĂ­" \
+ 'gr' "gr" \
+ 'hr' "Croatian" \
+ 'hu' "Hungarian" \
+ 'id' "Indonesian" \
+ 'ie' "Interlingue" \
+ 'il' "il" \
+ 'in' "in" \
+ 'iq' "iq" \
+ 'ir' "ir" \
+ 'is' "Icelandic" \
+ 'it' "Italian" \
+ 'jp' "Japanese" \
+ 'ke' "ke" \
+ 'kg' "Kongo" \
+ 'kh' "kh" \
+ 'kr' "Kanuri" \
+ 'kz' "kz" \
+ 'la' "Latin" \
+ 'latam' "Latin-American" \
+ 'lk' "lk" \
+ 'lt' "Lithuanian" \
+ 'lv' "Latvian" \
+ 'ma' "ma" \
+ 'mao' "Maori" \
+ 'md' "md" \
+ 'me' "me" \
+ 'mk' "Macedonian" \
+ 'ml' "Malayalam" \
+ 'mm' "mm" \
+ 'mn' "Mongolian" \
+ 'mt' "Maltese" \
+ 'mv' "mv" \
+ 'my' "Burmese" \
+ 'nec_vndr/jp' "nec_vndr/jp" \
+ 'ng' "Ndonga" \
+ 'nl' "Dutch" \
+ 'no' "Norwegian" \
+ 'np' "np" \
+ 'ph' "ph" \
+ 'pk' "pk" \
+ 'pl' "Polish" \
+ 'pt' "Portuguese" \
+ 'ro' "Romanian" \
+ 'rs' "rs" \
+ 'ru' "Russian" \
+ 'se' "Northern-Sami" \
+ 'si' "Sinhala" \
+ 'sk' "Slovak" \
+ 'sn' "Shona" \
+ 'sy' "sy" \
+ 'tg' "Tajik" \
+ 'th' "Thai" \
+ 'tj' "tj" \
+ 'tm' "tm" \
+ 'tr' "Turkish" \
+ 'tw' "Twi" \
+ 'tz' "tz" \
+ 'ua' "ua" \
+ 'us' "English" \
+ 'uz' "Uzbek" \
+ 'vn' "vn" \
+ 'za' "Zhuang" )
+
+
+Prompt()
+{
+ local title=$1
+ local prompt=$2
+ local default_option=$3
+ local options="${@:4}"
+
+ dialog --backtitle "$title" --stdout --no-tags --no-cancel --timeout $TIMEOUT \
+ --default-item $default_option --menu "$prompt" $H $W $N_ITEMS $options
+}
+
+
+### prompt for language if not already selected ###
language=$(grep 'LANG=' /root/.codecheck | cut -d '=' -f 2)
-if [ "${language// /}" == "_UNDEFINED_" ]
-then language=$(dialog --stdout --no-tags --no-cancel --timeout 10 \
- --backtitle "System language selection" \
- --menu "Choose your language:" 15 40 10 ${languages[@]})
- [ "${language}" == "" ] && language='en_US.UTF-8'
+if [ "${language// /}" == '_UNDEFINED_' ]
+then language=$(Prompt "$LANG_TITLE" "$LANG_PROMPT" $DEFAULT_LANG "${LANGUAGES[@]}")
+ [ "${language}" == "" ] && language=$DEFAULT_LANG
+ logger "$0: selected language='$language'"
- # Copy locale in locale.conf
echo "LANG=${language}" > /etc/locale.conf
- # Confirm that language was selected
- sed -i "s/^LANG=.*/LANG=${language}/" /root/.codecheck
-
- # Copy scripts to install in that language
language=${language/_*/}
for init_de in `ls -d /root/.install-* | sed 's|/root/\.install-\(.*\)|\1|'`
do ls /root/.install-${init_de}/language/${language}/ &> /dev/null || language='en'
cp -a /root/.install-${init_de}/language/${language}/* /root/.install-${init_de}/
done
+
+ sed -i "s/^LANG=.*/LANG=${language}/" /root/.codecheck
fi
-### Comprobe if X11 keymap was selected ###
+### prompt for X11 keymap if not already selected ###
keymap=$(grep 'XKBMAP=' /root/.codecheck | cut -d '=' -f 2)
-if [ "${keymap// /}" == "_UNDEFINED_" ]
-then keymap=$(dialog --stdout --no-tags --no-cancel --timeout 10 \
- --backtitle "System keymap selection" \
- --menu "Select your keymap:" 15 40 10 ${keymaps[@]})
+if [ "${keymap// /}" == '_UNDEFINED_' ]
+then keymap=$(Prompt "$KEYMAP_TITLE" "$KEYMAP_PROMPT" $DEFAULT_KEYMAP "${KEYMAPS[@]}")
+ [ "${keymap}" == "" ] && keymap=$DEFAULT_KEYMAP
+ logger "$0: selected keymap='$keymap'"
- # Set keymapping
setxkbmap ${keymap}
- # Confirm that X11 keymap was selected
sed -i "s/^XKBMAP=.*/XKBMAP=${keymap}/" /root/.codecheck
fi
+
+clear