# 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;}' .*<\/userName>/$SCHEDULESDIRECT_USERNAME<\/userName>/" xtvd.xml sed -i "s/.*<\/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 }