network: don't use "ifup -m"
[dracut.git] / modules.d / 10i18n / module-setup.sh
blob943987595752413220717973f3655dfa5ea18d21
1 #!/bin/bash
3 # called by dracut
4 check() {
5 [[ "$mount_needs" ]] && return 1
7 require_binaries setfont loadkeys kbd_mode || return 1
9 return 0
12 # called by dracut
13 depends() {
14 return 0
17 # called by dracut
18 install() {
19 if dracut_module_included "systemd"; then
20 unset FONT
21 unset KEYMAP
22 [[ -f /etc/vconsole.conf ]] && . /etc/vconsole.conf
25 KBDSUBDIRS=consolefonts,consoletrans,keymaps,unimaps
26 DEFAULT_FONT="${i18n_default_font:-LatArCyrHeb-16}"
27 I18N_CONF="/etc/locale.conf"
28 VCONFIG_CONF="/etc/vconsole.conf"
30 # This is from 10redhat-i18n.
31 findkeymap () {
32 local MAP=$1
33 [[ ! -f $MAP ]] && \
34 MAP=$(find ${kbddir}/keymaps -type f -name $MAP -o -name $MAP.\* | head -n1)
35 [[ " $KEYMAPS " = *" $MAP "* ]] && return
36 KEYMAPS="$KEYMAPS $MAP"
37 case $MAP in
38 *.gz) cmd=zgrep;;
39 *.bz2) cmd=bzgrep;;
40 *) cmd=grep ;;
41 esac
43 for INCL in $($cmd "^include " $MAP | while read a a b || [ -n "$a" ]; do echo ${a//\"/}; done); do
44 for FN in $(find ${kbddir}/keymaps -type f -name $INCL\*); do
45 findkeymap $FN
46 done
47 done
50 # Function gathers variables from distributed files among the tree, maps to
51 # specified names and prints the result in format "new-name=value".
53 # $@ = list in format specified below (BNF notation)
55 # <list> ::= <element> | <element> " " <list>
56 # <element> ::= <conf-file-name> ":" <map-list>
57 # <map-list> ::= <mapping> | <mapping> "," <map-list>
58 # <mapping> ::= <src-var> "-" <dst-var> | <src-var>
60 # We assume no whitespace are allowed between symbols.
61 # <conf-file-name> is a file holding <src-var> in your system.
62 # <src-var> is a variable holding value of meaning the same as <dst-var>.
63 # <dst-var> is a variable which will be set up inside initramfs.
64 # If <dst-var> has the same name as <src-var> we can omit <dst-var>.
66 # Example:
67 # /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS
68 # <list> = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS
69 # <element> = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS
70 # <conf-file-name> = /etc/conf.d/keymaps
71 # <map-list> = KEYMAP,extended_keymaps-EXT_KEYMAPS
72 # <mapping> = KEYMAP
73 # <src-var> = KEYMAP
74 # <mapping> = extended_keymaps-EXT_KEYMAPS
75 # <src-var> = extended_keymaps
76 # <dst-var> = EXT_KEYMAPS
77 gather_vars() {
78 local item map value
80 for item in $@
82 item=(${item/:/ })
83 for map in ${item[1]//,/ }
85 map=(${map//-/ })
86 if [[ -f "${item[0]}" ]]; then
87 value=$(grep "^${map[0]}=" "${item[0]}")
88 value=${value#*=}
89 echo "${map[1]:-${map[0]}}=${value}"
91 done
92 done
95 install_base() {
96 inst_multiple setfont loadkeys kbd_mode stty
98 if ! dracut_module_included "systemd"; then
99 inst ${moddir}/console_init.sh /lib/udev/console_init
100 inst_rules ${moddir}/10-console.rules
101 inst_hook cmdline 20 "${moddir}/parse-i18n.sh"
105 install_all_kbd() {
106 local rel f
108 for _src in $(eval echo ${kbddir}/{${KBDSUBDIRS}}); do
109 inst_dir "$_src"
110 cp --reflink=auto --sparse=auto -prfL -t "${initdir}/${_src}" "$_src"/*
111 done
113 # remove unnecessary files
114 rm -f -- "${initdir}${kbddir}/consoletrans/utflist"
115 find "${initdir}${kbddir}/" -name README\* -delete
116 find "${initdir}${kbddir}/" -name '*.gz' -print -quit \
117 | while read line || [ -n "$line" ]; do
118 inst_multiple gzip
119 done
121 find "${initdir}${kbddir}/" -name '*.bz2' -print -quit \
122 | while read line || [ -n "$line" ]; do
123 inst_multiple bzip2
124 done
127 install_local_i18n() {
128 local map
130 eval $(gather_vars ${i18n_vars})
131 [ -f $I18N_CONF ] && . $I18N_CONF
132 [ -f $VCONFIG_CONF ] && . $VCONFIG_CONF
134 shopt -q -s nocasematch
135 if [[ ${UNICODE} ]]
136 then
137 if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]
138 then
139 UNICODE=1
140 elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]]
141 then
142 UNICODE=0
143 else
144 UNICODE=''
147 if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]
148 then
149 UNICODE=1
151 shopt -q -u nocasematch
153 # Gentoo user may have KEYMAP set to something like "-u pl2",
154 KEYMAP=${KEYMAP#-* }
156 # openSUSE user may have KEYMAP set to something like ".gz"
157 KEYMAP=${KEYMAP/.gz/}
159 # KEYTABLE is a bit special - it defines base keymap name and UNICODE
160 # determines whether non-UNICODE or UNICODE version is used
162 if [[ ${KEYTABLE} ]]; then
163 if [[ ${UNICODE} == 1 ]]; then
164 [[ ${KEYTABLE} =~ .*\.uni.* ]] || KEYTABLE=${KEYTABLE%.map*}.uni
166 KEYMAP=${KEYTABLE}
169 # I'm not sure of the purpose of UNIKEYMAP and GRP_TOGGLE. They were in
170 # original redhat-i18n module. Anyway it won't hurt.
171 EXT_KEYMAPS+=\ ${UNIKEYMAP}\ ${GRP_TOGGLE}
173 [[ ${KEYMAP} ]] || {
174 dinfo 'No KEYMAP configured.'
175 return 1
178 findkeymap ${KEYMAP}
180 for map in ${EXT_KEYMAPS}
182 ddebug "Adding extra map: ${map}"
183 findkeymap ${map}
184 done
186 inst_opt_decompress ${KEYMAPS}
188 inst_opt_decompress ${kbddir}/consolefonts/${DEFAULT_FONT}.*
190 if [[ ${FONT} ]] && [[ ${FONT} != ${DEFAULT_FONT} ]]
191 then
192 FONT=${FONT%.psf*}
193 inst_opt_decompress ${kbddir}/consolefonts/${FONT}.*
196 if [[ ${FONT_MAP} ]]
197 then
198 FONT_MAP=${FONT_MAP%.trans}
199 inst_simple ${kbddir}/consoletrans/${FONT_MAP}.trans
202 if [[ ${FONT_UNIMAP} ]]
203 then
204 FONT_UNIMAP=${FONT_UNIMAP%.uni}
205 inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
208 if dracut_module_included "systemd" && [[ -f ${I18N_CONF} ]]; then
209 inst_simple ${I18N_CONF}
210 else
211 mksubdirs ${initdir}${I18N_CONF}
212 print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
215 if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
216 inst_simple ${VCONFIG_CONF}
217 else
218 mksubdirs ${initdir}${VCONFIG_CONF}
219 print_vars KEYMAP EXT_KEYMAPS UNICODE FONT FONT_MAP FONT_UNIMAP >> ${initdir}${VCONFIG_CONF}
222 return 0
225 checks() {
226 for kbddir in ${kbddir} /usr/lib/kbd /lib/kbd /usr/share /usr/share/kbd
228 [[ -d "${kbddir}" ]] && \
229 for dir in ${KBDSUBDIRS//,/ }
231 [[ -d "${kbddir}/${dir}" ]] && continue
232 false
233 done && break
234 kbddir=''
235 done
237 [[ -f $I18N_CONF && -f $VCONFIG_CONF ]] || \
238 [[ ! ${hostonly} || ${i18n_vars} ]] || {
239 derror 'i18n_vars not set! Please set up i18n_vars in ' \
240 'configuration file.'
242 return 0
245 if checks; then
246 install_base
248 if [[ ${hostonly} ]] && ! [[ ${i18n_install_all} == "yes" ]]; then
249 install_local_i18n || install_all_kbd
250 else
251 install_all_kbd