From 9557d32784b2affac3ea9fcf28a90df1c4d9f8bc Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Thu, 9 Jan 2025 00:58:30 -0500
Subject: linhes-system: add pacman_orphans.cron to remove orphaned pkgs

---
 linhes/linhes-system/PKGBUILD            | 68 ++++++++++++++++----------------
 linhes/linhes-system/pacman_orphans.cron |  1 +
 2 files changed, 36 insertions(+), 33 deletions(-)
 create mode 100755 linhes/linhes-system/pacman_orphans.cron

diff --git a/linhes/linhes-system/PKGBUILD b/linhes/linhes-system/PKGBUILD
index 2a7b96d..521303e 100755
--- a/linhes/linhes-system/PKGBUILD
+++ b/linhes/linhes-system/PKGBUILD
@@ -1,13 +1,13 @@
 pkgname=linhes-system
 pkgver=9.0.0
-pkgrel=87
+pkgrel=88
 arch=('x86_64')
 #install=$pkgname.install
 pkgdesc="Everything that makes LinHES a system"
 license=('GPL2')
 depends=('cronie' 'dbus-python' 'dvb-firmware' 'expect' 'flatpak' 'firefox' 'glances' 'inetutils' 
          'kdialog' 'kwalletmanager' 'libnotify'
-         'logrotate' 'linhes-templates' 'linhes-theme' 'mlocate' 'ncdu' 'python-dateutil' 'python-pytz'
+         'logrotate' 'linhes-templates' 'linhes-theme' 'mlocate' 'moreutils' 'ncdu' 'python-dateutil' 'python-pytz'
          'python-tzlocal' 'openssh' 'pacman-contrib' 'rsyslog' 'ttf-overlock' 'wget' 'x11vnc'
          'intel-media-driver' 'libva-intel-driver' 'pigz')
 binfiles="add_storage.py balance_storage_groups.py empty_storage_groups.py remove_storage.py
@@ -20,7 +20,7 @@ binfiles="add_storage.py balance_storage_groups.py empty_storage_groups.py remov
           create_media_dirs.sh be_check.py
           myth2mkv myth2mp3 myth2videos udev_link.sh"
 source=($binfiles
-    'lh_mtc.cron' 'paccache.cron' 'flatpak_update.cron' 'xfs_defrag.cron'
+    'lh_mtc.cron' 'paccache.cron' 'flatpak_update.cron' 'xfs_defrag.cron' 'pacman_orphans.cron'
     'readme_is_xml' 'add_storage.readme' 'LinHES-release' 'lh_log_care.cron'
     '79-cronie.hook' 'fstrim.hook' 'openssh.hook' 'plex_lib.conf' 'rsyslog.hook'
     '10-monitor.conf' '81-wol.rules' 'x11vnc.override.conf' 'lh_lighttpd.conf' 'lh_php.ini'
@@ -64,6 +64,7 @@ sha256sums=('e6eaa2fb4819fa60cb05b4d2e7328d2914af3a73028a735ec4d56e7ece33ecc0'
             '186203d3c0520bb3d611da99d33a7713e9c1563814285f1f101097234f214b2f'
             'd8d36a501928d0cc505957d392291fad317b1e895ff99847d90643cf5f622a89'
             'cdfc0c836b8194f631f4a9e022c232ff75a13ff1a161a1a011858578bea5f930'
+            'e74baee39a8072798a534cab2e794931c42ef6898e489ec4be78c076f04bf7e0'
             '5f502b1bc8815d69c802320790745e4526d5817fd8ecc7b00cf8b16078f8d440'
             '12e424432bdf2d50afe3e632c018fef847e860a35a53525eccbe656b9c4118aa'
             'ee745056d018f860572f8363ed5e730ba501394c23cdd6f316719d7141c10050'
@@ -88,12 +89,12 @@ sha256sums=('e6eaa2fb4819fa60cb05b4d2e7328d2914af3a73028a735ec4d56e7ece33ecc0'
             '2b91f6eb8c010a0dce1f41149c0549d067915fba93251c7af7e5328a05977f0c')
 
 package() {
-    cd $srcdir
+    cd ${srcdir}
 
-    install -m755 -D linhes-profile.sh $pkgdir/etc/profile.d/linhes-profile.sh
+    install -m755 -D linhes-profile.sh ${pkgdir}/etc/profile.d/linhes-profile.sh
 
     #bin files
-    BINDIR=$pkgdir/usr/bin
+    BINDIR=${pkgdir}/usr/bin
     for i in $binfiles
     do
         item=$i
@@ -102,60 +103,61 @@ package() {
     done
 
     #release files
-    install -Dm644 "$srcdir/LinHES-release" "$pkgdir/etc/LinHES-release"
+    install -Dm644 "${srcdir}/LinHES-release" "${pkgdir}/etc/LinHES-release"
 
     #startup files
-    install -Dm644 "$srcdir/lh_system_start.sh.desktop" "$pkgdir/etc/skel/.config/autostart/lh_system_start.sh.desktop"
+    install -Dm644 "${srcdir}/lh_system_start.sh.desktop" "${pkgdir}/etc/skel/.config/autostart/lh_system_start.sh.desktop"
 
     #systemd files
-    install -Dm644 $srcdir/x11vnc.override.conf $pkgdir/etc/systemd/system/x11vnc.service.d/override.conf
+    install -Dm644 ${srcdir}/x11vnc.override.conf ${pkgdir}/etc/systemd/system/x11vnc.service.d/override.conf
 
     #sql files
-    install -Dm644 $srcdir/lh_sqlserver.cnf $pkgdir/etc/my.cnf.d/lh_sqlserver.cnf
+    install -Dm644 ${srcdir}/lh_sqlserver.cnf ${pkgdir}/etc/my.cnf.d/lh_sqlserver.cnf
 
     #php files
-    install -Dm644 $srcdir/lh_php.ini $pkgdir/etc/php/conf.d/lh_php.ini
+    install -Dm644 ${srcdir}/lh_php.ini ${pkgdir}/etc/php/conf.d/lh_php.ini
 
     #lighttpd files
-    install -Dm644 $srcdir/lh_lighttpd.conf $pkgdir/etc/lighttpd/conf.d/lh_lighttpd.conf
+    install -Dm644 ${srcdir}/lh_lighttpd.conf ${pkgdir}/etc/lighttpd/conf.d/lh_lighttpd.conf
 
     #gen_lib_xml.py files
     install -Dm644 ${srcdir}/plex_lib.conf ${pkgdir}/etc/gen_lib_xml.d/plex_lib.conf
 
     #rsyslog files
-    install -Dm644 $srcdir/rsyslog.mythtv.conf $pkgdir/etc/rsyslog.d/mythtv.conf
+    install -Dm644 ${srcdir}/rsyslog.mythtv.conf ${pkgdir}/etc/rsyslog.d/mythtv.conf
 
     #remote files
-    install -Dm644 $srcdir/rc6_mce.toml $pkgdir/etc/rc_keymaps/rc6_mce.toml
+    install -Dm644 ${srcdir}/rc6_mce.toml ${pkgdir}/etc/rc_keymaps/rc6_mce.toml
 
     #readme files
-    install -Dm644 $srcdir/readme_is_xml $pkgdir/etc/gen_is_xml.d/readme_is_xml
-    install -Dm644 $srcdir/readme_is_xml $pkgdir/etc/gen_lib_xml.d/readme_gen_xml
-    install -Dm644 $srcdir/readme_is_xml $pkgdir/etc/gen_game_xml.d/readme_gen_xml
-    install -Dm644 $srcdir/add_storage.readme $pkgdir/etc/storage.d/readme
+    install -Dm644 ${srcdir}/readme_is_xml ${pkgdir}/etc/gen_is_xml.d/readme_is_xml
+    install -Dm644 ${srcdir}/readme_is_xml ${pkgdir}/etc/gen_lib_xml.d/readme_gen_xml
+    install -Dm644 ${srcdir}/readme_is_xml ${pkgdir}/etc/gen_game_xml.d/readme_gen_xml
+    install -Dm644 ${srcdir}/add_storage.readme ${pkgdir}/etc/storage.d/readme
 
     #cron files
-    install -Dm755 $srcdir/paccache.cron $pkgdir/etc/cron.weekly/paccache
-    install -Dm755 $srcdir/xfs_defrag.cron $pkgdir/etc/cron.weekly/xfs_defrag
-    install -Dm755 $srcdir/lh_mtc.cron $pkgdir/etc/cron.hourly/lh_mtc
-    install -Dm755 $srcdir/flatpak_update.cron $pkgdir/etc/cron.daily/flatpak_update
-    install -Dm755 $srcdir/lh_log_care.cron $pkgdir/etc/cron.daily/lh_log_care
-    install -Dm755 $srcdir/recordings.cron $pkgdir/etc/cron.hourly/recordings
+    install -Dm755 ${srcdir}/paccache.cron ${pkgdir}/etc/cron.weekly/paccache
+    install -Dm755 ${srcdir}/pacman_orphans.cron ${pkgdir}/etc/cron.weekly/pacman_orphans
+    install -Dm755 ${srcdir}/xfs_defrag.cron ${pkgdir}/etc/cron.weekly/xfs_defrag
+    install -Dm755 ${srcdir}/lh_mtc.cron ${pkgdir}/etc/cron.hourly/lh_mtc
+    install -Dm755 ${srcdir}/flatpak_update.cron ${pkgdir}/etc/cron.daily/flatpak_update
+    install -Dm755 ${srcdir}/lh_log_care.cron ${pkgdir}/etc/cron.daily/lh_log_care
+    install -Dm755 ${srcdir}/recordings.cron ${pkgdir}/etc/cron.hourly/recordings
 
     #hooks
-	install -Dm0644 $srcdir/79-cronie.hook "${pkgdir}"/usr/share/libalpm/hooks/79-cronie.hook
-	install -Dm0644 $srcdir/fstrim.hook "${pkgdir}"/usr/share/libalpm/hooks/fstrim.hook
-	install -Dm0644 $srcdir/openssh.hook "${pkgdir}"/usr/share/libalpm/hooks/openssh.hook
-	install -Dm0644 $srcdir/lh_restart_needed.hook "${pkgdir}"/usr/share/libalpm/hooks/lh_restart_needed.hook
-	install -Dm0644 $srcdir/rsyslog.hook "${pkgdir}"/usr/share/libalpm/hooks/rsyslog.hook
+    install -Dm0644 ${srcdir}/79-cronie.hook "${pkgdir}"/usr/share/libalpm/hooks/79-cronie.hook
+    install -Dm0644 ${srcdir}/fstrim.hook "${pkgdir}"/usr/share/libalpm/hooks/fstrim.hook
+    install -Dm0644 ${srcdir}/openssh.hook "${pkgdir}"/usr/share/libalpm/hooks/openssh.hook
+    install -Dm0644 ${srcdir}/lh_restart_needed.hook "${pkgdir}"/usr/share/libalpm/hooks/lh_restart_needed.hook
+    install -Dm0644 ${srcdir}/rsyslog.hook "${pkgdir}"/usr/share/libalpm/hooks/rsyslog.hook
 
     #sudo rules
-    install -Dm0440 "$srcdir/system-sudo.rules" "$pkgdir/etc/sudoers.d/system_sudo"
-    chmod 750 $pkgdir/etc/sudoers.d/
+    install -Dm0440 "${srcdir}/system-sudo.rules" "${pkgdir}/etc/sudoers.d/system_sudo"
+    chmod 750 ${pkgdir}/etc/sudoers.d/
 
     #udev rules
-	install -Dm0644 "$srcdir/81-wol.rules" "$pkgdir/etc/udev/rules.d/81-wol.rules"
+    install -Dm0644 "${srcdir}/81-wol.rules" "${pkgdir}/etc/udev/rules.d/81-wol.rules"
 
     #disable dpms
-    install -Dm0644 "$srcdir/10-monitor.conf" "$pkgdir/etc/X11/xorg.conf.d/10-monitor.conf"
+    install -Dm0644 "${srcdir}/10-monitor.conf" "${pkgdir}/etc/X11/xorg.conf.d/10-monitor.conf"
 }
diff --git a/linhes/linhes-system/pacman_orphans.cron b/linhes/linhes-system/pacman_orphans.cron
new file mode 100755
index 0000000..e042c33
--- /dev/null
+++ b/linhes/linhes-system/pacman_orphans.cron
@@ -0,0 +1 @@
+pacman -Qdtq | ifne pacman -Rns
-- 
cgit v0.12

