fix(releng): correct hostname and keyboard mapping in anaconda post-installation
Fix two bugs in the anaconda post-installation script: 1. Hostname handling: Anaconda writes an empty /etc/hostname to the target system. Now we preserve the hostname set during installation from the live environment, falling back to 'fws' if using default values. 2. Keyboard mapping: Anaconda derives keyboard layout from language only, ignoring territory. For locales with territory variants (e.g., fr_CH for Switzerland), we now apply territory-specific keyboard maps to both console (vconsole.conf) and X11 (xorg.conf.d) using langtable for proper mapping.
This commit is contained in:
@@ -89,6 +89,19 @@ SYSROOT=/mnt/sysroot
|
|||||||
# DNS pour que « pacman -S <bureau> » fonctionne dans le chroot.
|
# DNS pour que « pacman -S <bureau> » fonctionne dans le chroot.
|
||||||
cp -f /etc/resolv.conf "$SYSROOT/etc/resolv.conf" 2>/dev/null || true
|
cp -f /etc/resolv.conf "$SYSROOT/etc/resolv.conf" 2>/dev/null || true
|
||||||
|
|
||||||
|
# --- Hostname : reprendre celui saisi dans Anaconda, sinon « fws » -----------
|
||||||
|
# BUG observé : Anaconda écrit un /etc/hostname VIDE dans la cible (le hostname
|
||||||
|
# du spoke Réseau n'est pas capté). On reprend donc le hostname COURANT du LIVE
|
||||||
|
# (Anaconda l'applique au live quand on le saisit dans le spoke) s'il diffère du
|
||||||
|
# défaut archiso, sinon on pose un défaut propre « fws » — jamais de hostname
|
||||||
|
# vide. (Ce %post tourne APRÈS l'écriture d'Anaconda → on écrase son fichier
|
||||||
|
# vide.)
|
||||||
|
HN="$(cat /proc/sys/kernel/hostname 2>/dev/null)"
|
||||||
|
case "$HN" in
|
||||||
|
""|archlinux|localhost|localhost.localdomain) HN="fws" ;;
|
||||||
|
esac
|
||||||
|
echo "$HN" > "$SYSROOT/etc/hostname"
|
||||||
|
|
||||||
# Choix du bureau (écrit par l'addon « Choix du bureau », à venir ; valeur lue
|
# Choix du bureau (écrit par l'addon « Choix du bureau », à venir ; valeur lue
|
||||||
# par le %post chrooté ci-dessous). « cli » par défaut si absent.
|
# par le %post chrooté ci-dessous). « cli » par défaut si absent.
|
||||||
if [ -f /tmp/fws-desktop ]; then
|
if [ -f /tmp/fws-desktop ]; then
|
||||||
@@ -194,6 +207,44 @@ else
|
|||||||
echo "[FWS] AVERTISSEMENT : grub-install a échoué — bootloader à refaire à la main"
|
echo "[FWS] AVERTISSEMENT : grub-install a échoué — bootloader à refaire à la main"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# --- 3bis) Clavier : corriger le keymap selon le TERRITOIRE de la locale ------
|
||||||
|
# BUG observé : Anaconda dérive le clavier de la LANGUE en IGNORANT le territoire
|
||||||
|
# → fr_CH (Suisse) donne « fr » (France) au lieu du clavier SUISSE. On corrige :
|
||||||
|
# si un keymap console spécifique au territoire existe (fr_CH, de_CH…), on
|
||||||
|
# l'impose dans /etc/vconsole.conf, et on règle aussi le clavier X11 (pour un
|
||||||
|
# bureau installé ensuite) via langtable. Locale lue dans /etc/locale.conf, à
|
||||||
|
# défaut dans /root/anaconda-ks.cfg (« lang … »).
|
||||||
|
fix_keyboard() {
|
||||||
|
local langv loc lng terr font xk xl xv
|
||||||
|
langv="$(. /etc/locale.conf 2>/dev/null; printf '%s' "${LANG:-}")"
|
||||||
|
[ -n "$langv" ] || langv="$(sed -n 's/^lang[[:space:]]\+//p' /root/anaconda-ks.cfg 2>/dev/null | head -1)"
|
||||||
|
loc="${langv%%.*}" # fr_CH.UTF-8 → fr_CH
|
||||||
|
lng="${loc%%_*}" # fr
|
||||||
|
terr="${loc#*_}"; [ "$terr" = "$loc" ] && terr="" # CH
|
||||||
|
[ -n "$terr" ] || return 0
|
||||||
|
find /usr/share/kbd/keymaps -name "${lng}_${terr}.map.gz" 2>/dev/null | grep -q . || return 0
|
||||||
|
# vconsole (console TTY) : keymap du territoire (ex. fr_CH). On préserve FONT.
|
||||||
|
font="$(grep '^FONT=' /etc/vconsole.conf 2>/dev/null)"
|
||||||
|
{ echo "KEYMAP=${lng}_${terr}"; [ -n "$font" ] && echo "$font"; } > /etc/vconsole.conf
|
||||||
|
# X11 (bureau) : layout/variant via langtable (ex. fr_CH → 'ch(fr)' → ch/fr).
|
||||||
|
xk="$(python3 -c "import langtable; k=langtable.list_keyboards(languageId='$lng', territoryId='$terr'); print(k[0] if k else '')" 2>/dev/null)"
|
||||||
|
case "$xk" in
|
||||||
|
*'('*')') xl="${xk%%(*}"; xv="${xk#*(}"; xv="${xv%)}" ;;
|
||||||
|
?*) xl="$xk"; xv="" ;;
|
||||||
|
*) return 0 ;;
|
||||||
|
esac
|
||||||
|
mkdir -p /etc/X11/xorg.conf.d
|
||||||
|
cat > /etc/X11/xorg.conf.d/00-keyboard.conf <<EOF
|
||||||
|
Section "InputClass"
|
||||||
|
Identifier "system-keyboard"
|
||||||
|
MatchIsKeyboard "on"
|
||||||
|
Option "XkbLayout" "$xl"
|
||||||
|
Option "XkbVariant" "$xv"
|
||||||
|
EndSection
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
fix_keyboard || echo "[FWS] clavier : ajustement territoire ignoré"
|
||||||
|
|
||||||
# --- 4) Bureau choisi : pacman -S du DE (non bloquant si pas de réseau) -------
|
# --- 4) Bureau choisi : pacman -S du DE (non bloquant si pas de réseau) -------
|
||||||
DESK="cli"
|
DESK="cli"
|
||||||
[ -f /tmp/fws-desktop ] && DESK="$(tr -d '[:space:]' < /tmp/fws-desktop)"
|
[ -f /tmp/fws-desktop ] && DESK="$(tr -d '[:space:]' < /tmp/fws-desktop)"
|
||||||
|
|||||||
Reference in New Issue
Block a user