From 003fe951e1d811a01d17fcbfff8d4491503833b3 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Tue, 22 Nov 2022 09:12:21 -0500
Subject: linhes-system: add diskspace.sh

linhes_system_start.sh: more adjustments
---
 linhes/linhes-system/PKGBUILD           |  7 ++--
 linhes/linhes-system/diskspace.sh       | 67 +++++++++++++++++++++++++++++++++
 linhes/linhes-system/lh_system_start.sh | 53 ++++++++++++++++++++++----
 3 files changed, 117 insertions(+), 10 deletions(-)
 create mode 100755 linhes/linhes-system/diskspace.sh

diff --git a/linhes/linhes-system/PKGBUILD b/linhes/linhes-system/PKGBUILD
index 9d6814b..ec03819 100755
--- a/linhes/linhes-system/PKGBUILD
+++ b/linhes/linhes-system/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=linhes-system
 pkgver=9.0.0
-pkgrel=2
+pkgrel=3
 arch=('x86_64')
 #install=$pkgname.install
 pkgdesc="Everything that makes LinHES a system"
@@ -8,7 +8,7 @@ license=('GPL2')
 depends=('cronie' 'libnotify' 'linhes-templates' 'pacman-contrib' 'openssh' 'ttf-overlock')
 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 jobqueue_helper.py
-          find_orphans.py
+          diskspace.sh find_orphans.py
           create_media_dirs.sh be_check.py
           myth2mkv myth2mp3"
 source=($binfiles
@@ -67,8 +67,9 @@ sha256sums=('96f67b5428debb7dac909893c56a7637bf6545c068732822981d4080125c53d9'
             '11168c9cd3b117decaab6bc665c183b4aab917cf0a976bce4c1b5e4686a27bc9'
             'ae34515e144830f424d3bd3f6b1b446892d62beed20bca6f0fb19b0bbb779f27'
             '23358a7bff4968eccd469613b81b1415c2ae0ebe77f14f74426697333e4d88d7'
-            '78a13fe09338b1cfe63e992cc71737b63acc1afaad7dc3b2996b03aa22c92f5b'
+            '3d75c92c19da1f21da751f6425d9403eae58a1f5f665b39d72e6d2ff0e9c5494'
             '91bdec992bb2c933e15625c181f2195c402060b879168ebf35944cb064c904b9'
+            'f046b10e9f8686a8f5d1a48220506c0e22cc3b630f787d9f5e6b9044a22e7b26'
             '76f023c0cde7fea269234f1b29c32b117b91769217d4b1b8a3922daceb25f9f8'
             'bffcc13e4b480f720feb2b3c781bc4247c63303250c3d885022c699573d45a33'
             '0254a21644473ba7953501a223f13b9b55d7ec290c80a567724ca1ac13e02e30'
diff --git a/linhes/linhes-system/diskspace.sh b/linhes/linhes-system/diskspace.sh
new file mode 100755
index 0000000..b48f59d
--- /dev/null
+++ b/linhes/linhes-system/diskspace.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+### Monitor free disk space
+# Display alert if the free percentage of space is >= $ALERT
+
+#
+# Static Config Variables
+#
+# free space percentage to trigger an alert
+ALERT=90
+
+#
+# Static Binary Paths
+#
+DF='/usr/bin/df'
+GREP='/usr/bin/grep'
+AWK='/usr/bin/awk'
+CUT='/usr/bin/cut'
+HOSTNAME='/usr/bin/hostname'
+DATE='/usr/bin/date'
+MSG_CLIENT='/usr/bin/notify-send'
+
+#
+# Static System Variables
+#
+THIS_HOST=`${HOSTNAME}`
+
+#
+# Check CLI Options
+#
+VERBOSE=false
+OSD=false
+for ARG in "$@" ; do
+        case $ARG in
+        "-v")
+                VERBOSE=true
+                ;;
+        "-osd")
+                OSD=true
+                ;;
+        esac
+done
+
+[ $VERBOSE = true ] && echo "Checking free disk space on ${THIS_HOST}"
+[ $VERBOSE = true ] && echo "Threshold for warning is ${ALERT}%"
+[ $VERBOSE = true ] && echo "------------------------------------------------------------------"
+
+# Dynamic Variables
+#DATE_STR=`${DATE} "+%d-%B-%y @ %H%Mhrs"`
+
+# Call df to find the used percentages. Grep for only local disks (not remote mounts like nfs or smb)
+# Pipe the output to awk to get the needed columns, then start a while loop to process each line.
+$DF -HPl | $GREP -E "^/dev/" | $AWK '{ print $5 " " $6 " " $1 }' | while read OUTPUT ; do
+    USED_PCENT=$(echo ${OUTPUT} | $AWK '{ print $1}' | $CUT -d'%' -f1  )    # Used space as a percentage
+    PARTITION=$(echo ${OUTPUT} | $AWK '{ print $2 }' )                      # Mount Point (eg, /home)
+    DEVICE=$(echo ${OUTPUT} | $AWK '{ print $3 }' )                         # Device (eg, /dev/sda1 or LABEL or UUID)
+    if [ $VERBOSE = true ] ; then
+        echo -e "${USED_PCENT}% used:\tDevice ${DEVICE} mounted to ${PARTITION}"
+    fi
+    if [ ${USED_PCENT} -ge $ALERT ]; then
+        echo "WARNING: Partition (${PARTITION}) on (${DEVICE}) is ${USED_PCENT}% full on ${THIS_HOST}"
+        if [ $OSD = true ] && { [ ${PARTITION} = / ] || [ ${PARTITION} = /home ] || [ ${PARTITION} = /data/srv/mysql ]; } then
+            $MSG_CLIENT "Disk Space WARNING" "Partition (${PARTITION}) on (${DEVICE}) is ${USED_PCENT}% full."
+        fi
+    fi
+done
+
+exit 0
diff --git a/linhes/linhes-system/lh_system_start.sh b/linhes/linhes-system/lh_system_start.sh
index 887edd8..6ba1cb0 100755
--- a/linhes/linhes-system/lh_system_start.sh
+++ b/linhes/linhes-system/lh_system_start.sh
@@ -8,22 +8,61 @@ function msg(){
 }
 
 function applyUIsettings(){
-    #plasma-apply-wallpaperimage /usr/share/linhes/templates/lights-bud-abstract-4k-cq.jpg
+    cp /usr/share/linhes/templates/plasma-org.kde.plasma.desktop-appletsrc ~/.config/
+    #restart plasma
+    kquitapp5 plasmashell
+    kstart5 plasmashell > /dev/null 2>&1
     plasma-apply-colorscheme BreezeDark
     kwriteconfig5 --group KDE --key SingleClick false
     kwriteconfig5 --file ~/.config/kscreenlockerrc --group Daemon --key Autolock false
     kwriteconfig5 --file ~/.config/kscreenlockerrc --group Daemon --key LockOnResume false
-    cp /usr/share/linhes/templates/plasma-org.kde.plasma.desktop-appletsrc ~/.config/
-    #restart plasma
-    kquitapp5 plasmashell
-    kstart5 plasmashell
     #disable file indexing
     balooctl disable
+    sleep 2
+    plasma-apply-wallpaperimage /usr/share/linhes/templates/lights-bud-abstract-4k-cq.jpg
+    msg "Welcome to LinHES 9!"
+}
+
+function make_nanorc(){
+    mkdir ~/.config/nano
+    echo -e 'set tabsize 4\nset tabstospaces\ninclude "/usr/share/nano/*.nanrc"' >> ~/.config/nano/nanorc
+}
+
+function notify_scan(){
+    if [ -e /tmp/scan_report ]
+    then
+        msg "New Storage Found" "Run add_storage.py for details."
+    fi
+}
+
+function first_configure(){
+    echo "First configure..."
+    if [ ! $SystemType = "Frontend_only" ]
+    then
+        if [ ! -f ~/.config/lh_configured ]
+        then
+            applyUIsettings
+            msg "New install of LinHES. Starting setup."
+            # only run mythfilldatabase for masterbackends
+            if [ $SystemType = "Master_backend" ]
+            then
+                #nice -n 19 mythfilldatabase --quiet &
+                msg "Guide data is being loaded." "Until this completes some shows will appear as unknown in the program guide."
+            fi
+            touch ~/.config/lh_configured
+        fi
+    else
+        if [ ! -f ~/.config/lh_configured ]
+        then
+            applyUIsettings
+            touch -f ~/.config/lh_configured
+        fi
+    fi
 }
 
 
 
 #-------MAIN-------
+first_configure
 /usr/bin/enableIRWake.sh &
-msg "Welcome to LinHES 9!"
-applyUIsettings
+notify_scan
-- 
cgit v0.12

