Created
July 1, 2025 18:11
-
-
Save rorar/d247d6175942382fff9fa4dfac521704 to your computer and use it in GitHub Desktop.
binhex Docker - change locale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
######################################## | |
# 0) Prüfen, ob grep & echo vorhanden sind | |
######################################## | |
# - 'echo' ist i. d. R. ein Bash-Builtin; trotzdem prüfen wir, | |
# ob eine Binärdatei vorhanden ist (Teil von coreutils). | |
# - Fehlen die Kommandos, werden sie via pacman installiert. | |
######################################## | |
command -v grep >/dev/null 2>&1 || { | |
printf '\e[33m[WARN]\e[0m grep nicht gefunden – installiere …\n' | |
pacman -Sy --noconfirm grep | |
printf '\e[32m[INFO]\e[0m grep wurde installiert.\n' | |
} | |
# Nur selten nötig, aber der Vollständigkeit halber | |
if ! command -v echo >/dev/null 2>&1 || [[ ! -x "$(command -v echo)" ]]; then | |
printf '\e[33m[WARN]\e[0m echo nicht gefunden – installiere coreutils …\n' | |
pacman -Sy --noconfirm coreutils | |
printf '\e[32m[INFO]\e[0m coreutils (echo) wurde installiert.\n' | |
fi | |
######################################## | |
# 1) Variable(n) für die gewünschte Locale | |
######################################## | |
LOCALE_CUSTOM_VAR="de_DE" | |
LOCALE_CUSTOM_CHAR="UTF-8" | |
LOCALE_LINE="${LOCALE_CUSTOM_VAR}.${LOCALE_CUSTOM_CHAR} ${LOCALE_CUSTOM_CHAR}" | |
######################################## | |
# Hilfsfunktionen für farbige Log-Ausgaben | |
######################################## | |
info () { printf '\e[32m[INFO]\e[0m %s\n' "$*"; } | |
warn () { printf '\e[33m[WARN]\e[0m %s\n' "$*"; } | |
fail () { printf '\e[31m[FAIL]\e[0m %s\n' "$*"; exit 1; } | |
######################################## | |
# 2) /etc/locale.gen prüfen & anpassen | |
######################################## | |
if grep -q -E "^${LOCALE_LINE}$" /etc/locale.gen; then | |
info "Locale-Eintrag bereits aktiv: ${LOCALE_LINE}" | |
elif grep -q -E "^#${LOCALE_LINE}$" /etc/locale.gen; then | |
info "Locale-Eintrag gefunden, aber auskommentiert – aktiviere ihn." | |
sed -i "s/^#${LOCALE_LINE}$/${LOCALE_LINE}/" /etc/locale.gen | |
else | |
warn "Locale-Eintrag nicht vorhanden – füge hinzu." | |
echo "${LOCALE_LINE}" >> /etc/locale.gen | |
fi | |
######################################## | |
# 3) Prüfen, ob glibc installiert ist | |
######################################## | |
if pacman -Qi glibc &>/dev/null; then | |
info "glibc ist bereits installiert." | |
else | |
warn "glibc nicht gefunden – installiere …" | |
pacman -Sy --noconfirm glibc | |
info "glibc wurde installiert." | |
fi | |
######################################## | |
# 4) locale-gen ausführen – ggf. erneut, falls Fehler erkannt | |
######################################## | |
run_locale_gen () { | |
locale-gen 2>&1 | tee /tmp/locale.log | |
} | |
info "Führe locale-gen aus …" | |
if run_locale_gen | grep -q "Generation complete."; then | |
info "Locale-Generierung erfolgreich." | |
else | |
# Prüfen auf fehlende locale.alias o. Ä. | |
if grep -q "locale alias file" /tmp/locale.log; then | |
warn "locale.alias-Problem erkannt – glibc wird neu installiert." | |
pacman -Sy --noconfirm --overwrite='*' glibc | |
run_locale_gen | grep -q "Generation complete." \ | |
&& info "Locale-Generierung erfolgreich nach Neuinstallation." \ | |
|| fail "Locale-Generierung schlug erneut fehl!" | |
else | |
fail "locale-gen schlug fehl – Log siehe /tmp/locale.log" | |
fi | |
fi | |
######################################## | |
# 5) Systemweite Variablen eintragen | |
######################################## | |
echo "LANG=${LOCALE_CUSTOM_VAR}.${LOCALE_CUSTOM_CHAR}" > /etc/locale.conf | |
echo "LANG=${LOCALE_CUSTOM_VAR}.${LOCALE_CUSTOM_CHAR}" # sichtbarer Beweis | |
info "Setup abgeschlossen – aktuelle Locale:" | |
locale | grep -E 'LANG|LC_ALL' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment