summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/linhes_update.sh
blob: d563504304a8089b00ebf0b7cea71798902e10ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/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\        <!--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"
        else
            restart_mfe
        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
		grep -v -e /mythmenu /tmp/linhes.xml > /tmp/linhes.xml.tmp
		echo "<!--#UpdatesAvailable-->" >> /tmp/linhes.xml.tmp
		echo "   <button>" >> /tmp/linhes.xml.tmp
		echo "     <type>UPGRADE</type>" >> /tmp/linhes.xml.tmp
		echo "     <text>Updates Available</text>" >> /tmp/linhes.xml.tmp
		echo "     <description>Updates for the LinHES system</description>" >> /tmp/linhes.xml.tmp
		echo "     <action>MENU update2.xml</action>" >> /tmp/linhes.xml.tmp
		echo "   </button>" >> /tmp/linhes.xml.tmp
		echo "<!--#UpdatesAvailable-->" >> /tmp/linhes.xml.tmp
		echo "</mythmenu>" >> /tmp/linhes.xml.tmp
		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
            echo "" >> /tmp/update3.xml.tmp
            echo "   <button>" >> /tmp/update3.xml.tmp
            echo "     <type>UPGRADE</type>" >> /tmp/update3.xml.tmp
            echo "     <text>REBOOT REQUIRED</text>" >> /tmp/update3.xml.tmp
            echo "     <description>Some packages require a reboot</description>" >> /tmp/update3.xml.tmp
            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
            echo "   <button>" >> /tmp/update3.xml.tmp
            echo "     <type>UPGRADE</type>" >> /tmp/update3.xml.tmp
            echo "     <text>$line</text>" >> /tmp/update3.xml.tmp
            echo "     <description>$line</description>" >> /tmp/update3.xml.tmp
            echo "     <action>NONE</action>" >> /tmp/update3.xml.tmp
            echo "   </button>" >> /tmp/update3.xml.tmp
        done < "/tmp/to_be_upgraded"
        echo "</mythmenu>" >> /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\        <!--LinHES UPDATE MESSAGE-->' /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