Files
config/linux/fedora_setup.sh
T

204 lines
4.7 KiB
Bash
Executable File

#!/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 \
filezilla \
git \
hugo \
NetworkManager-openvpn \
openvpn \
qbittorrent \
steam \
thunderbird \
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 optional RPM apps..."
pkg_install discord || warn "discord not available from enabled repos"
echo
echo "Installing Flatpaks..."
flatpak_install \
org.signal.Signal \
com.bitwarden.desktop \
io.github.martinrotter.rssguard \
com.spotify.Client \
io.github.Archeb.opentrace
echo
echo "Setting ownership hint for /mnt/games..."
echo "After you mount the ext4 games partition, you may want:"
echo " sudo chown -R ${REAL_USER}:${REAL_USER} /mnt/games"
cat <<EOF
=== Setup completed at $(date --iso-8601=seconds) ===
Check log: $LOGFILE
Manual mount follow-up:
1. Find UUIDs:
lsblk -f
2. Back up fstab:
sudo cp /etc/fstab /etc/fstab.bak
3. Add entries like these:
# ext4 games partition
UUID=XXXXXX-XXXX /mnt/games ext4 defaults,nofail 0 2
# example media partition if still NTFS
UUID=YYYYYY-YYYY /mnt/media ntfs defaults,nofail,uid=1000,gid=1000 0 0
4. Test mounts:
sudo mount -a
5. For the ext4 games partition, fix ownership if needed:
sudo chown -R ${REAL_USER}:${REAL_USER} /mnt/games
6. Reboot and verify.
Notes:
- /mnt/games is assumed to be ext4.
- Signal Desktop is installed via Flatpak only.
- ext4 stores ownership/permissions in the filesystem itself.
- Use KDE Partition Manager or GNOME Disks if you prefer a GUI.
EOF