#!/bin/bash # Written by Bob Igo from the MythTV Store at http://MythiC.TV # Email: bob@stormlogic.com # # If you run into problems with this script, please send me email # PURPOSE: # -------------------------- # This script automates the creation of a new LinHES.sql based # on the contents of the current mythconverg database. if [ `whoami` != "root" ]; then echo "This script must be run as root." exit -1 fi # Every file we may create, edit, or delete ########################################### export LINHES_SQL_PROTOTYPE=/data/database/LinHES.sql-new export MYTHTV_SQL_OLD=/data/database/LinHES.sql-backup export TMPFILE=/tmp/LinHES.sql-tmp echo "" echo " ** ONLY CESMAN SHOULD EVER NEED TO RUN THIS SCRIPT **" echo "" echo " WARNING: This will archive your mythconverg database to a file," echo " then delete mythconverg from MySQL. It will then launch mythbackend" echo " to repopulate mythconverg, with a goal of creating the smallest-possible" echo " mythconverg database that MythTV can load without complanining." echo " Every attempt will be made to restore your original database, but" echo " ***no guarantee is made***." echo "" echo " ** ONLY CESMAN SHOULD EVER NEED TO RUN THIS SCRIPT **" echo "" echo -n "Proceed? [y|N] " read FEAR if [ "$FEAR" != "y" ] && [ "$FEAR" != "Y" ]; then echo "***NO OPERATION WILL BE PERFORMED***" exit fi # Archive the current mythconverg table from the MySQL database: echo "DROP DATABASE IF EXISTS mythconverg; CREATE DATABASE mythconverg; USE mythconverg;" > $MYTHTV_SQL_OLD mysqldump mythconverg >> $MYTHTV_SQL_OLD # delete the mythconverg database from MySQL killall mythbackend mysql -e "DROP DATABASE IF EXISTS mythconverg; CREATE DATABASE mythconverg;" mythtv-setup --geometry 640x480 2>&1 > /dev/null & echo "*" echo "* 1) PICK ANY LANGUAGE WHEN PROMPTED." echo "* 2) AGREE TO THE SCHEMA UPGRADE." echo "* 3) PRESS ENTER HERE WHEN THE MYTHTV-SETUP MENU LAUNCHES." echo "*" read KEYPRESS mysql -e "USE mythconverg; \ INSERT INTO settings VALUES ('SecurityPin','0000','"`hostname`"'); \ INSERT INTO settings VALUES ('BackendServerIP','127.0.0.1','"`hostname`"'); \ INSERT INTO storagegroup VALUES ('\N', 'Default','"`hostname`"','/');" echo "*" echo "* 1) EXIT MYTHTV-SETUP" echo "* 2) PRESS ENTER HERE WHEN READY TO CONTINUE." echo "*" read KEYPRESS # let mythbackend repopulate mythconverg from scratch mythbackend 2>&1 > /dev/null & sleep 3 mythfrontend --geometry 640x480 2>&1 > /dev/null & echo "*" echo "* 1) EXIT MYTHFRONTEND" echo "* 2) PRESS ENTER HERE WHEN READY TO CONTINUE." echo "*" read KEYPRESS killall mythfrontend killall mythbackend # save off the mostly-pristine MythTV myconverg database # (It would be 100% pristine, but mythbackend won't run unless BackendServerIP is given a value, # and both mythtv-setup and the mythfrontend won't proceed until you've picked a language.) # Edit the pristine MythTV mythconverg database so that we can use it to prime # the database during a semi-automated LinHES installation. SQL_FILENAME=$LINHES_SQL_PROTOTYPE # load our library functions . /usr/LH/tweaker/bin/SQLtweaker.sh # echo "*" echo "* Writing $LINHES_SQL_PROTOTYPE..." echo "*" # echo "/*" > $LINHES_SQL_PROTOTYPE echo " * MythTV raw SQL creation file." >> $LINHES_SQL_PROTOTYPE echo " */" >> $LINHES_SQL_PROTOTYPE echo "" >> $LINHES_SQL_PROTOTYPE echo "-- #################################################################### --" >> $LINHES_SQL_PROTOTYPE echo "-- Drop any initial database:" >> $LINHES_SQL_PROTOTYPE echo "DROP DATABASE IF EXISTS mythconverg;" >> $LINHES_SQL_PROTOTYPE echo "" >> $LINHES_SQL_PROTOTYPE echo "-- #################################################################### --" >> $LINHES_SQL_PROTOTYPE echo "-- Create an empty new database:" >> $LINHES_SQL_PROTOTYPE echo "CREATE DATABASE mythconverg;" >> $LINHES_SQL_PROTOTYPE echo "GRANT ALL ON mythconverg.* TO mythtv@localhost IDENTIFIED BY \"mythtv\";" >> $LINHES_SQL_PROTOTYPE echo "FLUSH PRIVILEGES;" >> $LINHES_SQL_PROTOTYPE echo "GRANT CREATE TEMPORARY TABLES ON mythconverg.* TO mythtv@localhost IDENTIFIED BY \"mythtv\";" >> $LINHES_SQL_PROTOTYPE echo "FLUSH PRIVILEGES;" >> $LINHES_SQL_PROTOTYPE echo "USE mythconverg;" >> $LINHES_SQL_PROTOTYPE echo "" >> $LINHES_SQL_PROTOTYPE echo "-- #################################################################### --" >> $LINHES_SQL_PROTOTYPE echo "-- Create all the tables:" >> $LINHES_SQL_PROTOTYPE echo "" >> $LINHES_SQL_PROTOTYPE # Dump the database, removing all unneeded DB inserts - when LinHES launches mythtv-setup and mythfrontend, # anything undefined will be given default values by the applications, except for the INSERTs below. mysqldump mythconverg | sed -e "s/`hostname`/MythTVhost'/g" -e "s/AUTO_INCREMENT=[0-9]* //g" > $TMPFILE grep -v "INSERT INTO" $TMPFILE >> $LINHES_SQL_PROTOTYPE sed "s/,(/,\n(/g" $TMPFILE | grep DBSchema | sed "s/\(.*\)NULL),/INSERT INTO settings VALUES \1'MythTVhost');/g" >> $LINHES_SQL_PROTOTYPE echo "INSERT INTO settings VALUES ('SecurityPin','0000','MythTVhost');" >> $LINHES_SQL_PROTOTYPE echo "INSERT INTO settings VALUES ('BackendServerIP','127.0.0.1','MythTVhost');" >> $LINHES_SQL_PROTOTYPE echo "INSERT INTO settings VALUES ('MasterServerIP','127.0.0.1','MythTVhost');" >> $LINHES_SQL_PROTOTYPE echo "INSERT INTO settings VALUES ('MasterServerPort','6543','MythTVhost');" >> $LINHES_SQL_PROTOTYPE echo "INSERT INTO settings VALUES ('Theme', 'LinHES','MythTVhost');" >> $LINHES_SQL_PROTOTYPE echo "INSERT INTO settings VALUES ('HostMyhostname', 'type_hostname_here','MythTVhost');" >> $LINHES_SQL_PROTOTYPE echo "INSERT INTO storagegroup VALUES ('\N', 'Default','MythTVhost','/');" >> $LINHES_SQL_PROTOTYPE rm $TMPFILE # echo "*" echo "...DONE" echo "*" # echo "*" echo "* PRESS ENTER HERE WHEN READY TO RESTORE THE OLD DATABASE" echo "* AND RE-LAUNCH MYTHBACKEND" echo "*" read KEYPRESS # echo "Restoring original database from $MYTHTV_SQL_OLD..." # # Restore the original mythconverg database cat $MYTHTV_SQL_OLD | mysql 2>&1 > /dev/null # echo "...DONE" # # echo "restarting mythbackend..." # mythbackend & # echo "...DONE" #