#!/usr/bin/env bash set -Eeuo pipefail LOGFILE="${HOME:-/root}/fedora-setup-$(date +%Y%m%d-%H%M%S).log" exec > >(tee -a "$LOGFILE") 2>&1 echo "=== Fedora New Machine Setup Started at $(date --iso-8601=seconds) ===" if [[ ${EUID:-$(id -u)} -eq 0 ]]; then SUDO="" REAL_USER="${SUDO_USER:-root}" REAL_HOME="$(getent passwd "$REAL_USER" | cut -d: -f6)" else SUDO="sudo" REAL_USER="$USER" REAL_HOME="$HOME" fi FEDORA_VER="$(rpm -E %fedora)" run() { echo echo ">>> $*" "$@" } warn() { echo "WARNING: $*" >&2 } have_cmd() { command -v "$1" >/dev/null 2>&1 } pkg_installed() { rpm -q "$1" >/dev/null 2>&1 } pkg_install() { local to_install=() local pkg for pkg in "$@"; do if ! pkg_installed "$pkg"; then to_install+=("$pkg") fi done if ((${#to_install[@]} == 0)); then echo "Packages already installed: $*" return 0 fi run $SUDO dnf install -y "${to_install[@]}" || warn "Some packages failed to install: ${to_install[*]}" } flatpak_install() { local ref for ref in "$@"; do if flatpak info "$ref" >/dev/null 2>&1; then echo "Flatpak already installed: $ref" else run flatpak install -y flathub "$ref" || warn "Flatpak failed: $ref" fi done } write_vscode_repo() { run $SUDO rpm --import https://packages.microsoft.com/keys/microsoft.asc run $SUDO tee /etc/yum.repos.d/vscode.repo >/dev/null <<'EOF' [code] name=Visual Studio Code baseurl=https://packages.microsoft.com/yumrepos/vscode enabled=1 type=rpm-md gpgcheck=1 gpgkey=https://packages.microsoft.com/keys/microsoft.asc EOF } echo "Detected Fedora version: $FEDORA_VER" echo "Running as: ${REAL_USER}" echo echo "Creating mount points..." run $SUDO mkdir -p /mnt/games /mnt/media if have_cmd systemctl; then run $SUDO systemctl daemon-reload || true fi echo echo "Installing DNF tools..." pkg_install dnf-plugins-core echo echo "Installing RPM Fusion repos..." run $SUDO dnf install -y \ "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-${FEDORA_VER}.noarch.rpm" \ "https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-${FEDORA_VER}.noarch.rpm" \ || warn "RPM Fusion install failed or repos may already exist" echo echo "Enabling Flatpak + Flathub..." pkg_install flatpak run flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo echo echo "Upgrading system..." run $SUDO dnf upgrade -y || warn "System upgrade encountered errors" echo echo "Installing multimedia codecs..." run $SUDO dnf swap -y ffmpeg-free ffmpeg --allowerasing || warn "ffmpeg swap failed" run $SUDO dnf install -y \ mozilla-openh264 \ gstreamer1-plugins-bad-freeworld \ ffmpeg \ || warn "Codec package install failed" run $SUDO dnf update -y @multimedia --setopt=install_weak_deps=False --exclude=PackageKit-gstreamer-plugin \ || warn "Multimedia group update failed" echo echo "Installing common RPM apps..." pkg_install \ git \ hugo \ NetworkManager-openvpn \ openvpn \ qbittorrent \ steam \ oh-my-posh \ openrgb \ screenfetch \ yt-dlp echo echo "Installing fonts..." pkg_install cascadia-fonts-all run $SUDO fc-cache -f || true echo echo "Setting up VS Code repo..." write_vscode_repo run $SUDO dnf makecache -y || warn "dnf makecache failed" pkg_install code echo echo "Installing Flatpaks..." flatpak_install \ org.signal.Signal \ com.bitwarden.desktop \ io.github.martinrotter.rssguard \ com.spotify.Client \ io.github.Archeb.opentrace \ org.filezillaproject.Filezilla \ org.mozilla.Thunderbird \ com.discordapp.Discord echo echo "Configuring Flatpak access to mounted media..." run flatpak override --user --filesystem=/mnt/media org.filezillaproject.Filezilla \ || warn "Could not grant FileZilla access to /mnt/media" echo echo "Setting ownership hint for mounted directories..." echo "After you mount the ext4 games/media partitions, you may want:" echo " sudo chown -R ${REAL_USER}:${REAL_USER} /mnt/games /mnt/media" echo echo "qBittorrent note: keep the RPM build for host-level VPN adapter binding." echo "After connecting OpenVPN, select its tun interface in qBittorrent:" echo " Tools -> Options -> Advanced -> Network interface" echo "Then restart qBittorrent and verify transfers stop when the VPN disconnects." echo echo "=== Fedora New Machine Setup Finished at $(date --iso-8601=seconds) ===" echo "Log saved to: $LOGFILE"