#!/usr/bin/env bash
set -e

# ---- RPM Fusion ----
sudo dnf -y install \
  https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
  https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

sudo dnf -y upgrade --refresh

# ---- CachyOS Kernel ----
sudo dnf -y copr enable bieszczaders/kernel-cachyos
sudo dnf -y install kernel-cachyos kernel-cachyos-devel

# ---- Set CachyOS kernel as default ----
CACHY_KERNEL=$(grubby --info=ALL | awk -F= '/^kernel=/ && /cachyos/ {print $2; exit}')
sudo grubby --set-default "$CACHY_KERNEL"

# ---- NVIDIA drivers + CUDA ----
sudo dnf -y install \
  akmod-nvidia \
  xorg-x11-drv-nvidia-cuda \
  xorg-x11-drv-nvidia-cuda-libs

# ---- Sunshine (lizardbyte beta) ----
sudo dnf -y copr enable lizardbyte/beta
sudo dnf -y install sunshine

# ---- Steam ----
sudo dnf -y install steam

# ---- Flatpak + XIVLauncher ----
sudo dnf -y install flatpak
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak install -y flathub dev.goats.xivlauncher

# ---- Firewall ports for Sunshine ----
sudo firewall-cmd --permanent --add-port=47984/tcp
sudo firewall-cmd --permanent --add-port=47989/tcp
sudo firewall-cmd --permanent --add-port=47990/tcp
sudo firewall-cmd --permanent --add-port=48010/tcp
sudo firewall-cmd --permanent --add-port=47998/udp
sudo firewall-cmd --permanent --add-port=47999/udp
sudo firewall-cmd --permanent --add-port=48000/udp

# ---- SSH ----
sudo dnf -y install openssh-server
sudo systemctl enable --now sshd
sudo firewall-cmd --permanent --add-service=ssh

sudo firewall-cmd --reload

# ---- Samba support for Thunar ----
sudo dnf -y install gvfs-smb samba-client

# ---- Set hostname ----
sudo hostnamectl set-hostname 373M3N4NK1

echo "Done. Reboot required to use CachyOS kernel and NVIDIA drivers."