From b8f425e3dff10f18eb019157bbf553074e3fcc51 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Thu, 13 Feb 2014 21:18:16 +0000
Subject: LinHES-system: lh_system_host_update: add Notify option that calls
 linhes_update.sh. refs #959

linhes_update.sh: add -s option to silence OSD. Add sed to show and hide message in LH theme.

linhes_update2.sh: add sed to hide message in LH theme.
---
 abs/core/LinHES-system/PKGBUILD              | 10 ++---
 abs/core/LinHES-system/lh_system_host_update | 13 ++++--
 abs/core/LinHES-system/linhes_update.sh      | 67 ++++++++++++++++++++++------
 abs/core/LinHES-system/linhes_update2.sh     | 10 ++++-
 abs/core/LinHES-system/myth_mtc.py           |  1 +
 5 files changed, 77 insertions(+), 24 deletions(-)

diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD
index 387793b..82df8b0 100755
--- a/abs/core/LinHES-system/PKGBUILD
+++ b/abs/core/LinHES-system/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-system
 pkgver=8.1
-pkgrel=16
+pkgrel=17
 arch=('i686' 'x86_64')
 install=system.install
 pkgdesc="Everything that makes LinHES an automated system"
@@ -79,7 +79,7 @@ md5sums=('7ab2a2c643d2b286811d8303d08982ad'
          'de32a1c50101265dd7f6ca5037f7a26a'
          '301884fb60521627fffd1160b2cf5181'
          '76b2637cac0452b3acdbeeb4e8a5474b'
-         '6d473cfc5c8e2ffedbd894807824d56f'
+         '8dcdd10f5551a45d6e8681800fafe7e0'
          'dc3eef2a624754e16805d72bbe488b67'
          '617af86b901538817ebdcaf646248dc5'
          '542e670e78d117657f93141e9689f54d'
@@ -93,7 +93,7 @@ md5sums=('7ab2a2c643d2b286811d8303d08982ad'
          '3edef50a49a47694bf8add39cc160add'
          'b376c30f95892b8682fad84f81685f75'
          'bc69a520add58ede9b060c73e67ace13'
-         '2e5e1b3187f75154366bffe806ff8ae9'
+         '74e17d6f7453c52d56fecaed5c3f6ad5'
          '47e093e8cfe4b5b96602358e1f540832'
          '63bbc62240f46a9997eaae4a84b09b76'
          '2c005d95312018bef80092136f80f254'
@@ -121,8 +121,8 @@ md5sums=('7ab2a2c643d2b286811d8303d08982ad'
          '34fc1f58ad1eabf4eff4979d420760c0'
          '1118e7982ba77cb5be9b2391b7cdfd38'
          'a94fe6d980f4b810f2e2ae5352084b39'
-         '2c56266a79d058bf01f0de19c2cd042a'
-         'c27d3fdf59b211f9d3cd76a81f6257dc'
+         '24b18dd43b983748359f472ee70fe139'
+         '96b9e14b063e251fc3c2fe9f5b42a22e'
          '28f29578e5b3ba84fdf2aa57cf475bcf'
          '4a1fda884dcd7d65fb2690fbdbd92a83'
          '2b7fe3b57592823a4c7e3ec132dcb7f4'
diff --git a/abs/core/LinHES-system/lh_system_host_update b/abs/core/LinHES-system/lh_system_host_update
index ca6aeff..0a63e0a 100644
--- a/abs/core/LinHES-system/lh_system_host_update
+++ b/abs/core/LinHES-system/lh_system_host_update
@@ -37,17 +37,22 @@ case $Hostupdateplan in
                 		echo  "$pkg is up to date"
                 	fi
 	        done
-	;;
+        ;;
 	"All")
-		echo "" 
+		echo ""
 		echo "Updating ALL packages"
 		pacman -Sy
 		pacman --noconfirm -Su --force
-	;;
+        ;;
 	"None")
 		echo ""
 		echo "Updating NO packages"
-		;;
+        ;;
+    "Notify")
+        echo ""
+        echo "Notify if there are updates"
+        /usr/LH/bin/linhes_update.sh -s
+        ;;
     *)  echo ""
         echo "Unknown  $Hostupdateplan, skipping updates"
         ;;
diff --git a/abs/core/LinHES-system/linhes_update.sh b/abs/core/LinHES-system/linhes_update.sh
index afaf6d5..21dfb6c 100644
--- a/abs/core/LinHES-system/linhes_update.sh
+++ b/abs/core/LinHES-system/linhes_update.sh
@@ -1,27 +1,49 @@
 #!/bin/bash
 #Called from LinHES Service Menu Check for Updates Menu
 
+usage () {
+    echo "Usage: $0 [-h] [-s]"
+    echo
+    echo "-h - Print this help/usage message and quit"
+    echo "-s - Run silently, no OSD messages"
+    exit $1
+}
+
 dsply ()  {
-    if grep -q Updates\ Available /usr/share/mythtv/themes/defaultmenu/linhes.xml
+    if grep -q "Updates Available" /usr/share/mythtv/themes/defaultmenu/linhes.xml
     then
-        msg_client.py --clear --tag "checkUpdates"
-        msg_client.py --kill
-        msg_client.py --msg "Updates available!\nGo to the Service Menu to install the updates.|middle"
+        if [ "$1" = false ]; then
+            msg_client.py --clear --tag "checkUpdates"
+            msg_client.py --kill
+            msg_client.py --msg "Updates available!\nGo to the Service Menu to install the updates.|middle"
+        fi
+        echo "    Updates available!"
+        pkill -USR1 mythfrontend
 		exit
     else
-        msg_client.py --msg "Checking for updates...|middle" --timeout 600 --tag "checkUpdates"
+        [ "$1" = false ] && { msg_client.py --msg "Checking for updates...|middle" --timeout 600 --tag "checkUpdates"; }
+        echo "    Checking for updates..."
     fi
 }
 
 chck ()  {
 	sudo pacman -Sy
+    [ -f /tmp/to_be_upgraded ] && sudo rm /tmp/to_be_upgraded
 	sudo pacman -Qu > /tmp/to_be_upgraded
 	if [[ ! -s /tmp/to_be_upgraded ]]
 	then
-        msg_client.py --clear --tag "checkUpdates"
-        msg_client.py --kill
-		msg_client.py --msg "No updates available.\nReturning to Main Menu.|middle"
+        #hide LinHES update message on main menu
+        echo "    Hiding update message in LinHES theme."
+        sudo sed -i '/LinHES UPDATE MESSAGE/c\        <!--LinHES UPDATE MESSAGE' /usr/share/mythtv/themes/LinHES/menu-ui.xml
+
+        if [ "$1" = false ]; then
+            msg_client.py --clear --tag "checkUpdates"
+            msg_client.py --kill
+		    msg_client.py --msg "No updates available.\nReturning to Main Menu.|middle"
+        fi
+        echo "    No updates available."
 	else
+        echo "    Update menu to show Updates Available."
 		mv /usr/share/mythtv/themes/defaultmenu/linhes.xml /tmp/linhes.xml.tmp
 		sed -e '/\#Check/,/\#Check/d' < /tmp/linhes.xml.tmp > /usr/share/mythtv/themes/defaultmenu/linhes.xml
 		mv /usr/share/mythtv/themes/defaultmenu/linhes.xml /tmp
@@ -38,7 +60,7 @@ chck ()  {
 		mv /tmp/linhes.xml.tmp /usr/share/mythtv/themes/defaultmenu/linhes.xml
 
 		echo "<mythmenu name=\"LH_UPDATE\">" > /tmp/update3.xml.tmp
-		
+
         #check for kernel update and warn reboot is required
         if grep linux /tmp/to_be_upgraded || grep nvidia /tmp/to_be_upgraded
  		then
@@ -50,7 +72,7 @@ chck ()  {
             echo "     <action>NONE</action>" >> /tmp/update3.xml.tmp
             echo "   </button>" >> /tmp/update3.xml.tmp
 		fi
-        
+
         #create menu items for each pkg to be upgraded
 		while read line; do
             echo "" >> /tmp/update3.xml.tmp
@@ -63,9 +85,28 @@ chck ()  {
         done < "/tmp/to_be_upgraded"
         echo "</mythmenu>" >> /tmp/update3.xml.tmp
         mv /tmp/update3.xml.tmp /usr/share/mythtv/themes/defaultmenu/update3.xml
-  		dsply
+
+        #show LinHES update message on main menu
+        echo "    Showing update message in LinHES theme."
+        sudo sed -i '/LinHES UPDATE MESSAGE/c\        <!--LinHES UPDATE MESSAGE-->' /usr/share/mythtv/themes/LinHES/menu-ui.xml
+
+  		dsply $1
 	fi
 	}
 
-dsply
-chck
+# Command line argument handling
+SILENT=false
+while getopts "hs" OPT ; do
+    case $OPT in
+    h) usage 0 ;;
+    s) SILENT=true ;;
+    *) usage 1 ;;
+    esac
+done
+# Check for extra cruft on the command line...
+shift $(($OPTIND - 1))
+[ -n "$*" ] && usage 1
+
+dsply $SILENT
+chck $SILENT
+pkill -USR1 mythfrontend
diff --git a/abs/core/LinHES-system/linhes_update2.sh b/abs/core/LinHES-system/linhes_update2.sh
index 6087729..d1913d0 100644
--- a/abs/core/LinHES-system/linhes_update2.sh
+++ b/abs/core/LinHES-system/linhes_update2.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-
+#Called from LinHES Service Menu Updates Available Menu
 
 if [[ "$1" = "install" ]]
 then
@@ -16,7 +16,7 @@ else
     msg_client.py --msg "Updates canceled.|middle"
 fi
 
-rm -fr /tmp/to_be_upgraded
+sudo rm -fr /tmp/to_be_upgraded
 
 if grep -q Updates\ Available /usr/share/mythtv/themes/defaultmenu/linhes.xml
 then
@@ -36,3 +36,9 @@ then
 	echo "</mythmenu>" >> /tmp/linhes.xml.tmp
 	mv /tmp/linhes.xml.tmp /usr/share/mythtv/themes/defaultmenu/linhes.xml
 fi
+
+#hide LinHES update message on main menu
+sudo sed -i '/LinHES UPDATE MESSAGE/c\        <!--LinHES UPDATE MESSAGE' /usr/share/mythtv/themes/LinHES/menu-ui.xml
+
+#reload theme
+pkill -USR1 mythfrontend
diff --git a/abs/core/LinHES-system/myth_mtc.py b/abs/core/LinHES-system/myth_mtc.py
index c33a888..db6b42a 100755
--- a/abs/core/LinHES-system/myth_mtc.py
+++ b/abs/core/LinHES-system/myth_mtc.py
@@ -6,6 +6,7 @@ import socket
 import os
 import datetime,time
 import shlex
+sys.dont_write_bytecode = True
 import idle
 
 try:
-- 
cgit v0.12

