#!/bin/sh # BastionGuard – locale enablement # Abilita/genera en_US.UTF-8 sul sistema SENZA impostarla come default. set -eu LOCALE_GEN="en_US.UTF-8" LOCALE_A_NEEDLE_1="en_US.utf8" LOCALE_A_NEEDLE_2="en_US.UTF-8" echo "[BastionGuard] Richiesta abilitazione locale: ${LOCALE_GEN} (senza cambiarla di default)" # Se gia' presente, esci if locale -a 2>/dev/null | grep -qiE "^(${LOCALE_A_NEEDLE_1}|${LOCALE_A_NEEDLE_2})$"; then echo "[BastionGuard] Locale ${LOCALE_GEN} gia' disponibile. Nessuna modifica necessaria." exit 0 fi # Rileva distro ID="" ID_LIKE="" if [ -f /etc/os-release ]; then # shellcheck disable=SC1091 . /etc/os-release ID="${ID:-}" ID_LIKE="${ID_LIKE:-}" fi is_debian_like() { echo "$ID $ID_LIKE" | grep -qiE "debian|ubuntu"; } is_arch_like() { echo "$ID $ID_LIKE" | grep -qiE "arch"; } is_rhel_like() { echo "$ID $ID_LIKE" | grep -qiE "fedora|rhel|centos|rocky|alma"; } is_suse_like() { echo "$ID $ID_LIKE" | grep -qiE "suse|opensuse"; } # Funzione: verifica che sia comparsa dopo le operazioni verify_enabled() { if locale -a 2>/dev/null | grep -qiE "^(${LOCALE_A_NEEDLE_1}|${LOCALE_A_NEEDLE_2})$"; then echo "[BastionGuard] OK: locale ${LOCALE_GEN} ora disponibile." return 0 fi echo "[BastionGuard] ERRORE: locale ${LOCALE_GEN} non risulta disponibile dopo il setup." return 1 } # Debian/Ubuntu: usa /etc/locale.gen + locale-gen, ma NON update-locale if is_debian_like; then echo "[BastionGuard] Sistema Debian-like: abilito in /etc/locale.gen e genero" if [ -f /etc/locale.gen ]; then # decommenta o aggiungi if grep -qE "^[# ]*en_US.UTF-8[[:space:]]+UTF-8" /etc/locale.gen; then sed -i 's/^[# ]*\(en_US.UTF-8[[:space:]]\+UTF-8\)/\1/' /etc/locale.gen else echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen fi fi if command -v locale-gen >/dev/null 2>&1; then locale-gen en_US.UTF-8 >/dev/null else echo "[BastionGuard] ERRORE: locale-gen non trovato." exit 2 fi verify_enabled exit $? # Arch: /etc/locale.gen + locale-gen (NON scrivere /etc/locale.conf) elif is_arch_like; then echo "[BastionGuard] Sistema Arch-like: abilito in /etc/locale.gen e genero" if [ -f /etc/locale.gen ]; then if grep -qE "^[# ]*en_US.UTF-8[[:space:]]+UTF-8" /etc/locale.gen; then sed -i 's/^[# ]*\(en_US.UTF-8[[:space:]]\+UTF-8\)/\1/' /etc/locale.gen else echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen fi fi locale-gen >/dev/null verify_enabled exit $? # Fedora/RHEL: NON usare localectl set-locale. Serve il langpack. elif is_rhel_like; then echo "[BastionGuard] Sistema RHEL/Fedora-like: installo langpack se necessario (senza cambiare default)" if command -v dnf >/dev/null 2>&1; then # glibc-langpack-en abilita en_US su molte varianti Fedora/RHEL dnf -y install glibc-langpack-en >/dev/null elif command -v yum >/dev/null 2>&1; then yum -y install glibc-langpack-en >/dev/null else echo "[BastionGuard] ERRORE: dnf/yum non trovato." exit 2 fi verify_enabled exit $? # openSUSE: spesso basta glibc-locale / glibc-locale-base (varia). Proviamo pacchetto EN. elif is_suse_like; then echo "[BastionGuard] Sistema SUSE-like: installo pacchetti locale EN se necessari (senza cambiare default)" if command -v zypper >/dev/null 2>&1; then # nomi pacchetti possono variare; questi sono comuni zypper -n install glibc-locale glibc-i18ndata >/dev/null || true else echo "[BastionGuard] ERRORE: zypper non trovato." exit 2 fi verify_enabled exit $? # Fallback: prova localedef senza cambiare default else echo "[BastionGuard] Distro non riconosciuta: provo localedef (senza cambiare default)" if command -v localedef >/dev/null 2>&1; then # prova a creare en_US.UTF-8 se i sorgenti sono presenti localedef -i en_US -f UTF-8 en_US.UTF-8 >/dev/null 2>&1 || true fi verify_enabled exit $? fi