#!/usr/bin/env bash set -e DRY_RUN=false # Check for dry-run flag if [[ "$1" == "--dry-run" ]]; then DRY_RUN=true echo "Running in dry-run mode. No changes will be made." fi run_cmd() { # Run the command or just print it if dry-run if [ "$DRY_RUN" = true ]; then echo "[DRY-RUN] $*" else eval "$@" fi } echo "Detecting Linux distribution..." # Detect distro if [ -f /etc/os-release ]; then . /etc/os-release DISTRO=$ID VERSION=$VERSION_ID else echo "Cannot detect Linux distribution." exit 1 fi # Detect if immutable (rpm-ostree or SteamOS readonly) IMMUTABLE=false IS_STEAMOS=false if command -v rpm-ostree &>/dev/null; then IMMUTABLE=true elif command -v steamos-readonly &>/dev/null; then IMMUTABLE=true IS_STEAMOS=true fi echo "Distribution detected: $DISTRO $VERSION" echo "Immutable system: $IMMUTABLE" # ----------------------------- # Debian/Ubuntu installer # ----------------------------- install_debian() { echo "Adding i386 architecture..." run_cmd "sudo dpkg --add-architecture i386" run_cmd "sudo apt update" echo "Installing 32-bit runtime libraries..." run_cmd "sudo apt install -y libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386" } # ----------------------------- # Fedora/Bazzite installer (immutable-aware) # ----------------------------- install_fedora() { if [ "$IMMUTABLE" = true ]; then echo "Immutable Fedora/Bazzite detected." # List of 32-bit packages we want PKGS=("glibc.i686" "libstdc++.i686" "ncurses-libs.i686" "zlib-ng-compat.i686") # Filter out packages that are already installed TO_INSTALL=() for pkg in "${PKGS[@]}"; do if rpm -q "$pkg" &>/dev/null; then echo "$pkg is already installed, skipping." else TO_INSTALL+=("$pkg") fi done if [ ${#TO_INSTALL[@]} -eq 0 ]; then echo "All required 32-bit packages are already installed. Nothing to do." else echo "Layering 32-bit libraries via rpm-ostree: ${TO_INSTALL[*]}" run_cmd "sudo rpm-ostree install ${TO_INSTALL[*]}" echo "Reboot required for layered packages to take effect." fi else echo "Installing 32-bit libraries via dnf..." run_cmd "sudo dnf install -y glibc.i686 libstdc++.i686 ncurses-libs.i686 zlib-ng-compat.i686" fi } # ----------------------------- # Arch/Manjaro/SteamOS 3+ installer # ----------------------------- install_arch() { if [ "$IS_STEAMOS" = true ]; then echo "Immutable SteamOS 3+ detected." read -p "Do you want to temporarily disable read-only mode to install 32-bit libraries? (y/N): " RESP if [[ "$RESP" =~ ^[Yy]$ ]]; then echo "Disabling read-only mode..." run_cmd "sudo steamos-readonly disable" echo "Installing 32-bit libraries..." run_cmd "sudo pacman -S --noconfirm lib32-glibc lib32-gcc-libs lib32-ncurses lib32-zlib" echo "Re-enabling read-only mode..." run_cmd "sudo steamos-readonly enable" echo "32-bit libraries installed successfully!" else echo "Operation canceled. You can manually disable read-only mode later and rerun the script." fi return fi # Regular Arch / Manjaro if ! grep -q '^\[multilib\]' /etc/pacman.conf; then echo "Enabling multilib repository..." run_cmd "sudo sed -i '/\[multilib\]/,/Include/s/^#//' /etc/pacman.conf" run_cmd "sudo pacman -Syu --noconfirm" fi echo "Installing 32-bit runtime libraries..." run_cmd "sudo pacman -S --noconfirm lib32-glibc lib32-gcc-libs lib32-ncurses lib32-zlib" } # ----------------------------- # Execute per detected distro # ----------------------------- case "$DISTRO" in ubuntu|debian) echo "Installing 32-bit libraries for Debian/Ubuntu..." install_debian ;; fedora|bazzite) echo "Installing 32-bit libraries for Fedora/Bazzite..." install_fedora ;; arch|manjaro|cachyos) echo "Installing 32-bit libraries for Arch/Manjaro/SteamOS 3+..." install_arch ;; *) echo "Unsupported distribution: $DISTRO" exit 1 ;; esac echo "32-bit multilib support installation complete!"