diff options
Diffstat (limited to 'abs/core/tweaker/bin/twk_what_has_changed.sh')
-rwxr-xr-x | abs/core/tweaker/bin/twk_what_has_changed.sh | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/abs/core/tweaker/bin/twk_what_has_changed.sh b/abs/core/tweaker/bin/twk_what_has_changed.sh new file mode 100755 index 0000000..deff7cf --- /dev/null +++ b/abs/core/tweaker/bin/twk_what_has_changed.sh @@ -0,0 +1,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 + |