From 1c179b8b08dfedc9b58f72db33116cd5e5bac66c Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Wed, 15 Mar 2023 17:32:08 -0400
Subject: linhes-system: add lh_restart_needed.sh

---
 linhes/linhes-system/PKGBUILD             |  5 +++--
 linhes/linhes-system/lh_restart_needed.sh | 35 +++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100755 linhes/linhes-system/lh_restart_needed.sh

diff --git a/linhes/linhes-system/PKGBUILD b/linhes/linhes-system/PKGBUILD
index 061412a..24220c0 100755
--- a/linhes/linhes-system/PKGBUILD
+++ b/linhes/linhes-system/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=linhes-system
 pkgver=9.0.0
-pkgrel=56
+pkgrel=57
 arch=('x86_64')
 #install=$pkgname.install
 pkgdesc="Everything that makes LinHES a system"
@@ -13,7 +13,7 @@ depends=('cronie' 'dbus-python' 'dvb-firmware' 'expect' 'flatpak' 'firefox' 'gla
 binfiles="add_storage.py balance_storage_groups.py empty_storage_groups.py remove_storage.py
           checkXFSfrag.sh enableIRWake.sh idle.py lh_system_start.sh lh_notify-send
           lh_home_check.sh lh_myth_status.py lh_system_backup lh_system_backup_job
-          jobqueue_helper.py gen_lib_xml.py lh_setup_fileshare.py
+          jobqueue_helper.py gen_lib_xml.py lh_setup_fileshare.py lh_restart_needed.sh
           diskspace.sh find_orphans.py optimize_mythdb.py lh_mtc.py
           misc_recent_recordings.pl misc_status_config.py misc_status_info.sh
           misc_upcoming_recordings.pl misc_which_recorder.pl plexmediascanner.sh
@@ -42,6 +42,7 @@ sha256sums=('525bfe29b63d3ec5a17a32fa29745e24070020490c3f5b6dd6b03250348fb324'
             '91bdec992bb2c933e15625c181f2195c402060b879168ebf35944cb064c904b9'
             '5cacfdd02833e5a3130d765573e772e6bd5030336ba86239c5e4db5ffa36fc69'
             'd51253c207d3315997d7122cb774c6d0fc38975c33e66bf416f0b1b95cf86e5b'
+            'a6c1118b1b3cf663a382caf817bc88e2e3c2d9d57dc17b1696bbb2b71baaa8b1'
             'ebdb3ee0212e0cc72526bb5e50a032573e1894acb7bf75617243b0b49aa1f8f2'
             'cd3306991c8b63f5402c0e52405cc1a6581cb3c42af74b7c2f879c8192f95610'
             'e371c6a289c68fe200d7da856c20a8c579efa23178f4d62235f7359d7f6e49a1'
diff --git a/linhes/linhes-system/lh_restart_needed.sh b/linhes/linhes-system/lh_restart_needed.sh
new file mode 100755
index 0000000..c939a28
--- /dev/null
+++ b/linhes/linhes-system/lh_restart_needed.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+get_boot_kernel() {
+    local get_version=0
+    for field in $(file /boot/vmlinuz*); do
+        if [[ $get_version -eq 1 ]]; then
+            echo $field
+            return
+        elif [[ $field == version ]]; then
+            # the next field contains the version
+            get_version=1
+        fi
+    done
+}
+
+rc=1
+
+libs=$(lsof -n +c 0 2> /dev/null | grep 'DEL.*lib' | awk '1 { print $1 ": " $NF }' | sort -u)
+if [[ -n $libs ]]; then
+    cat <<< $libs
+    echo "# LIBS: reboot required"
+    rc=0
+fi
+
+active_kernel=$(uname -r)
+current_kernel=$(get_boot_kernel)
+#echo $active_kernel
+#echo $current_kernel
+
+if [[ $active_kernel != $current_kernel ]]; then
+    echo "$active_kernel < $current_kernel"
+    echo "# KERNEL: reboot required"
+    rc=0
+fi
+exit $rc
-- 
cgit v0.12

