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
|
# This isn't to be run. Do not chmod it +x and try - it won't do anything.
# This function will change or create entries in various tables within
# the mythconverg database.
# If the key value already exists in $SQL_FILENAME, then it is changed. Otherwise,
# it will create the necessary SQL to make the entry if it does not exist.
#
# For the purposes of this function, a key is defined as any unique string of text
# after which a comma and a value or values follow. E.g.:
# in an entry like this:
# INSERT INTO `videotypes` VALUES (6,'mpeg','',0,1);
# we can define the key as "6" if we wanted, but that would be ambiguous. So we can instead
# define it as "6,'mpeg'" and we gain the ability to control the values of the fields after
# the first two. So this function call
#
# ChangeOrMakeEntry "6,'mpeg'" "'mplayer -fs -zoom', 0,1" "videotypes"
#
# would change the above SQL entry into this:
#
# INSERT INTO `videotypes` VALUES (6,'mpeg','mplayer -fs -zoom', 0,1);
# parameters: name, value, table
# Some tables have simple key, value pairs. Others have several potential keys and values.
# The 'settings' table is a simple key, value pair table, plus the name of the system on which
# the settings hold true, e.g.:
# INSERT INTO `settings` VALUES ('FooHat','Peas with sauce:drizzle','MythTVhost');
###
function ChangeOrMakeEntry {
NAME=$1 ; shift
VALUE=$1 ; shift
TABLE=$1 ; shift
if [ `grep -c "$NAME" $SQL_FILENAME` == 0 ]; then
# There is no setting for $SETTING_NAME, so we need to make it
echo "INSERT INTO \`$TABLE\`" VALUES \($NAME,$VALUE\)\; >> $SQL_FILENAME
else
# There is a setting for $SETTING_NAME, so make sure it's what we want it to be.
sed -i "s@$NAME,.*);@$NAME,$VALUE);@" $SQL_FILENAME
fi
}
# shortcut function to ChangeOrMakeEntry for 'settings' table
function ChangeOrMakeSetting {
NAME=$1 ; shift
VALUE=$1 ; shift
ChangeOrMakeEntry "$NAME" "$VALUE, 'MythTVhost'" "settings"
}
# shortcut function to ChangeOrMakeEntry for 'settings' table
function ChangeOrMakeKeybinding {
NAME=$1 ; shift
VALUE=$1 ; shift
ChangeOrMakeEntry "$NAME" "$VALUE, 'MythTVhost'" "keybindings"
}
# This only works for North America at the moment.
LocaleCode() { # no arguments. Obtain a zipcode or locale, either using
# SchedulesDirect subscription info or by asking the user.
mysqldump --tab=/tmp --opt mythconverg videosource
# Get the first data direct "Video Source"
dd_src=$(awk -F'\t' '$3 == "schedulesdirect1" {print $0; exit 0;}' </tmp/videosource.txt)
/bin/rm -f /tmp/videosource.txt
if [ -n "$dd_src" ]; then
# we have a chance at getting a usable locale from the schedulesdirect data
cd /usr/LH/
SCHEDULESDIRECT_USERNAME=$(echo "$dd_src" | cut -f4)
SCHEDULESDIRECT_PASSWORD=$(echo "$dd_src" | cut -f7)
sed -i "s/<userName>.*<\/userName>/<userName>$SCHEDULESDIRECT_USERNAME<\/userName>/" xtvd.xml
sed -i "s/<password>.*<\/password>/<password>$SCHEDULESDIRECT_PASSWORD<\/password>/" xtvd.xml
datadirect-parse.pl &> /dev/null
SQL_LocaleCode=`grep -i postalCode \`ls -1tr *xml | tail -1\` | perl -e '%zips=""; while(<>) { split(/postalCode=/); @_[1] =~ m/(\d{5})/; if ($1) { $zips{$1}=$1; } } @keys = keys %zips; if ($#keys == 1) { print values %zips,"\n"; }'`
if [ "$SQL_LocaleCode" == "" ]; then # zipcode was ambiguous or was not extractable
echo -e "\nPlease enter your US zipcode or Canadian Postal Code:"
read SQL_LocaleCode
fi
echo $SQL_LocaleCode > /tmp/locale.txt # remember this just long enough to make use of it in PostSQLTweaker.sh
fi
}
|