# Maintainer: Peter Jung <admin@ptr1337.dev>

pkgname=jupiter-hw-support
pkgver=20260413.1
pkgrel=1
arch=('any')
license=('MIT')
depends=(
    'python-evdev'
    'python>=3.13'
    'dmidecode' # for jupiter-biosupdate
    'python-crcmod' 'python-click' 'python-progressbar'
    'python-hid>=1.0.6-2' # for jupiter-controller-update
    'jq' # for jupiter-controller-update, jupiter-biosupdate
    'alsa-utils' # for the sound workarounds
    'f3' 'parted' 'e2fsprogs' # for sdcard formatting
    'udisks2>=2.9.4-1.1' # for mounting external drives with the 'as-user' option
)
optdepends=('grub-steamos')
makedepends=('rsync' 'git' 'xorg-xcursorgen')
pkgdesc='CachyOS - Deckify Steam Deck HW Support'
source=("git+https://github.com/evlaV/jupiter-hw-support.git#tag=jupiter-${pkgver}"
        "steamos-btrfs-automount.patch"
        "cachyos-automount.patch"
        "udev-automount-rules.patch"
        "priv-write.patch"
        "cachyos-bios.patch")
#install="$pkgname.install"
options=(!strip !debug)
sha256sums=('b4cb40ac1d61c1ebbc05a0106f7c0fec1c278cd50ae5c9b0fcbc51cbd97b2895'
            'b56443748e059dfc61122f2324b6ca6b1be32e4cf9c08884249a89f1e6438964'
            'cb839c99b9338eebb4f2b73af97f32ccf1684facf9c4b4c181f09247a4af19a4'
            '48bf1ff6957c23b37ed0054ac863a08fdc2c9f80ff11b2a27233af93b443e755'
            '1e4a352bbff01ca68ac9c5f1e9581db458b1b7f663f4e46089be0ebd9d1f7463'
            'f3ca66a1b9ef5d929e925c0a8a07e91d0d7874e47cc549297480bdcf9cb15237')
prepare() {
  cd "${pkgname}"
  git revert -n 8e870e11fb98094dff7ae3d695fcb47efd38e63e

  patch --forward --strip=1 --input=../steamos-btrfs-automount.patch
  patch --forward --strip=1 --input=../cachyos-automount.patch
  patch --forward --strip=1 --input=../udev-automount-rules.patch
  patch --forward --strip=1 --input=../priv-write.patch
  patch --forward --strip=1 --input=../cachyos-bios.patch
}

package() {
  rsync -a "$srcdir"/jupiter-hw-support/* "$pkgdir"

  cd $pkgdir/usr/share/holo
  xcursorgen $pkgdir/usr/share/holo/holo-cursor-config $pkgdir/usr/share/icons/steam/cursors/default

  cd "$pkgdir/usr/share/jupiter_bios_updater"

  # Remove gtk2 binary and respective build/start script - unused
  # Attempts to use gtk2 libraries which are not on the device.
  rm h2offt-g H2OFFTx64-G.sh

  # Driver module -- doesn't currently build, and not supported
  rm -rf driver
}
