#!/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
}
restart_mfe () {
#check if started from mythfrontend-start and if so just kill mfe
#otherwise reload mfe
if [[ `pgrep -fx "/bin/bash /usr/LH/bin/mythfrontend-start"` ]]
then
killall mythfrontend
else
pkill -USR1 mythfrontend
fi
}
dsply () {
if grep -q "Updates Available" /usr/share/mythtv/themes/defaultmenu/linhes.xml
then
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"
else
restart_mfe
fi
echo " Updates available!"
exit
else
[ "$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
#hide LinHES update message on main menu
echo " Hiding update message in LinHES theme."
sudo sed -i '/LinHES UPDATE MESSAGE/c\ " >> /tmp/linhes.xml.tmp
echo " " >> /tmp/linhes.xml.tmp
echo "" >> /tmp/linhes.xml.tmp
echo "" >> /tmp/linhes.xml.tmp
mv /tmp/linhes.xml.tmp /usr/share/mythtv/themes/defaultmenu/linhes.xml
echo "" > /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
echo "" >> /tmp/update3.xml.tmp
echo " " >> /tmp/update3.xml.tmp
fi
#create menu items for each pkg to be upgraded
while read line; do
echo "" >> /tmp/update3.xml.tmp
echo " " >> /tmp/update3.xml.tmp
done < "/tmp/to_be_upgraded"
echo "" >> /tmp/update3.xml.tmp
mv /tmp/update3.xml.tmp /usr/share/mythtv/themes/defaultmenu/update3.xml
#show LinHES update message on main menu
echo " Showing update message in LinHES theme."
sudo sed -i '/LinHES UPDATE MESSAGE/c\ ' /usr/share/mythtv/themes/LinHES/menu-ui.xml
dsply $1
fi
}
# 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