summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/tweaker/bin/twk_what_has_changed.sh
blob: deff7cf3489cbbae103bb8e26006233467351056 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash

# Copyright 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv
# and Tom Culliton of <affiliation>.  Most of restore_baseline_SQL taken from
# KnoppMyth R5F27's /usr/local/bin/KnoppMyth-run script (multiple authors)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


#----------------------------------------------------------------------------
. /usr/local/bin/backupcommon || {
    echo "Can not find common settings!"
    exit 1
}
#----------------------------------------------------------------------------

# Target output file for our results
DIFF_RESULTS=/tmp/database_changes.txt
LOGFILE=/var/log/twk_what_has_changed.log
WORKING_DIR=/tmp/

# Restore the SQL to the way it would have been after R5F27 was installed
# and before the user made any changes to MythTV settings.
# This is KnoppMyth-centric and does not apply to general MythTV distros,
# however it is possible to generalize this to apply to any MythTV distro
# including generic Linux distros in which MythTV has been installed.
#
# Preconditions: MySQL daemon is running
#
# Postconditions: 'mythconverg' is deleted and re-created, just as it
# would be during the course of a normal installation.
restore_baseline_SQL() {
    echo "restoring baseline SQL" >> $LOGFILE
    KRP_RESULT=-1
    KRPAutoDetect.pl &> /dev/null # be quiet
    KRP_RESULT=$?;

    # Parts from R5F27's KnoppMyth-run
    KNOPPMYTH_SQL_FILE="/usr/local/share/knoppmyth/KnoppMyth.sql"
    
    # Try to detect and configure settings for various tuner
    # and capture devices.
    /usr/local/bin/TunerConfig.sh $KNOPPMYTH_SQL_FILE >> /dev/null
    /usr/local/bin/ren_host.sh
    GlobalSQLtweaker.sh $KNOPPMYTH_SQL_FILE

    if [[ ($KRP_RESULT != 1) && ($KRP_RESULT != 2) && ($KRP_RESULT != 3) && ($KRP_RESULT != 10) && (-n "$IS_AUS") ]]; then # not Dragon
	/usr/local/bin/epia_sql.sh
    fi
    
    # General MythTV SQL settings for all boxes
    if [ -f "/usr/local/bin/MythTV-sql" ]; then
	# Interject platform-specific SQL settings before we populate the SQL
	# database.
	if [[ ($KRP_RESULT == 1) || ($KRP_RESULT == 2) || ($KRP_RESULT == 3) || ($KRP_RESULT == 10) ]]; then # Dragon
	    DragonSQLtweaker.sh $KNOPPMYTH_SQL_FILE
	fi
	# Now use the (possibly modified) KnoppMyth.sql to populate initial
	# MythTV settings.
	
	# This wipes out the current mythconverg and replaces it with what's in $KNOPPMYTH_SQL_FILE
	sh /usr/local/bin/MythTV-sql $KNOPPMYTH_SQL_FILE
    fi

    echo \
	"MythTV will re-launch in a tiny window.  If it asks you about
upgrading the schema, agree.  When the schema upgrade is complete,
exit MythTV.
You can exit MythTV immediately if you aren't asked to do a schema
upgrade."
    echo "###"
    echo "Press ENTER to re-launch MythTV."
    read CONTINUE;
    restart_mythtv "--geometry 640x480"
}

# Call mysql and only dump the requested data in tab seperated columns
get_data () {
    mysql mythconverg -u root -sNBe "$*"
}

# Compares $MYTHTV_EXPECTED_DB_NAME to $USERS_DB_NAME
compare_databases() {
    echo "comparing databases" >> $LOGFILE
    tables_to_compare="capturecard cardinput codecparams displayprofilegroups displayprofiles dtv_multiplex keybindings playgroups profilegroups recordingprofiles settings videotypes weatherdatalayout weatherscreens weathersourcesettings"
    hostnames=$(get_data "select distinct hostname from settings where hostname is not null") 

    /etc/init.d/mysql start >> $LOGFILE
    # Do some MySQL magic to compare $tables_to_compare between
    # $MYTHTV_EXPECTED_DB_NAME (baseline) and $USERS_DB_NAME (user's version)
    # ???
}

# This is somewhat KnoppMyth-centric, though minor modification would
# make it work generally.
function restart_mythtv {
    echo "restarting MythTV" >> $LOGFILE
    EXTRA_PARAMETERS=$1 ; shift
    /etc/init.d/mythtv-backend start >> $LOGFILE
    killall mythfrontend
    # re-launches the frontend and gives the user a chance to upgrade to latest schema
    su - mythtv -c "export DISPLAY=:0.0 ; mythfrontend --logfile /var/log/mythtv/mythfrontend.log $EXTRA_PARAMETERS" >> $LOGFILE
}

function rename_database {
    db_source=$1 ; shift
    db_target=$1 ; shift

    echo "renaming database $db_source to $db_target" >> $LOGFILE

    # Exit the frontend before messing with the SQL
    killall mythfrontend
    # If we stop MySQL before stopping the MythTV backend, we'll probably trigger badness
    /etc/init.d/mythtv-backend stop >> $LOGFILE
    # MySQL needs to stop before we do this.
    /etc/init.d/mysql stop >> $LOGFILE
    /bin/mv $db_source $db_target
}

main() {
    echo -n "$0 started running: " >> $LOGFILE
    date >> $LOGFILE

    echo "STEP 0..."
    echo "STEP 0" >> $LOGFILE
    # 0) acquire system settings
    MYTHTV_EXPECTED_DB_NAME=`grep DBName /etc/mythtv/mysql.txt | awk -F= '{ print $2 }'`
    USERS_DB_NAME="mythconverg-copy"
    /etc/init.d/mysql start >> $LOGFILE
    # MySQL needs to be running or mysqladmin won't return anything
    SQL_HOME=`mysqladmin variables | grep datadir | awk -F\| '{ print $3 }' | sed 's/ //g'`

    echo "STEP 1..."
    echo "STEP 1" >> $LOGFILE
    # 1) rename the current MythTV MySQL database
    rename_database $SQL_HOME$MYTHTV_EXPECTED_DB_NAME $WORKING_DIR$USERS_DB_NAME

    echo "STEP 2..."
    echo "STEP 2" >> $LOGFILE
    # 2) re-create the R5F27 baseline SQL.
    /etc/init.d/mysql start >> $LOGFILE
    restore_baseline_SQL

    echo "STEP 3..."
    echo "STEP 3" >> $LOGFILE
    # 3) compare the fresh baseline DB with the user's modified DB, and save the
    # diffs to a text file
    # ???

    echo "STEP 4..."
    echo "STEP 4" >> $LOGFILE
    # 4) restore the user's database
    rename_database $WORKING_DIR$USERS_DB_NAME $SQL_HOME$MYTHTV_EXPECTED_DB_NAME
    /etc/init.d/mysql start >> $LOGFILE

    echo "STEP 5..."
    echo "STEP 5" >> $LOGFILE
    # 5) Tell them the comparison is done, tell them where to find the results,
    # and prompt them to restart MythTV.
    echo "Your results are in $DIFF_RESULTS"
    echo "###"
    echo "Press ENTER to re-launch MythTV."
    read CONTINUE;

    restart_mythtv "&"
    echo "DONE"
    echo -n "$0 stopped running: " >> $LOGFILE
    date >> $LOGFILE
}

main