| 1 |
#!/bin/sh -e
|
| 2 |
|
| 3 |
. /usr/share/debconf/confmodule
|
| 4 |
|
| 5 |
db_capb backup
|
| 6 |
|
| 7 |
INDENT=" "
|
| 8 |
|
| 9 |
localecode="debian-installer/locale"
|
| 10 |
langname="languagechooser/language-name"
|
| 11 |
fallbacklocalecode="debian-installer/fallbacklocale"
|
| 12 |
languagecode="debian-installer/language"
|
| 13 |
countrycode="debian-installer/country"
|
| 14 |
consoledisplay="debian-installer/consoledisplay"
|
| 15 |
shortlist="countrychooser/country-name-shortlist"
|
| 16 |
fulllist="countrychooser/country-name"
|
| 17 |
|
| 18 |
# This is the iso_3166.tab file location
|
| 19 |
ISO3166TAB=/usr/share/iso-codes/iso_3166.tab
|
| 20 |
SUPPORTEDLOCALES=/etc/SUPPORTED-short
|
| 21 |
SHORTLISTS=/etc/shortlists
|
| 22 |
|
| 23 |
for list in $ISO3166TAB ; do
|
| 24 |
if [ -f "$list" ]; then
|
| 25 |
countries="$list"
|
| 26 |
fi
|
| 27 |
done
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
error() {
|
| 32 |
logger -t localechooser "error: $@"
|
| 33 |
exit 1
|
| 34 |
}
|
| 35 |
|
| 36 |
|
| 37 |
log() {
|
| 38 |
logger -t localechooser "info: $@"
|
| 39 |
}
|
| 40 |
|
| 41 |
|
| 42 |
code2country() {
|
| 43 |
if [ -n "$1" ] ; then
|
| 44 |
line=`grep "$1" $countries`
|
| 45 |
|
| 46 |
if [ -n "$line" ]; then
|
| 47 |
# Remember that country names may have spaces so the code
|
| 48 |
# is different than in country2code.
|
| 49 |
printf "$INDENT"
|
| 50 |
echo $line | cut -b 4-
|
| 51 |
else
|
| 52 |
error "Unable to locate info on country '$COUNTRYCODE'"
|
| 53 |
fi
|
| 54 |
else
|
| 55 |
error "Missing argument"
|
| 56 |
fi
|
| 57 |
}
|
| 58 |
|
| 59 |
country2code() {
|
| 60 |
COUNTRYNAME=$(echo "$1" | sed "s/^$INDENT//" | sed 's/\\,/,/g')
|
| 61 |
line=`grep "$COUNTRYNAME$" $countries`
|
| 62 |
|
| 63 |
if [ -n "$line" ]; then
|
| 64 |
set $line
|
| 65 |
if [ -n "$1" ]; then
|
| 66 |
echo "$1"
|
| 67 |
fi
|
| 68 |
fi
|
| 69 |
}
|
| 70 |
|
| 71 |
locale2langname() {
|
| 72 |
if [ ! -f $2 ] ; then
|
| 73 |
echo "$2 does not exist"
|
| 74 |
exit 1
|
| 75 |
fi
|
| 76 |
# Match the full locale with 2nd field in languagelist
|
| 77 |
line=$(cat $2 | grep -v "^#" | cut -f1,2 -d\;|grep ";$1")
|
| 78 |
if [ -z "$line" ] ; then
|
| 79 |
# Only match the language part
|
| 80 |
langpart=$(echo $1 | cut -f1 -d_)
|
| 81 |
line=$(cat $2 | grep -v "^#" | cut -f1,2 -d\;|grep ";${langpart}")
|
| 82 |
fi
|
| 83 |
echo $line | cut -f1 -d\;
|
| 84 |
}
|
| 85 |
|
| 86 |
locale2countrycode(){
|
| 87 |
if [ -n "$1" ] ; then
|
| 88 |
echo $1 | cut -f2 -d_ | cut -f1 -d@ | cut -f1 -d\.
|
| 89 |
else
|
| 90 |
error "Missing argument"
|
| 91 |
fi
|
| 92 |
}
|
| 93 |
|
| 94 |
# This function performs several tasks:
|
| 95 |
# - Search in $COUNTRY_SHORTLIST for either a coutrycode or a countryname
|
| 96 |
# - Build a shortlist for the dialog
|
| 97 |
get_shortlist() {
|
| 98 |
OLD_IFS="$IFS"
|
| 99 |
IFS=$(echo -en "\t")
|
| 100 |
SLIST=""
|
| 101 |
count=0
|
| 102 |
for value in $COUNTRY_SHORTLIST; do
|
| 103 |
count=$(($count+1))
|
| 104 |
if [ "$(($count % 2))" -eq 1 ] ; then
|
| 105 |
CCODE=$value
|
| 106 |
else
|
| 107 |
CNAME=$value
|
| 108 |
case "$1" in
|
| 109 |
code)
|
| 110 |
if [ "$CNAME" = "$2" ] ; then
|
| 111 |
echo $CCODE
|
| 112 |
break
|
| 113 |
fi
|
| 114 |
;;
|
| 115 |
name)
|
| 116 |
if [ "$CCODE" = "$2" ] ; then
|
| 117 |
echo $CNAME
|
| 118 |
break
|
| 119 |
fi
|
| 120 |
;;
|
| 121 |
shortlist)
|
| 122 |
if [ ! -z "${SLIST}" ]; then
|
| 123 |
SLIST="${SLIST}, "
|
| 124 |
fi
|
| 125 |
SL_NAME=$(echo "${INDENT}${CNAME}" | sed -e 's/,/\\,/')
|
| 126 |
SLIST="${SLIST}${SL_NAME}"
|
| 127 |
;;
|
| 128 |
esac
|
| 129 |
fi
|
| 130 |
done
|
| 131 |
if [ "$1" = "shortlist" ] ; then
|
| 132 |
echo "$SLIST"
|
| 133 |
fi
|
| 134 |
IFS="$OLD_IFS"
|
| 135 |
}
|
| 136 |
|
| 137 |
loccountry2code() {
|
| 138 |
COUNTRYNAME=$(echo "$1" | sed "s/^$INDENT//" | sed 's/\\,/,/g')
|
| 139 |
echo $(get_shortlist code "$COUNTRYNAME")
|
| 140 |
}
|
| 141 |
|
| 142 |
|
| 143 |
# Begin languagechooser part
|
| 144 |
# debconf/language is an alias for debian-installer/language
|
| 145 |
db_register "$languagecode" "debconf/language"
|
| 146 |
|
| 147 |
# Only display the translated texts (ie the English "translation")
|
| 148 |
# when in UTF-8 mode.
|
| 149 |
if ( echo $LANG $LC_CTYPE | grep -q UTF-8 ); then
|
| 150 |
db_set debconf/language en
|
| 151 |
else
|
| 152 |
db_set debconf/language C
|
| 153 |
fi
|
| 154 |
|
| 155 |
# First of all, analyse debian-installer/locale and
|
| 156 |
# populate debconf with it
|
| 157 |
db_get $localecode
|
| 158 |
if test "$RET" ; then
|
| 159 |
db_set $langname $(locale2langname "$RET")
|
| 160 |
db_set $shortlist $(code2country "$(locale2countrycode "$RET")")
|
| 161 |
db_set $fulllist $(code2country "$(locale2countrycode "$RET")")
|
| 162 |
fi
|
| 163 |
|
| 164 |
db_input high $langname || [ $? -eq 30 ]
|
| 165 |
if db_go; then
|
| 166 |
db_get $langname
|
| 167 |
if test "$RET" ; then
|
| 168 |
LANGNAME="$RET"
|
| 169 |
. languagemap
|
| 170 |
db_set "$languagecode" "$LANGUAGELIST"
|
| 171 |
db_set "$localecode" "$LOCALE"
|
| 172 |
db_set "$fallbacklocalecode" "$FALLBACKLOCALE"
|
| 173 |
# For "remembering" which locale is set by languagechooser
|
| 174 |
db_set "$languagechooserlocalecode" "$LOCALE"
|
| 175 |
db_set "$countrycode" "$COUNTRY"
|
| 176 |
db_set "$consoledisplay" "$CONSOLE"
|
| 177 |
else
|
| 178 |
# Error, not sure how to handle it
|
| 179 |
:
|
| 180 |
fi
|
| 181 |
else
|
| 182 |
# Error, not sure how to handle it
|
| 183 |
:
|
| 184 |
fi
|
| 185 |
|
| 186 |
db_get "$languagecode"
|
| 187 |
db_set "debconf/language" "$LANGUAGELIST"
|
| 188 |
|
| 189 |
log "Asking for language specific packages to be Installed."
|
| 190 |
|
| 191 |
case "$LANGUAGE" in
|
| 192 |
ar|el|he|ja|ko|tr|zh)
|
| 193 |
anna-install bterm-unifont
|
| 194 |
;;
|
| 195 |
esac
|
| 196 |
|
| 197 |
# Enable translations (if this is present, base-config generated the
|
| 198 |
# required locale on boot)
|
| 199 |
apt-install locales || true
|
| 200 |
|
| 201 |
if [ "$LANGUAGE" != "en" ]; then
|
| 202 |
# Package iso-codes is missing in Woody. Do not fail if it is
|
| 203 |
# missing to make d-i capable of installing Woody and Skolelinux.
|
| 204 |
apt-install iso-codes || true
|
| 205 |
apt-install localization-config || true
|
| 206 |
fi
|
| 207 |
|
| 208 |
case "$LANGUAGE" in
|
| 209 |
ja|ko|ko_KR|el|zh|zh_CN|zh_TW|bg)
|
| 210 |
# Japanese, Korean, Greek, Chinese, Bulgarian
|
| 211 |
apt-install jfbterm || true
|
| 212 |
apt-install unifont || true
|
| 213 |
;;
|
| 214 |
# ru)
|
| 215 |
# Russian
|
| 216 |
# apt-install console-cyrillic || true
|
| 217 |
# apt-install console-terminus || true
|
| 218 |
# ;;
|
| 219 |
tr)
|
| 220 |
# Turkish
|
| 221 |
apt-install console-terminus || true
|
| 222 |
;;
|
| 223 |
ar|he|fa)
|
| 224 |
# RTL languages (Arabic, Hebrew, Farsi)
|
| 225 |
apt-install jfbterm || true
|
| 226 |
apt-install unifont || true
|
| 227 |
apt-install libfribidi0 || true
|
| 228 |
;;
|
| 229 |
*)
|
| 230 |
;;
|
| 231 |
esac
|
| 232 |
|
| 233 |
log "$localecode = '$LOCALE'"
|
| 234 |
log "$fallbacklocalecode = '$FALLBACKLOCALE'"
|
| 235 |
log "$languagechooserlocalecode = '$LOCALE'"
|
| 236 |
log "$languagecode = '$LANGUAGELIST'"
|
| 237 |
log "$countrycode = '$COUNTRY'"
|
| 238 |
log "$consoledisplay = '$CONSOLE'"
|
| 239 |
|
| 240 |
db_get $fulllist
|
| 241 |
# if no preseeding was done
|
| 242 |
if [ -z "$RET" ] ; then
|
| 243 |
# Grab back the country we got previously
|
| 244 |
db_get "$countrycode"
|
| 245 |
if [ -n "$RET" ]; then
|
| 246 |
# Remember which code was first used
|
| 247 |
# This is needed at the end of the script
|
| 248 |
COUNTRYCODE_LANGUAGECHOOSER="$RET"
|
| 249 |
COUNTRY_LANGUAGECHOOSER="$(code2country "$RET")"
|
| 250 |
db_set "$fulllist" "${COUNTRY_LANGUAGECHOOSER}"
|
| 251 |
db_set "$shortlist" "${COUNTRY_LANGUAGECHOOSER}"
|
| 252 |
fi
|
| 253 |
fi
|
| 254 |
|
| 255 |
|
| 256 |
# Keep track of values we have after language choice step
|
| 257 |
LOCALE_LANGUAGECHOOSER=$LOCALE
|
| 258 |
LANGUAGECODE_LANGUAGECHOOSER=$LANGUAGE
|
| 259 |
|
| 260 |
# If present, keep track of charset or modifier we got previously
|
| 261 |
EXTRA_LANGUAGECHOOSER=`echo $FALLBACKLOCALE | sed -e 's/^[^.@]*//'`
|
| 262 |
|
| 263 |
|
| 264 |
FIRST_LANG=$(echo $LANGUAGELIST | sed -e 's/:.*$//')
|
| 265 |
|
| 266 |
if grep -q "^$FIRST_LANG" $SHORTLISTS; then
|
| 267 |
use_lang=$FIRST_LANG
|
| 268 |
elif grep -q "^$LANGUAGE" $SHORTLISTS; then
|
| 269 |
use_lang=$LANGUAGE
|
| 270 |
else
|
| 271 |
use_lang=""
|
| 272 |
fi
|
| 273 |
|
| 274 |
# At this step we should have either xx, or xx_YY in LANGNAME
|
| 275 |
if [ "$LANGUAGE" != "C" ]; then
|
| 276 |
STATE=1
|
| 277 |
LASTSTATE=3
|
| 278 |
fullprio=high
|
| 279 |
shortprio=high
|
| 280 |
while [ "$STATE" != 0 -a "$STATE" -le "$LASTSTATE" ]; do
|
| 281 |
case "$STATE" in
|
| 282 |
1)
|
| 283 |
# If the locale includes a country, then
|
| 284 |
# don't display the short list, and only show the
|
| 285 |
# full list at medium priority.
|
| 286 |
if (echo $LOCALE | grep "_" >/dev/null 2>&1) ; then
|
| 287 |
askedshort=0
|
| 288 |
fullprio=medium
|
| 289 |
else
|
| 290 |
if [ "$use_lang" ]; then
|
| 291 |
# Build a short list of supported locales for
|
| 292 |
# the language.
|
| 293 |
COUNTRY_SHORTLIST=$(grep "^$use_lang[[:space:]]" $SHORTLISTS | \
|
| 294 |
sed -e "s/^$use_lang[[:space:]]//")
|
| 295 |
SHORTLIST=$(get_shortlist shortlist $use_lang)
|
| 296 |
|
| 297 |
db_subst $shortlist SHORTLIST "$SHORTLIST"
|
| 298 |
db_subst $shortlist DEFAULTLOCALE "$LOCALE"
|
| 299 |
db_input $shortprio $shortlist || [ $? -eq 30 ]
|
| 300 |
askedshort=1
|
| 301 |
else
|
| 302 |
askedshort=0
|
| 303 |
fi
|
| 304 |
fi
|
| 305 |
;;
|
| 306 |
2)
|
| 307 |
db_get $shortlist
|
| 308 |
if [ "$askedshort" = 1 ] && [ "$RET" != "other" ]; then
|
| 309 |
COUNTRYCODE="$(loccountry2code "$RET" $use_lang )" || true
|
| 310 |
if [ -n "$COUNTRYCODE" ]; then
|
| 311 |
break
|
| 312 |
fi
|
| 313 |
fi
|
| 314 |
|
| 315 |
db_subst $fulllist DEFAULTLOCALE "$LOCALE"
|
| 316 |
db_input $fullprio $fulllist || [ $? -eq 30 ]
|
| 317 |
;;
|
| 318 |
3)
|
| 319 |
db_get $fulllist
|
| 320 |
COUNTRYCODE="$(country2code "$RET")" || true
|
| 321 |
if [ -n "$COUNTRYCODE" ]; then
|
| 322 |
break
|
| 323 |
else
|
| 324 |
# User probably selected a region.
|
| 325 |
STATE=2
|
| 326 |
continue
|
| 327 |
fi
|
| 328 |
;;
|
| 329 |
esac
|
| 330 |
|
| 331 |
if db_go; then
|
| 332 |
STATE=$(($STATE + 1))
|
| 333 |
else
|
| 334 |
STATE=$(($STATE - 1))
|
| 335 |
fi
|
| 336 |
done
|
| 337 |
|
| 338 |
if [ "$STATE" = 0 ]; then
|
| 339 |
exit 10 # back out to main menu
|
| 340 |
fi
|
| 341 |
fi
|
| 342 |
|
| 343 |
db_set "$countrycode" "$COUNTRYCODE"
|
| 344 |
log "$countrycode = '$COUNTRYCODE'"
|
| 345 |
|
| 346 |
# Search for a supported locale which most closely resembles.
|
| 347 |
OLDLOCALE=$LOCALE
|
| 348 |
LOCALE=""
|
| 349 |
|
| 350 |
for entry in ${LANGUAGE}_${COUNTRYCODE}${EXTRA_LANGUAGECHOOSER} \
|
| 351 |
${LANGUAGE}_${COUNTRYCODE}; do
|
| 352 |
# Is the locale we inherited
|
| 353 |
# really a complete locale?
|
| 354 |
LOCALE_LANGUAGECHOOSER_COMPLETE=$(echo $OLDLOCALE | grep "_" || true)
|
| 355 |
if grep -q "^${entry}$" $SUPPORTEDLOCALES; then
|
| 356 |
# Special handling of cases where the locale
|
| 357 |
# in languagechooser is NOT the combination of
|
| 358 |
# language_COUNTRY. Used for Norwegian Bokmal transition
|
| 359 |
# in order to keep no_NO as locale. May be used in the
|
| 360 |
# future for other special cases, so we'd better keep this
|
| 361 |
if \
|
| 362 |
[ "$LANGUAGE" = "${LANGUAGECODE_LANGUAGECHOOSER}" \
|
| 363 |
-a \
|
| 364 |
"$COUNTRYCODE" = "${COUNTRYCODE_LANGUAGECHOOSER}" \
|
| 365 |
-a \
|
| 366 |
"${LANGUAGE}_${COUNTRYCODE}" != "$OLDLOCALE" \
|
| 367 |
-a \
|
| 368 |
-n "${LOCALE_LANGUAGECHOOSER_COMPLETE}" \
|
| 369 |
] ; then
|
| 370 |
# In details : we revert back to the locale
|
| 371 |
# inherited from the language step if the country step
|
| 372 |
# did NOT induce change in language and country
|
| 373 |
# but the resulting locale is different from the
|
| 374 |
# one we had in first step
|
| 375 |
LOCALE=$OLDLOCALE
|
| 376 |
else
|
| 377 |
LOCALE="${entry}"
|
| 378 |
fi
|
| 379 |
break
|
| 380 |
fi
|
| 381 |
done
|
| 382 |
|
| 383 |
# Fall back to a supported locale.
|
| 384 |
if [ -z "${LOCALE}" ]; then
|
| 385 |
if grep -q "^${FALLBACKLOCALE}$" $SUPPORTEDLOCALES; then
|
| 386 |
LOCALE="$FALLBACKLOCALE"
|
| 387 |
else
|
| 388 |
LOCALE=`echo $FALLBACKLOCALE | sed -e 's/[.@].*$//'`
|
| 389 |
fi
|
| 390 |
log "falling back to locale '$LOCALE'"
|
| 391 |
fi
|
| 392 |
|
| 393 |
# Set the locale.
|
| 394 |
db_set "$localecode" "$LOCALE"
|
| 395 |
log "$localecode = '$LOCALE'"
|
| 396 |
|
| 397 |
# The code below adds lang_COUNTRY at the beginning of the language
|
| 398 |
# list we got from languagechooser
|
| 399 |
# We shouldn't just add this before the former list in case the country
|
| 400 |
# is changed several times.
|
| 401 |
if [ "$COUNTRYCODE" != "$COUNTRYCODE_LANGUAGECHOOSER" -a -n "$COUNTRYCODE" -a -n "$LANGUAGE" ]; then
|
| 402 |
LANGUAGELIST=${LANGUAGE}_${COUNTRYCODE}:${LANGUAGELIST}
|
| 403 |
# Languagelist setting
|
| 404 |
db_set "$languagecode" "$LANGUAGELIST"
|
| 405 |
log "$languagecode = '$LANGUAGELIST'"
|
| 406 |
fi
|
| 407 |
|
| 408 |
|
| 409 |
# Third step : ask for a locale at medium priority
|
| 410 |
# We will choose it among
|
| 411 |
POSSIBLELOCALES=$(grep -e "^${LANGUAGE}_${COUNTRYCODE}" $SUPPORTEDLOCALES)
|
| 412 |
if [ $(echo $POSSIBLELOCALES | wc -w) -gt 1 ] ; then
|
| 413 |
CHOICES=""
|
| 414 |
for i in $POSSIBLELOCALES ; do
|
| 415 |
if [ -z $CHOICES ] ; then
|
| 416 |
CHOICES=$i
|
| 417 |
else
|
| 418 |
CHOICES="$CHOICES,$i"
|
| 419 |
fi
|
| 420 |
done
|
| 421 |
db_subst $localecode LOCALELIST "$CHOICES"
|
| 422 |
db_input medium $localecode || [ $? -eq 30 ]
|
| 423 |
if db_go ; then
|
| 424 |
log "$localecode = '$RET'"
|
| 425 |
else
|
| 426 |
exit 10
|
| 427 |
fi
|
| 428 |
fi
|
| 429 |
|
| 430 |
|
| 431 |
exit 0
|