#!/bin/sh

set -ex

EXTRA_PACKAGES="https://raw.githubusercontent.com/pkgforge-dev/Anylinux-AppImages/refs/heads/main/useful-tools/get-debloated-pkgs.sh"

echo "Installing build dependencies..."
echo "---------------------------------------------------------------"
pacman -Syu --noconfirm \
	appstream \
	base-devel \
	cmake \
	cmocka \
	curl \
	dbus \
	fmt \
	gcc-libs \
	git \
	glew \
	glfw \
	glslang \
	glu \
	hicolor-icon-theme \
	lazarus \
	libglvnd \
	libx11 \
	libxkbcommon \
	mesa \
	meson \
	nlohmann-json \
	patchelf \
	pciutils \
	python \
	python-mako \
	python-matplotlib \
	python-numpy \
	qt6ct \
	qt6pas \
	qt6-wayland \
	strace \
	vulkan-headers \
	vulkan-icd-loader \
	vulkan-nouveau \
	vulkan-radeon \
	vulkan-tools \
	wayland \
	wget \
	xorg-server-xvfb \
	zsync

# temp solution until pascube can be built in CI
pacman-key --init
pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
pacman-key --lsign-key 3056513887B78AEB
pacman --noconfirm -U 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst'
pacman --noconfirm -U 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'
echo '[chaotic-aur]
Include = /etc/pacman.d/chaotic-mirrorlist' >> /etc/pacman.conf
pacman -Syu --noconfirm pascube

echo "Installing debloated packages..."
echo "---------------------------------------------------------------"
wget --retry-connrefused --tries=30 "$EXTRA_PACKAGES" -O ./get-debloated-pkgs.sh
chmod +x ./get-debloated-pkgs.sh
./get-debloated-pkgs.sh --add-common --prefer-nano mangohud-mini

#echo "Building pascube..."
#echo "---------------------------------------------------------------"
#sed -i 's|EUID == 0|EUID == 69|g' /usr/bin/makepkg
#git clone --depth 1 https://github.com/benjamimgois/pascube ./pascube && (
#	cd ./pascube
#	makepkg -fs --noconfirm
#	ls -la .
#	pacman --noconfirm -U ./*.pkg.tar.*
#)
