This repository has been archived by the owner on Sep 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubiquity-fix
147 lines (126 loc) · 4.34 KB
/
ubiquity-fix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#! /bin/sh
set -e
. /usr/share/debconf/confmodule
# Avoid locale errors when using apt-install (logical consequence
# of the fact that locales is not yet installed).
export IT_LANG_OVERRIDE=C
db_get debian-installer/locale
LOCALE="$RET"
# Set locale to C if it has not yet been set
# This can happen during e.g. s390 installs where localechooser is not run
[ "$LOCALE" ] || LOCALE="C"
if [ "$LOCALE" != "C" ]; then
db_get debian-installer/language
LANGLIST="$RET"
fi
EXTRAS=""
if db_get localechooser/supported-locales; then
EXTRAS="$(echo "$RET" | sed 's/,//g')"
fi
LANGUAGE="${LOCALE%%_*}"
LOCALE_TRANSLATIONS="$LOCALE"
case ${LOCALE%%_*} in
pt|zh)
# In the special cases of Portuguese and Chinese, selecting a
# different location may imply a different dialect of the language.
# In such cases, make LANG reflect the selected language (for
# messages, character types, and collation) and make the other
# locale categories reflect the selected language.
db_get localechooser/languagelist
ORIG_LANGUAGE="$RET"
db_get debian-installer/country
COUNTRY="$RET"
if grep -q "^$ORIG_LANGUAGE;" /usr/share/localechooser/languagelist; then
SUPPORTEDLOCALES=/usr/share/localechooser/SUPPORTED
if [ ! -f "$SUPPORTEDLOCALES" ]; then
SUPPORTEDLOCALES=/usr/share/i18n/SUPPORTED
fi
LOCALE_TRANSLATIONS="$(grep "^$ORIG_LANGUAGE;" /usr/share/localechooser/languagelist | cut -d';' -f5)"
newlocale="$(echo "$LOCALE" | sed "s/_[A-Z][A-Z]*/_$COUNTRY/")"
if grep -q "^${newlocale%%[.@]*}[.@ ]" $SUPPORTEDLOCALES && \
[ "$newlocale" != "$LOCALE_TRANSLATIONS" ]; then
LOCALE="$newlocale"
LANGLIST="$(grep "^$ORIG_LANGUAGE;" /usr/share/localechooser/languagelist | cut -d';' -f6)"
fi
fi
;;
esac
# Enable translations
if [ "$LOCALE" != "C" ] || [ "$EXTRAS" ]; then
apt-install locales || true
fi
set_field () {
local file category value
file="$1"
category="$2"
value="$3"
if grep -qs "^#* *$category=" "$file"; then
sed -i "s,^#* *$category=.*,$category=\"$value\"," "$file"
else
echo "$category=\"$value\"" >> "$file"
fi
}
# Set global locale and language, and make sure the glibc locale is
# generated.
DESTFILE="/target/etc/default/locale"
if [ -e $DESTFILE ]; then
sed -i 's/^# LANG=$/LANG=\"'"$LOCALE_TRANSLATIONS"'\"/' $DESTFILE
# We set LANGUAGE only if the languagelist is a list of
# languages with alternatives. Otherwise, setting it is useless
if echo "$LANGLIST" | grep -q ":"; then
sed -i 's/^# LANGUAGE=$/LANGUAGE=\"'"$LANGLIST"'\"/' $DESTFILE
fi
fi
# Fallback in case the file wasn't provided by locales, or the format
# changed.
if [ ! -e "$DESTFILE" ] || ! grep -q '^LANG=' $DESTFILE; then
mkdir -p "${DESTFILE%/*}"
echo "LANG=\"$LOCALE_TRANSLATIONS\"" >> $DESTFILE
if echo "$LANGLIST" | grep -q ":"; then
echo "LANGUAGE=\"$LANGLIST\"" >> $DESTFILE
fi
fi
if [ "$LOCALE_TRANSLATIONS" != "$LOCALE" ]; then
for category in \
LC_NUMERIC LC_TIME LC_MONETARY LC_PAPER LC_NAME LC_ADDRESS \
LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION; do
set_field /target/etc/default/locale "$category" "$LOCALE"
done
fi
# For languages that have no chance to be displayed at the Linux console
# let's set root's environment with a non localized environment
ROOTPROFILE="/target/root/.profile"
# We must map the language to its "level" from languagelist
LANGUAGECODE=`echo $LOCALE|cut -f1 -d_`
# For language with multiple entries such as pt/pt_BR or zh_CN/zh_TW
# we don't really care about the entry we will match as the level will always
# be the same
LEVEL=`cat /usr/share/localechooser/languagelist |\
cut -f 2-3 -d\; | \
grep "$LANGUAGECODE" | \
head -n 1 | \
cut -f1 -d\;`
if [ "$LEVEL" = "3" ] || [ "$LEVEL" = "4" ]; then
echo "# Installed by Debian Installer:" >>$ROOTPROFILE
echo "# no localization for root because $LOCALE" >>$ROOTPROFILE
echo "# cannot be properly displayed at the Linux console" >>$ROOTPROFILE
echo "LANG=C" >>$ROOTPROFILE
echo "LANGUAGE=C" >>$ROOTPROFILE
fi
locale_gen () {
local loc
for loc; do
# Create a skeleton locale-langpack subdirectory so that
# /usr/share/language-tools/language-options knows that this
# locale is supposed to have a meaningful existence.
mkdir -p "/target/usr/share/locale-langpack/${loc%_*}"
done
log-output -t localechooser chroot /target /usr/sbin/locale-gen "$@"
}
if [ "$LOCALE" != C ]; then
locale_gen "$LOCALE" || true
fi
if [ "$EXTRAS" ]; then
locale_gen $EXTRAS || true
fi
exit 0