#!/bin/sh

set -eu

SHARUN="https://raw.githubusercontent.com/pkgforge-dev/Anylinux-AppImages/refs/heads/main/useful-tools/quick-sharun.sh"
ARCH="$(uname -m)"
VERSION="$(cat ~/version)"
export ARCH VERSION
export OUTPATH=./dist
export DESKTOP=/usr/share/applications/ru.linux_gaming.PortProtonQt.desktop
export ICON=/usr/share/icons/hicolor/scalable/apps/ru.linux_gaming.PortProtonQt.svg
export OUTNAME=PortProtonQt-"$VERSION"-anylinux-"$ARCH".AppImage
export DEPLOY_OPENGL=1
export DEPLOY_SYS_PYTHON=1
export OPTIMIZE_LAUNCH=1

# Adjust comp settings to bypass oom-killer
export DWARFS_COMP="zstd:level=15 -S22 -B5"

# DEPLOY ALL LIBS
wget --retry-connrefused --tries=30 "$SHARUN" -O ./quick-sharun
chmod +x ./quick-sharun

# Add udev rules
mkdir -p ./AppDir/etc/udev/rules.d
cp /usr/lib/udev/rules.d/60-portprotonqt.rules ./AppDir/etc/udev/rules.d

# Deploy Qt translations
mkdir -p ./AppDir/usr/share/qt6/translations
cp -r /usr/share/qt6/translations/* ./AppDir/usr/share/qt6/translations/

# Deploy dependencies
# Qt libs have to be passed manually due to the app being a python script
./quick-sharun \
	/usr/bin/portprotonqt* \
	/usr/lib/libQt6Core.so* \
	/usr/lib/libQt6Gui.so* \
	/usr/lib/libQt6Network.so* \
	/usr/lib/libudev.so*

# Turn AppDir into AppImage
./quick-sharun --make-appimage
