From 3c23b95df42b8ec226ab4110364cd69a50b48b2b Mon Sep 17 00:00:00 2001
From: Bob Igo <bob@stormlogic.com>
Date: Mon, 9 Feb 2009 21:49:15 -0500
Subject: Tweaker integration progress.

---
 abs/core-testing/tweaker/bin/LocalIPCheck.pl     | 47 ++++++++++++++++++++++++
 abs/core-testing/tweaker/bin/twk_EXAMPLE.pl      |  2 +-
 abs/core-testing/tweaker/bin/twk_RAM.pl          | 11 ++++--
 abs/core-testing/tweaker/bin/twk_audio.pl        | 16 +++++---
 abs/core-testing/tweaker/bin/twk_audio_RP.pl     |  2 +-
 abs/core-testing/tweaker/bin/twk_cpu.pl          |  2 +-
 abs/core-testing/tweaker/bin/twk_dragon.pl       |  2 +-
 abs/core-testing/tweaker/bin/twk_general.pl      |  2 +-
 abs/core-testing/tweaker/bin/twk_graphics.pl     |  2 +-
 abs/core-testing/tweaker/bin/twk_keymap.sh       | 17 ++++-----
 abs/core-testing/tweaker/bin/twk_linux.pl        |  2 +-
 abs/core-testing/tweaker/bin/twk_localization.pl |  2 +-
 abs/core-testing/tweaker/bin/twk_scrub_sql.pl    |  2 +-
 abs/core-testing/tweaker/bin/twk_tuners.pl       |  2 +-
 abs/core-testing/tweaker/bin/twk_upgrade.pl      |  4 +-
 abs/core-testing/tweaker/lib/Tweaker/Script.pm   |  4 +-
 16 files changed, 87 insertions(+), 32 deletions(-)
 create mode 100755 abs/core-testing/tweaker/bin/LocalIPCheck.pl

diff --git a/abs/core-testing/tweaker/bin/LocalIPCheck.pl b/abs/core-testing/tweaker/bin/LocalIPCheck.pl
new file mode 100755
index 0000000..b744fb6
--- /dev/null
+++ b/abs/core-testing/tweaker/bin/LocalIPCheck.pl
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+
+# Valid private IP ranges
+
+my @LOCAL_IP_RANGES = ("10.0.0.0", "10.255.255.255",
+		       "172.16.0.0", "172.31.255.255",
+		       "192.168.0.0", "192.168.255.255");
+
+# input: A dotted quad IP address.
+
+# output: 0 if a public (internet) address
+#       : 8 if a class A private (LAN) address
+#       : 12 if a class B private (LAN) address
+#       : 16 if a class C private (LAN) address
+
+sub get_IP_number () {
+    my ($dotted_quad) = @_;
+    my $IP_number=0;
+    
+    split(/\./, $dotted_quad);
+
+    for (my $i=0; $i < 4; $i++) {
+	$IP_number=$IP_number+@_[3-$i]*(2**(8*$i));
+    }
+    return $IP_number;
+}
+
+while(<>) {
+    chop;
+    my $IPnumber=&get_IP_number($_);
+    my $class=16;
+
+    while (@LOCAL_IP_RANGES) {
+	my $highIPnumber = &get_IP_number(pop(@LOCAL_IP_RANGES));
+	my $lowIPnumber = &get_IP_number(pop(@LOCAL_IP_RANGES));
+
+	if (($lowIPnumber <= $IPnumber) && ($highIPnumber >= $IPnumber)) {
+	    exit($class); # PRIVATE IP
+	} else {
+	    $class += 4;
+	}
+    }
+}
+
+exit(0); # PUBLIC IP
+
+
diff --git a/abs/core-testing/tweaker/bin/twk_EXAMPLE.pl b/abs/core-testing/tweaker/bin/twk_EXAMPLE.pl
index 4fc401a..7dfb075 100755
--- a/abs/core-testing/tweaker/bin/twk_EXAMPLE.pl
+++ b/abs/core-testing/tweaker/bin/twk_EXAMPLE.pl
@@ -11,7 +11,7 @@
 
 #!/usr/bin/perl -w
 
-# Copyright 2008 YOUR NAME HERE
+# Copyright 2009 YOUR NAME HERE
 #
 # 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
diff --git a/abs/core-testing/tweaker/bin/twk_RAM.pl b/abs/core-testing/tweaker/bin/twk_RAM.pl
index ead3e3c..79fe938 100755
--- a/abs/core-testing/tweaker/bin/twk_RAM.pl
+++ b/abs/core-testing/tweaker/bin/twk_RAM.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2007, 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
@@ -48,10 +48,13 @@ sub implement_option {
 	# We will arbitrarily set the cache size to 1/16 of available RAM
 	my $cachesize = int($RAM_size / 16);
 	execute_shell_command("sed -i 's/cache.*=.*/cache=$cachesize/g' /etc/mplayer/mplayer.conf") || exit -1;
+
+	# If there's enough RAM, make mtd run by default.
+	# ??? unimplemented
     } else {
-	exit -1; # You may not have to do this.  It's only when you need to change MySQL settings for MythTV.
-    } # You may not have to do this.  It's only when you need to change MySQL settings for MythTV.
-    disconnect_from_db(); # You may not have to do this.  It's only when you need to change MySQL settings for MythTV.
+	exit -1;
+    }
+    disconnect_from_db();
 }
 
 # Poll the system to see what recommendationlevel the given option has on the system.
diff --git a/abs/core-testing/tweaker/bin/twk_audio.pl b/abs/core-testing/tweaker/bin/twk_audio.pl
index 72b9c86..b3bdd89 100755
--- a/abs/core-testing/tweaker/bin/twk_audio.pl
+++ b/abs/core-testing/tweaker/bin/twk_audio.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2007, 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
@@ -30,11 +30,16 @@ sub poll_for_digital_output_device {
     my @digital_matches = ( "digital", "IEC958" );
     
     my $results = execute_shell_command($poll_command);
-    foreach my $digital_match (@digital_matches) {
-	if ($results =~ /card (\d):.*device (\d).*$digital_match.*/i) {
-	    $card = $1;
-	    $device = $2;
+    if ($results) {
+	foreach my $digital_match (@digital_matches) {
+	    if ($results =~ /card (\d):.*device (\d).*$digital_match.*/i) {
+		$card = $1;
+		$device = $2;
+	    }
 	}
+    } else {
+	recommendation_level("not available", "No audio devices detected.");
+	exit(-1);
     }
     return ($card, $device);
 }
@@ -336,6 +341,7 @@ sub poll_options {
 	    }
 	}
 	case "analogsurround" {
+	    my ($card, $device) = poll_for_digital_output_device;
 	    recommendation_level("unsupported", "No configuration data exists yet for this option.");
 	}
 	case "digital" {
diff --git a/abs/core-testing/tweaker/bin/twk_audio_RP.pl b/abs/core-testing/tweaker/bin/twk_audio_RP.pl
index 2642fda..5b30bd8 100755
--- a/abs/core-testing/tweaker/bin/twk_audio_RP.pl
+++ b/abs/core-testing/tweaker/bin/twk_audio_RP.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2007, 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
diff --git a/abs/core-testing/tweaker/bin/twk_cpu.pl b/abs/core-testing/tweaker/bin/twk_cpu.pl
index 04a57cc..c6d87ab 100755
--- a/abs/core-testing/tweaker/bin/twk_cpu.pl
+++ b/abs/core-testing/tweaker/bin/twk_cpu.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2007, 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
diff --git a/abs/core-testing/tweaker/bin/twk_dragon.pl b/abs/core-testing/tweaker/bin/twk_dragon.pl
index 8bfccca..f5ad5b7 100755
--- a/abs/core-testing/tweaker/bin/twk_dragon.pl
+++ b/abs/core-testing/tweaker/bin/twk_dragon.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2008-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
diff --git a/abs/core-testing/tweaker/bin/twk_general.pl b/abs/core-testing/tweaker/bin/twk_general.pl
index 86da85d..9b01480 100755
--- a/abs/core-testing/tweaker/bin/twk_general.pl
+++ b/abs/core-testing/tweaker/bin/twk_general.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2007, 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
diff --git a/abs/core-testing/tweaker/bin/twk_graphics.pl b/abs/core-testing/tweaker/bin/twk_graphics.pl
index b2fdb17..4fb6d77 100755
--- a/abs/core-testing/tweaker/bin/twk_graphics.pl
+++ b/abs/core-testing/tweaker/bin/twk_graphics.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2007, 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
diff --git a/abs/core-testing/tweaker/bin/twk_keymap.sh b/abs/core-testing/tweaker/bin/twk_keymap.sh
index 41341bf..885594d 100755
--- a/abs/core-testing/tweaker/bin/twk_keymap.sh
+++ b/abs/core-testing/tweaker/bin/twk_keymap.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-# Copyright 2007, 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
@@ -60,15 +60,14 @@ chown -fR mythtv:mythtv $MYTH_HOME/.xine
 
 #Make mplayer use keymappings that get along with xine, MythMusic, and ATI remote button mappings.
 #NOTE: PGUP is PageUp and PGDWN is PageDown
-if [[ -f $MYTH_HOME/.mplayer/input.conf ]]; then
-    sed -i "s/^PGUP .*/PGUP seek -60/" $MYTH_HOME/.mplayer/input.conf
-    sed -i "s/^PGDWN .*/PGDWN seek +60/" $MYTH_HOME/.mplayer/input.conf
-    sed -i "s/^p .*/p pause/" $MYTH_HOME/.mplayer/input.conf
-    sed -i "s/^l .*/l pause/" $MYTH_HOME/.mplayer/input.conf
+if [[ -f /etc/mplayer/input.conf ]]; then
+    sed -i "s/^PGUP .*/PGUP seek -60/" /etc/mplayer/input.conf
+    sed -i "s/^PGDWN .*/PGDWN seek +60/" /etc/mplayer/input.conf
+    sed -i "s/^p .*/p pause/" /etc/mplayer/input.conf
+    sed -i "s/^l .*/l pause/" /etc/mplayer/input.conf
 else
-    mkdir -p $MYTH_HOME/.mplayer/
-    /bin/cp $KNOPPMYTH_SHARE/mplayer_keymap $MYTH_HOME/.mplayer/input.conf
+    echo "ERROR: /etc/mplayer/input.conf is missing, which is unexpected."
+    exit -1
 fi
-chown -fR mythtv:mythtv $MYTH_HOME/.mplayer
 
 echo "Tweaked keymap"
\ No newline at end of file
diff --git a/abs/core-testing/tweaker/bin/twk_linux.pl b/abs/core-testing/tweaker/bin/twk_linux.pl
index 107b4d9..f8b46fb 100755
--- a/abs/core-testing/tweaker/bin/twk_linux.pl
+++ b/abs/core-testing/tweaker/bin/twk_linux.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2007, 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
diff --git a/abs/core-testing/tweaker/bin/twk_localization.pl b/abs/core-testing/tweaker/bin/twk_localization.pl
index f517ff4..572ee06 100755
--- a/abs/core-testing/tweaker/bin/twk_localization.pl
+++ b/abs/core-testing/tweaker/bin/twk_localization.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2007, 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
diff --git a/abs/core-testing/tweaker/bin/twk_scrub_sql.pl b/abs/core-testing/tweaker/bin/twk_scrub_sql.pl
index 2012d4d..c1de20b 100755
--- a/abs/core-testing/tweaker/bin/twk_scrub_sql.pl
+++ b/abs/core-testing/tweaker/bin/twk_scrub_sql.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2008-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
diff --git a/abs/core-testing/tweaker/bin/twk_tuners.pl b/abs/core-testing/tweaker/bin/twk_tuners.pl
index ab7f029..0b2b88c 100755
--- a/abs/core-testing/tweaker/bin/twk_tuners.pl
+++ b/abs/core-testing/tweaker/bin/twk_tuners.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2008-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
diff --git a/abs/core-testing/tweaker/bin/twk_upgrade.pl b/abs/core-testing/tweaker/bin/twk_upgrade.pl
index 479a675..b5d09b6 100755
--- a/abs/core-testing/tweaker/bin/twk_upgrade.pl
+++ b/abs/core-testing/tweaker/bin/twk_upgrade.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright 2007, 2008 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
+# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
 #
 # 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
@@ -159,7 +159,7 @@ sub implement_option {
 	# Customize default MythTV library.xml to reflect KnoppMyth's wider selection of
 	# online stream options.
 	#$command = "sed -i \"/<type>STREAM<\\/type>\$/{N; N; N; N; s/text>.*<\\/text/text>Online Streams<\\/text/; s/action>.*<\\/action/action>MENU is.xml<\\/action/; s/<depends.*depends>//; }\" /usr/share/mythtv/library.xml";
-	$command = "/bin/cp /usr/share/mythtv/library.xml.km /usr/share/mythtv/library.xml"
+	$command = "/bin/cp /usr/share/mythtv/library.xml.km /usr/share/mythtv/library.xml";
 	execute_shell_command($command);
 	
     } else {
diff --git a/abs/core-testing/tweaker/lib/Tweaker/Script.pm b/abs/core-testing/tweaker/lib/Tweaker/Script.pm
index ec3a42a..7dd2c8f 100644
--- a/abs/core-testing/tweaker/lib/Tweaker/Script.pm
+++ b/abs/core-testing/tweaker/lib/Tweaker/Script.pm
@@ -80,7 +80,7 @@ sub get_mythtv_connection_string {
     # we want something like mythconverg:localhost
     my $dbname = "";
     my $dbhostname = "";
-    open(MYSQLTXT, "< /home/mythtv/.mythtv/mysql.txt");
+    open(MYSQLTXT, "< /usr/share/mythtv/mysql.txt");
     while(<MYSQLTXT>) {
 	if (/DBName=(.*)/) {
 	    $dbname=$1;
@@ -98,7 +98,7 @@ sub get_mythtv_authentication {
     my $dbusername = "";
     my $dbpassword = "";
 
-    open(MYSQLTXT, "< /home/mythtv/.mythtv/mysql.txt");
+    open(MYSQLTXT, "< /usr/share/mythtv/mysql.txt");
     while(<MYSQLTXT>) {
 	if (/DBUserName=(.*)/) {
 	    $dbusername=$1;
-- 
cgit v0.12