From dabf7e200b288c38b99f46fcb175e50754ad093a Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Thu, 10 Nov 2022 16:56:57 -0500
Subject: plex-htpc: update to 1.28.1

---
 linhes/plex-htpc/PKGBUILD  | 59 ++++++++++++++++++++++++++++++++++++++++++++++
 linhes/plex-htpc/qt.conf   |  4 ++++
 linhes/plex-htpc/update.sh | 42 +++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+)
 create mode 100644 linhes/plex-htpc/PKGBUILD
 create mode 100644 linhes/plex-htpc/qt.conf
 create mode 100755 linhes/plex-htpc/update.sh

diff --git a/linhes/plex-htpc/PKGBUILD b/linhes/plex-htpc/PKGBUILD
new file mode 100644
index 0000000..20e28bf
--- /dev/null
+++ b/linhes/plex-htpc/PKGBUILD
@@ -0,0 +1,59 @@
+# Maintainer: Ludvig Hozman <ludvig.hozman@gmail.com>
+
+pkgname=plex-htpc
+pkgver=1.28.1
+pkgrel=1
+_snapid=81OP06hEXlwmMrpMAhe5hyLy5bQ9q6Kz
+_snaprev=21
+pkgdesc="Plex HTPC application for linux"
+arch=('x86_64')
+url='http://plex.tv'
+license=('unknown')
+makedepends=('squashfs-tools')
+depends=('qt5-base' 'qt5-svg' 'qt5-webengine' 'qt5-quickcontrols' 'qt5-x11extras' 'mpv' 'ffmpeg4.4')
+optdepends=('qt5-wayland: Wayland support' 'libva: GPU accelerated decoding')
+source=("https://api.snapcraft.io/api/v1/snaps/download/${_snapid}_${_snaprev}.snap" "qt.conf")
+sha256sums=('14c8a317e62b63b3a8e20de76b802e4b1e8a6fdf1249297a3da45ad0df1cbe70'
+            '40d1b22236d9d2312d16563493b8c6d69134c5aa54ff6d1531243133fb46f083')
+
+prepare() {
+  unsquashfs -q -f -d "${srcdir}/${pkgname}" "${_snapid}_${_snaprev}.snap"
+}
+
+package() {
+  install -d "${pkgdir}/opt/${pkgname}"
+  cp -r "${srcdir}/${pkgname}/." "${pkgdir}/opt/${pkgname}"
+
+  sed -i 's|${SNAP}/meta/gui/icon.png|plex-htpc|g' "${pkgdir}/opt/${pkgname}/meta/gui/plex-htpc.desktop"
+
+  sed -e "/export LD_LIBRARY_PATH=/ c\export LD_LIBRARY_PATH=\"/usr/lib/${pkgname}:\$LD_LIBRARY_PATH\"" -i "${pkgdir}/opt/${pkgname}/Plex.sh"
+  sed -e '/export LC_ALL/ s/^#*/#/' -i "${pkgdir}/opt/${pkgname}/Plex.sh"
+  sed -e '/export QML/ s/^#*/#/' -i "${pkgdir}/opt/${pkgname}/Plex.sh"
+  sed -e '/export QT_/ s/^#*/#/' -i "${pkgdir}/opt/${pkgname}/Plex.sh"
+  sed -e '/export QTDIR/ s/^#*/#/' -i "${pkgdir}/opt/${pkgname}/Plex.sh"
+  sed -e '/export QT_QPA_PLATFORM/ i export FONTCONFIG_PATH="$BASE_DIR/etc/fonts"' -i "${pkgdir}/opt/${pkgname}/Plex.sh"
+  sed -e "/LIBVA_DRIVERS_PATH/c\export LIBVA_DRIVERS_PATH=/usr/lib/dri" -i "${pkgdir}/opt/${pkgname}/Plex.sh"
+
+  install -Dm644 "${pkgdir}/opt/${pkgname}/meta/gui/plex-htpc.desktop" -t "${pkgdir}/usr/share/applications"
+  install -Dm644 "${pkgdir}/opt/${pkgname}/meta/gui/icon.png" "${pkgdir}/usr/share/pixmaps/plex-htpc.png"
+  install -d "${pkgdir}/usr/lib/${pkgname}"
+  install -Dm644 "${pkgdir}/opt/${pkgname}/lib/libcec.so.4" -t "${pkgdir}/usr/lib/${pkgname}"
+  install -Dm644 "${pkgdir}/opt/${pkgname}/lib/libPlexMediaServer.so" -t "${pkgdir}/usr/lib/${pkgname}"
+  install -Dm644 "${pkgdir}/opt/${pkgname}/lib/libicudata.so.66" -t "${pkgdir}/usr/lib/${pkgname}"
+  install -Dm644 "${pkgdir}/opt/${pkgname}/lib/libicui18n.so.66" -t "${pkgdir}/usr/lib/${pkgname}"
+  install -Dm644 "${pkgdir}/opt/${pkgname}/lib/libicuuc.so.66" -t "${pkgdir}/usr/lib/${pkgname}"
+  install -Dm644 "${pkgdir}/opt/${pkgname}/lib/libavutil.so.56" -t "${pkgdir}/usr/lib/${pkgname}"
+  install -Dm644 "${pkgdir}/opt/${pkgname}/lib/libavformat.so.58" -t "${pkgdir}/usr/lib/${pkgname}"
+  ln -s "/usr/lib/libmpv.so" "${pkgdir}/usr/lib/${pkgname}/libmpv.so.2"
+
+  install -Dm644 "${srcdir}/${pkgname}/usr/lib/x86_64-linux-gnu/libvpx.so.6.2.0" "${pkgdir}/usr/lib/${pkgname}/libvpx.so.6"
+  install -Dm644 "${srcdir}/${pkgname}/usr/lib/x86_64-linux-gnu/libwebp.so.6.0.2" "${pkgdir}/usr/lib/${pkgname}/libwebp.so.6"
+  install -Dm644 "${srcdir}/${pkgname}/usr/lib/x86_64-linux-gnu/libre2.so.5.0.0" "${pkgdir}/usr/lib/${pkgname}/libre2.so.5"
+
+  rm -rf "$pkgdir/opt/$pkgname"/{lib,gnome-platform,meta,data-dir,snap,usr}
+
+  install -Dm644 "${srcdir}/qt.conf" -t "${pkgdir}/opt/${pkgname}/bin"
+
+  install -d "${pkgdir}/usr/bin"
+  ln -s "/opt/${pkgname}/Plex.sh" "${pkgdir}/usr/bin/plex-htpc"
+}
diff --git a/linhes/plex-htpc/qt.conf b/linhes/plex-htpc/qt.conf
new file mode 100644
index 0000000..9fa180b
--- /dev/null
+++ b/linhes/plex-htpc/qt.conf
@@ -0,0 +1,4 @@
+[Paths]
+Prefix = /usr/lib/qt
+Data = /usr/share/qt
+Translations = /usr/share/qt/translations
diff --git a/linhes/plex-htpc/update.sh b/linhes/plex-htpc/update.sh
new file mode 100755
index 0000000..ee9e98c
--- /dev/null
+++ b/linhes/plex-htpc/update.sh
@@ -0,0 +1,42 @@
+#!/bin/env bash
+set -eo pipefail
+
+PKGNAME=plex-htpc
+
+snap_res="$(curl "https://api.snapcraft.io/v2/snaps/info/${PKGNAME}" \
+  -H 'Snap-Device-Series: 16' -L)"
+
+snap_id="$(echo "$snap_res" | jq -r '."snap-id"')"
+stable_channel="$(echo "$snap_res" | jq -e '."channel-map"[] | select(.channel.name == "stable")')"
+
+new_revision="$(echo "$stable_channel" | jq -r '.revision')"
+new_version="$(echo "$stable_channel" | jq -r '.version')"
+new_sha384="$(echo "$stable_channel" | jq -r '.download."sha3-384"')"
+new_download="$(echo "$stable_channel" | jq -r '.download.url')"
+
+if [[ ! -f "${snap_id}_${new_revision}.snap" ]]; then
+  wget "$new_download"
+fi
+
+if [[ "$(sha384sum "${snap_id}_${new_revision}.snap" | cut -d' ' -f1)" != "$new_sha384" ]]; then
+  echo "SHA384 did NOT match"
+  #exit 1
+fi
+
+sed -i "s|^\(_snaprev=\).*|\\1$new_revision|g" PKGBUILD
+sed -i "s|^\(pkgver=\).*|\\1$new_version|g" PKGBUILD
+sed -i "s|^\(pkgrel=\).*|\\11|g" PKGBUILD
+
+updpkgsums
+makepkg --printsrcinfo >.SRCINFO
+git diff
+
+read -r -p "Continue (Y/n)?" choice
+case "$choice" in
+y | Y | "") echo "commiting..." ;;
+n | N) exit 1 ;;
+*) exit 1 ;;
+esac
+
+git add PKGBUILD .SRCINFO
+git commit -m "Update $PKGNAME to version $new_version"
-- 
cgit v0.12

