#!/bin/sh

if (( $EUID != 0 )); then
    echo "This script must be run as root." >&2
    exit 1
fi

build-essentials() {
	dnf install \
		make automake gcc gcc-c++ kernel-devel
}

development() {
	build-essentials

	dnf install \
		zsh \
		git	\
		shellcheck -y
}

games() {
	flatpak install flathub org.prismlauncher.PrismLauncher -y
	steam
}

steam() {
	flatpak install flathub com.valvesoftware.Steam -y
	dnf install steam-devices -y
}

communication() {
	flatpak install flathub org.telegram.desktop -y
	flatpak install flathub org.signal.Signal -y
}

utilities() {
    dnf install \
        micro \
        zathura \
        gimp -y
	flatpak install flathub engineer.atlas.Nyxt -y
	flatpak install flathub dev.zed.Zed -y
	flatpak install flathub com.bitwarden.desktop -y
	qutebrowser
}

keyd() {
	git clone https://github.com/rvaiya/keyd ~/Repos/keyd
	cd ~/Repos/keyd || exit
	make && make install
	cd - || exit
	systemctl enable --now keyd
}

qutebrowser() {
    dnf build-dep qutebrowser -y
    # socat is needed for startup script in root/bin/qutebrowser
    dnf install \
        socat \
        python3-virtualenv \
        qt5-qtwebengine-freeworld \
        libatomic -y
    git clone https://github.com/qutebrowser/qutebrowser /opt/qutebrowser
	cd /opt/qutebrowser || exit
	python3 scripts/mkvenv.py
	.venv/bin/pip install -e .
	cd - || exit
}

cosmic() {
	mkdir -p /etc/environment.d
	printf %s\\n "COSMIC_DATA_CONTROL_ENABLED=1" >> /etc/environment.d/clipboard.conf

	dnf install \
		copyq \
		thunar \
		xfce4-terminal -y
}

niri() {
	dnf install \
		niri \
		rofi \
		waybar \
		swaybg \
		swaylock -y

	rofication
}

anyrun() {
	git clone https://github.com/Kirottu/anyrun ~/Repos/anyrun
	cd ~/Repos/anyrun || exit
	dnf install \
			make automake gcc gcc-c++ kernel-devel \
			gtk4-layer-shell-devel \
			gtk4-devel \
			pango-devel \
			cairo-devel cairo-gobject \
			gdk-pixbuf2 \
			glib2 -y
		
	# Build all packages, and install the Anyrun binary
	cargo build --release
	cargo install --path anyrun/ --root /usr/local
	cd - || exit
}

kidex() {
	git clone https://github.com/Kirottu/kidex ~/Repos/kidex
	cd ~/Repos/kidex || exit
	cargo install --path kidex/ --root /usr/local
	cd - || exit
}

install_cargo() {
	curl https://sh.rustup.rs -sSf | sh
}

# rofication() {
# }

mkdir -p ~/Repos || exit
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
install_cargo

development
communication
utilities
games
keyd
cosmic
niri
