|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# called by dracut
|
|
|
|
check() {
|
|
|
|
[[ "$mount_needs" ]] && return 1
|
|
|
|
|
|
|
|
require_binaries setfont loadkeys kbd_mode || return 1
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# called by dracut
|
|
|
|
depends() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# called by dracut
|
|
|
|
install() {
|
|
|
|
declare -A KEYMAPS
|
|
|
|
|
|
|
|
if dracut_module_included "systemd"; then
|
|
|
|
unset FONT
|
|
|
|
unset KEYMAP
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
[[ -f "$dracutsysrootdir"/etc/vconsole.conf ]] && . "$dracutsysrootdir"/etc/vconsole.conf
|
|
|
|
fi
|
|
|
|
|
|
|
|
KBDSUBDIRS=(consolefonts consoletrans keymaps unimaps)
|
|
|
|
DEFAULT_FONT="${i18n_default_font:-eurlatgr}"
|
|
|
|
I18N_CONF="/etc/locale.conf"
|
|
|
|
VCONFIG_CONF="/etc/vconsole.conf"
|
|
|
|
|
|
|
|
findkeymap() {
|
|
|
|
# shellcheck disable=SC2064
|
|
|
|
trap "$(shopt -p nullglob globstar)" RETURN
|
|
|
|
shopt -q -s nullglob globstar
|
|
|
|
|
|
|
|
local -a MAPS
|
|
|
|
local MAPNAME
|
|
|
|
local INCLUDES
|
|
|
|
local MAP
|
|
|
|
local CMD
|
|
|
|
local FN
|
|
|
|
|
|
|
|
if [[ -f $dracutsysrootdir$1 ]]; then
|
|
|
|
MAPS=("$1")
|
|
|
|
else
|
|
|
|
MAPNAME=${1%.map*}
|
|
|
|
MAPS=("$dracutsysrootdir""${kbddir}"/keymaps/**/"${MAPNAME}"{,.map{,.*}})
|
|
|
|
fi
|
|
|
|
|
|
|
|
for MAP in "${MAPS[@]}"; do
|
|
|
|
[[ -f $MAP ]] || continue
|
|
|
|
[[ -v KEYMAPS["$MAP"] ]] && continue
|
|
|
|
|
|
|
|
KEYMAPS["$MAP"]=1
|
|
|
|
|
|
|
|
case "$MAP" in
|
|
|
|
*.gz) CMD="zgrep" ;;
|
|
|
|
*.bz2) CMD="bzgrep" ;;
|
|
|
|
*) CMD="grep" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
readarray -t INCLUDES < <("$CMD" '^include ' "$MAP" | while read -r _ a _ || [ -n "$a" ]; do echo "${a//\"/}"; done)
|
|
|
|
|
|
|
|
for INCL in "${INCLUDES[@]}"; do
|
|
|
|
for FN in "$dracutsysrootdir""${kbddir}"/keymaps/**/"$INCL"*; do
|
|
|
|
[[ -f $FN ]] || continue
|
|
|
|
[[ -v KEYMAPS["$FN"] ]] || findkeymap "$FN"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function gathers variables from distributed files among the tree, maps to
|
|
|
|
# specified names and prints the result in format "new-name=value".
|
|
|
|
#
|
|
|
|
# $@ = list in format specified below (BNF notation)
|
|
|
|
#
|
|
|
|
# <list> ::= <element> | <element> " " <list>
|
|
|
|
# <element> ::= <conf-file-name> ":" <map-list>
|
|
|
|
# <map-list> ::= <mapping> | <mapping> "," <map-list>
|
|
|
|
# <mapping> ::= <src-var> "-" <dst-var> | <src-var>
|
|
|
|
#
|
|
|
|
# We assume no whitespace are allowed between symbols.
|
|
|
|
# <conf-file-name> is a file holding <src-var> in your system.
|
|
|
|
# <src-var> is a variable holding value of meaning the same as <dst-var>.
|
|
|
|
# <dst-var> is a variable which will be set up inside initramfs.
|
|
|
|
# If <dst-var> has the same name as <src-var> we can omit <dst-var>.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
# /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS
|
|
|
|
# <list> = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS
|
|
|
|
# <element> = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS
|
|
|
|
# <conf-file-name> = /etc/conf.d/keymaps
|
|
|
|
# <map-list> = KEYMAP,extended_keymaps-EXT_KEYMAPS
|
|
|
|
# <mapping> = KEYMAP
|
|
|
|
# <src-var> = KEYMAP
|
|
|
|
# <mapping> = extended_keymaps-EXT_KEYMAPS
|
|
|
|
# <src-var> = extended_keymaps
|
|
|
|
# <dst-var> = EXT_KEYMAPS
|
|
|
|
gather_vars() {
|
|
|
|
local item map value
|
|
|
|
|
|
|
|
# FIXME: double check
|
|
|
|
# shellcheck disable=SC2068
|
|
|
|
for item in "$@"; do
|
|
|
|
read -r -a item <<< "${item/:/ }"
|
|
|
|
for map in ${item[1]//,/ }; do
|
|
|
|
read -r -a map <<< "${map//-/ }"
|
Allow running on a cross-compiled rootfs
For the shell scripts, new environment variables were introduced.
dracutsysrootdir is the root directory, file existence checks use it.
DRACUT_LDCONFIG can override ldconfig with a different one that works
on the sysroot with foreign binaries.
DRACUT_LDD can override ldd with a different one that works
with foreign binaries.
DRACUT_TESTBIN can override /bin/sh. A cross-compiled sysroot
may use symlinks that are valid only when running on the target
so a real file must be provided that exist in the sysroot.
DRACUT_INSTALL now supports debugging dracut-install in itself
when run by dracut but without debugging the dracut scripts.
E.g. DRACUT_INSTALL="valgrind dracut-install or
DRACUT_INSTALL="dracut-install --debug".
DRACUT_COMPRESS_BZIP2, DRACUT_COMPRESS_LBZIP2, DRACUT_COMPRESS_LZMA,
DRACUT_COMPRESS_XZ, DRACUT_COMPRESS_GZIP, DRACUT_COMPRESS_PIGZ,
DRACUT_COMPRESS_LZOP, DRACUT_COMPRESS_ZSTD, DRACUT_COMPRESS_LZ4,
DRACUT_COMPRESS_CAT: All of the compression utilities may be
overridden, to support the native binaries in non-standard places.
DRACUT_ARCH overrides "uname -m".
SYSTEMD_VERSION overrides "systemd --version".
The dracut-install utility was overhauled to support sysroot via
a new option -r and fixes for clang-analyze. It supports
cross-compiler-ldd from
https://gist.github.com/jerome-pouiller/c403786c1394f53f44a3b61214489e6f
DRACUT_INSTALL_PATH was introduced so dracut-install can work with
a different PATH. In a cross-compiled environment (e.g. Yocto), PATH
points to natively built binaries that are not in the host's /bin,
/usr/bin, etc. dracut-install still needs plain /bin and /usr/bin
that are relative to the cross-compiled sysroot.
The hashmap pool allocate_tile/deallocate_tile code was removed
because clang-analyze showed errors in it. hashmap_copy was removed
because it wasn't used and clang-analyze showed errors in it.
DRACUT_INSTALL_LOG_TARGET and DRACUT_INSTALL_LOG_LEVEL were
introduced so dracut-install can use different settings from
DRACUT_LOG_TARGET and DRACUT_LOG_LEVEL.
Signed-off-by: Böszörményi Zoltán <zboszor@pr.hu>
5 years ago
|
|
|
if [[ -f "$dracutsysrootdir${item[0]}" ]]; then
|
|
|
|
value=$(grep "^${map[0]}=" "$dracutsysrootdir${item[0]}")
|
|
|
|
value=${value#*=}
|
|
|
|
echo "${map[1]:-${map[0]}}=${value}"
|
|
|
|
fi
|
|
|
|
unset map
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
install_base() {
|
|
|
|
inst_multiple setfont loadkeys kbd_mode stty
|
|
|
|
|
|
|
|
if ! dracut_module_included "systemd"; then
|
|
|
|
inst "${moddir}"/console_init.sh /lib/udev/console_init
|
|
|
|
inst_rules "${moddir}"/10-console.rules
|
|
|
|
inst_hook cmdline 20 "${moddir}/parse-i18n.sh"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ${kbddir} != "/usr/share" ]]; then
|
|
|
|
inst_dir /usr/share
|
|
|
|
for _src in "${KBDSUBDIRS[@]}"; do
|
|
|
|
[ ! -e "${initdir}/usr/share/${_src}" ] && ln -s "${kbddir}/${_src}" "${initdir}/usr/share/${_src}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install_all_kbd() {
|
|
|
|
local _src _line
|
|
|
|
|
|
|
|
for _src in "${KBDSUBDIRS[@]}"; do
|
|
|
|
inst_dir "${kbddir}/$_src"
|
|
|
|
$DRACUT_CP -L -t "${initdir}/${kbddir}/$_src" "${dracutsysrootdir}${kbddir}/$_src"/*
|
|
|
|
done
|
|
|
|
|
|
|
|
# remove unnecessary files
|
|
|
|
rm -f -- "${initdir}${kbddir}/consoletrans/utflist"
|
|
|
|
find "${initdir}${kbddir}/" -name README\* -delete
|
|
|
|
find "${initdir}${kbddir}/" -name '*.gz' -print -quit \
|
|
|
|
| while read -r _line || [ -n "$_line" ]; do
|
|
|
|
inst_multiple gzip
|
|
|
|
done
|
|
|
|
|
|
|
|
find "${initdir}${kbddir}/" -name '*.bz2' -print -quit \
|
|
|
|
| while read -r _line || [ -n "$_line" ]; do
|
|
|
|
inst_multiple bzip2
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
install_local_i18n() {
|
|
|
|
local map
|
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
eval "$(gather_vars ${i18n_vars})"
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
[ -f "$dracutsysrootdir"$I18N_CONF ] && . "$dracutsysrootdir"$I18N_CONF
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
[ -f "$dracutsysrootdir"$VCONFIG_CONF ] && . "$dracutsysrootdir"$VCONFIG_CONF
|
|
|
|
|
|
|
|
shopt -q -s nocasematch
|
|
|
|
if [[ ${UNICODE} ]]; then
|
|
|
|
if [[ ${UNICODE} == YES || ${UNICODE} == 1 ]]; then
|
|
|
|
UNICODE=1
|
|
|
|
elif [[ ${UNICODE} == NO || ${UNICODE} == 0 ]]; then
|
|
|
|
UNICODE=0
|
|
|
|
else
|
|
|
|
UNICODE=''
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]; then
|
|
|
|
UNICODE=1
|
|
|
|
fi
|
|
|
|
shopt -q -u nocasematch
|
|
|
|
|
|
|
|
# Gentoo user may have KEYMAP set to something like "-u pl2",
|
|
|
|
KEYMAP=${KEYMAP#-* }
|
|
|
|
|
|
|
|
# openSUSE user may have KEYMAP set to something like ".gz"
|
|
|
|
KEYMAP=${KEYMAP/.gz/}
|
|
|
|
|
|
|
|
# KEYTABLE is a bit special - it defines base keymap name and UNICODE
|
|
|
|
# determines whether non-UNICODE or UNICODE version is used
|
|
|
|
|
|
|
|
if [[ ${KEYTABLE} ]]; then
|
|
|
|
if [[ ${UNICODE} == 1 ]]; then
|
|
|
|
[[ ${KEYTABLE} =~ .*\.uni.* ]] || KEYTABLE=${KEYTABLE%.map*}.uni
|
|
|
|
fi
|
|
|
|
KEYMAP=${KEYTABLE}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# I'm not sure of the purpose of UNIKEYMAP and GRP_TOGGLE. They were in
|
|
|
|
# original redhat-i18n module. Anyway it won't hurt.
|
|
|
|
EXT_KEYMAPS+=\ ${UNIKEYMAP}\ ${GRP_TOGGLE}
|
|
|
|
|
|
|
|
[[ ${KEYMAP} ]] || {
|
|
|
|
dinfo 'No KEYMAP configured.'
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
findkeymap "${KEYMAP}"
|
|
|
|
|
|
|
|
for map in ${EXT_KEYMAPS}; do
|
|
|
|
ddebug "Adding extra map: ${map}"
|
|
|
|
findkeymap "${map}"
|
|
|
|
done
|
|
|
|
|
|
|
|
for keymap in "${!KEYMAPS[@]}"; do
|
|
|
|
inst_opt_decompress "${keymap}"
|
|
|
|
done
|
|
|
|
|
|
|
|
inst_opt_decompress "${kbddir}"/consolefonts/"${DEFAULT_FONT}".*
|
|
|
|
|
|
|
|
if [[ ${FONT} ]] && [[ ${FONT} != "${DEFAULT_FONT}" ]]; then
|
|
|
|
FONT=${FONT%.psf*}
|
|
|
|
inst_opt_decompress "${kbddir}"/consolefonts/"${FONT}".*
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ${FONT_MAP} ]]; then
|
|
|
|
FONT_MAP=${FONT_MAP%.trans}
|
|
|
|
# There are three different formats that setfont supports
|
|
|
|
inst_simple "${kbddir}"/consoletrans/"${FONT_MAP}" \
|
|
|
|
|| inst_simple "${kbddir}"/consoletrans/"${FONT_MAP}".trans \
|
|
|
|
|| inst_simple "${kbddir}"/consoletrans/"${FONT_MAP}"_to_uni.trans \
|
|
|
|
|| dwarn "Could not find FONT_MAP ${FONT_MAP}!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ${FONT_UNIMAP} ]]; then
|
|
|
|
FONT_UNIMAP=${FONT_UNIMAP%.uni}
|
|
|
|
inst_simple "${kbddir}"/unimaps/"${FONT_UNIMAP}".uni
|
|
|
|
fi
|
|
|
|
|
Allow running on a cross-compiled rootfs
For the shell scripts, new environment variables were introduced.
dracutsysrootdir is the root directory, file existence checks use it.
DRACUT_LDCONFIG can override ldconfig with a different one that works
on the sysroot with foreign binaries.
DRACUT_LDD can override ldd with a different one that works
with foreign binaries.
DRACUT_TESTBIN can override /bin/sh. A cross-compiled sysroot
may use symlinks that are valid only when running on the target
so a real file must be provided that exist in the sysroot.
DRACUT_INSTALL now supports debugging dracut-install in itself
when run by dracut but without debugging the dracut scripts.
E.g. DRACUT_INSTALL="valgrind dracut-install or
DRACUT_INSTALL="dracut-install --debug".
DRACUT_COMPRESS_BZIP2, DRACUT_COMPRESS_LBZIP2, DRACUT_COMPRESS_LZMA,
DRACUT_COMPRESS_XZ, DRACUT_COMPRESS_GZIP, DRACUT_COMPRESS_PIGZ,
DRACUT_COMPRESS_LZOP, DRACUT_COMPRESS_ZSTD, DRACUT_COMPRESS_LZ4,
DRACUT_COMPRESS_CAT: All of the compression utilities may be
overridden, to support the native binaries in non-standard places.
DRACUT_ARCH overrides "uname -m".
SYSTEMD_VERSION overrides "systemd --version".
The dracut-install utility was overhauled to support sysroot via
a new option -r and fixes for clang-analyze. It supports
cross-compiler-ldd from
https://gist.github.com/jerome-pouiller/c403786c1394f53f44a3b61214489e6f
DRACUT_INSTALL_PATH was introduced so dracut-install can work with
a different PATH. In a cross-compiled environment (e.g. Yocto), PATH
points to natively built binaries that are not in the host's /bin,
/usr/bin, etc. dracut-install still needs plain /bin and /usr/bin
that are relative to the cross-compiled sysroot.
The hashmap pool allocate_tile/deallocate_tile code was removed
because clang-analyze showed errors in it. hashmap_copy was removed
because it wasn't used and clang-analyze showed errors in it.
DRACUT_INSTALL_LOG_TARGET and DRACUT_INSTALL_LOG_LEVEL were
introduced so dracut-install can use different settings from
DRACUT_LOG_TARGET and DRACUT_LOG_LEVEL.
Signed-off-by: Böszörményi Zoltán <zboszor@pr.hu>
5 years ago
|
|
|
if dracut_module_included "systemd" && [[ -f $dracutsysrootdir${I18N_CONF} ]]; then
|
|
|
|
inst_simple ${I18N_CONF}
|
|
|
|
else
|
|
|
|
mksubdirs "${initdir}"${I18N_CONF}
|
|
|
|
print_vars LC_ALL LANG >> "${initdir}"${I18N_CONF}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! dracut_module_included "systemd"; then
|
|
|
|
mksubdirs "${initdir}"${VCONFIG_CONF}
|
|
|
|
print_vars KEYMAP EXT_KEYMAPS UNICODE FONT FONT_MAP FONT_UNIMAP >> "${initdir}"${VCONFIG_CONF}
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
checks() {
|
|
|
|
for kbddir in ${kbddir} /usr/lib/kbd /lib/kbd /usr/share /usr/share/kbd; do
|
|
|
|
if [[ -d "$dracutsysrootdir${kbddir}" ]]; then
|
|
|
|
for dir in "${KBDSUBDIRS[@]}"; do
|
|
|
|
[[ -d "$dracutsysrootdir${kbddir}/${dir}" ]] && continue
|
|
|
|
false
|
|
|
|
done && break
|
|
|
|
fi
|
|
|
|
kbddir=''
|
|
|
|
done
|
|
|
|
|
|
|
|
[[ "$kbddir" ]] || return 1
|
|
|
|
|
|
|
|
[[ -f $dracutsysrootdir$I18N_CONF && -f $dracutsysrootdir$VCONFIG_CONF ]] \
|
|
|
|
|| [[ ! ${hostonly} || ${i18n_vars} ]] || {
|
|
|
|
derror 'i18n_vars not set! Please set up i18n_vars in ' \
|
|
|
|
'configuration file.'
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if checks; then
|
|
|
|
install_base
|
|
|
|
|
|
|
|
# https://github.com/dracutdevs/dracut/issues/796
|
|
|
|
if dracut_module_included "systemd" && [[ -f $dracutsysrootdir${VCONFIG_CONF} ]]; then
|
|
|
|
inst_simple ${VCONFIG_CONF}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ${hostonly} ]] && ! [[ ${i18n_install_all} == "yes" ]]; then
|
|
|
|
install_local_i18n || install_all_kbd
|
|
|
|
else
|
|
|
|
install_all_kbd
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|