summaryrefslogtreecommitdiffstats
path: root/abs/core/tweaker/bin/create-linhes-sql.sh
blob: 478eed04ad557a163297343c75127fbccb774f28 (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
#!/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"
#