feat: i18n moonarch-update via pacman gettext + inline DE
Update PKGBUILD version / update-pkgver (push) Successful in 2s
Update PKGBUILD version / update-pkgver (push) Successful in 2s
Prompts and log lines now follow the user's LANG. Reuses pacman's
gettext catalog for strings with matching upstream msgids
(Proceed with installation?, [Y/n], Starting full system upgrade...,
Do you want to remove these packages?). Moonarch-specific strings
go through an inline _t "en" "de" helper keyed off ${LANG%%.*}.
confirm() switches to pacman-style: :: prefix, default Y, accepts
y/Y/j/J. No PKGBUILD change — gettext ships with base.
This commit is contained in:
+36
-21
@@ -4,6 +4,21 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# --- i18n ---
|
||||
# Reuse pacman's gettext catalog for prompts that match upstream msgids.
|
||||
# For moonarch-specific strings fall back to _t() inline translation.
|
||||
export TEXTDOMAIN=pacman
|
||||
export TEXTDOMAINDIR=/usr/share/locale
|
||||
YN=$(gettext "[Y/n]")
|
||||
|
||||
_t() {
|
||||
# _t "english" "deutsch" — picks by $LANG
|
||||
case "${LANG%%.*}" in
|
||||
de_*) printf '%s' "$2" ;;
|
||||
*) printf '%s' "$1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# --- Helper functions ---
|
||||
|
||||
log() {
|
||||
@@ -19,8 +34,8 @@ read_packages() {
|
||||
}
|
||||
|
||||
confirm() {
|
||||
read -r -p "$1 [y/N] " response
|
||||
[[ "$response" =~ ^[yY]$ ]]
|
||||
read -r -p ":: $1 $YN " response
|
||||
[[ -z "$response" || "$response" =~ ^[yYjJ]$ ]]
|
||||
}
|
||||
|
||||
OFFICIAL_PACKAGES="/usr/share/moonarch/official.txt"
|
||||
@@ -29,85 +44,85 @@ AUR_PACKAGES="/usr/share/moonarch/aur.txt"
|
||||
# --- Prerequisites ---
|
||||
|
||||
if [[ $EUID -eq 0 ]]; then
|
||||
err "Do NOT run as root. The script uses sudo where needed."
|
||||
err "$(_t "Do NOT run as root. The script uses sudo where needed." "Nicht als root ausführen. Das Script verwendet sudo wo nötig.")"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- 1. Update system packages ---
|
||||
|
||||
log "=== Update system packages ==="
|
||||
log "=== $(gettext $'Starting full system upgrade...\n' | tr -d '\n.') ==="
|
||||
|
||||
if confirm "Run pacman -Syu?"; then
|
||||
if confirm "$(_t "Run pacman -Syu?" "pacman -Syu ausführen?")"; then
|
||||
sudo pacman -Syu
|
||||
else
|
||||
log "System update skipped."
|
||||
log "$(_t "System update skipped." "Systemaktualisierung übersprungen.")"
|
||||
fi
|
||||
|
||||
if command -v paru &>/dev/null; then
|
||||
if confirm "Update AUR packages (paru -Sua)?"; then
|
||||
if confirm "$(_t "Update AUR packages (paru -Sua)?" "AUR-Pakete aktualisieren (paru -Sua)?")"; then
|
||||
paru -Sua
|
||||
else
|
||||
log "AUR update skipped."
|
||||
log "$(_t "AUR update skipped." "AUR-Aktualisierung übersprungen.")"
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- 2. Reconcile package lists ---
|
||||
|
||||
log "=== Reconcile package lists ==="
|
||||
log "=== $(_t "Reconcile package lists" "Paketlisten abgleichen") ==="
|
||||
|
||||
if [[ -f "$OFFICIAL_PACKAGES" ]]; then
|
||||
MISSING_OFFICIAL=$(comm -23 <(read_packages "$OFFICIAL_PACKAGES" | sort) <(pacman -Qq | sort) || true)
|
||||
if [[ -n "$MISSING_OFFICIAL" ]]; then
|
||||
log "Missing official packages:"
|
||||
log "$(_t "Missing official packages:" "Fehlende offizielle Pakete:")"
|
||||
echo "$MISSING_OFFICIAL"
|
||||
if confirm "Install?"; then
|
||||
if confirm "$(gettext 'Proceed with installation?')"; then
|
||||
# shellcheck disable=SC2086
|
||||
sudo pacman -S --needed --noconfirm $MISSING_OFFICIAL
|
||||
fi
|
||||
else
|
||||
log "All official packages installed."
|
||||
log "$(_t "All official packages installed." "Alle offiziellen Pakete installiert.")"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -f "$AUR_PACKAGES" ]] && command -v paru &>/dev/null; then
|
||||
MISSING_AUR=$(comm -23 <(read_packages "$AUR_PACKAGES" | sort) <(pacman -Qq | sort) || true)
|
||||
if [[ -n "$MISSING_AUR" ]]; then
|
||||
log "Missing AUR packages:"
|
||||
log "$(_t "Missing AUR packages:" "Fehlende AUR-Pakete:")"
|
||||
echo "$MISSING_AUR"
|
||||
if confirm "Install?"; then
|
||||
if confirm "$(gettext 'Proceed with installation?')"; then
|
||||
# shellcheck disable=SC2086
|
||||
paru -S --needed --noconfirm $MISSING_AUR
|
||||
fi
|
||||
else
|
||||
log "All AUR packages installed."
|
||||
log "$(_t "All AUR packages installed." "Alle AUR-Pakete installiert.")"
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- 3. Orphaned packages ---
|
||||
|
||||
log "=== Orphaned packages ==="
|
||||
log "=== $(_t "Orphaned packages" "Verwaiste Pakete") ==="
|
||||
|
||||
ORPHANS=$(pacman -Qdtq 2>/dev/null || true)
|
||||
if [[ -n "$ORPHANS" ]]; then
|
||||
log "Orphaned packages found:"
|
||||
log "$(_t "Orphaned packages found:" "Verwaiste Pakete gefunden:")"
|
||||
echo "$ORPHANS"
|
||||
if confirm "Remove?"; then
|
||||
if confirm "$(gettext 'Do you want to remove these packages?')"; then
|
||||
# shellcheck disable=SC2086
|
||||
sudo pacman -Rsn --noconfirm $ORPHANS
|
||||
fi
|
||||
else
|
||||
log "No orphaned packages."
|
||||
log "$(_t "No orphaned packages." "Keine verwaisten Pakete.")"
|
||||
fi
|
||||
|
||||
# --- Done ---
|
||||
|
||||
log ""
|
||||
log "============================================"
|
||||
log " Moonarch update complete!"
|
||||
log " $(_t "Moonarch update complete!" "Moonarch-Aktualisierung abgeschlossen!")"
|
||||
log "============================================"
|
||||
|
||||
# Keep terminal open when launched from a GUI (e.g. Waybar on-click)
|
||||
if [[ -t 0 ]]; then
|
||||
echo
|
||||
read -n 1 -s -r -p "Press any key to close..."
|
||||
read -n 1 -s -r -p "$(_t "Press any key to close..." "Beliebige Taste drücken zum Schließen …")"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user