Package: laptop-detect
Version: 0.12.1
Severity: wishlist
Tags: patch

Please include a commandline option that enables verbose output. I
implemented this (patch attached). While at it, I also included options
to print a usage message and version information on the script. (The
latter also required some minor changes to debian/rules)

Regards,
Sven

-- System Information:
Debian Release: 3.1
  APT prefers stable
  APT policy: (990, 'stable'), (400, 'experimental'), (90, 'testing'), (50, 
'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.11.12-incase
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
diff -urN laptop-detect-0.12.1.simplified/debian/changelog 
laptop-detect-0.12.1.allow-verbose/debian/changelog
--- laptop-detect-0.12.1.simplified/debian/changelog    2005-06-14 
12:38:52.000000000 +0200
+++ laptop-detect-0.12.1.allow-verbose/debian/changelog 2006-08-09 
03:11:19.741555562 +0200
@@ -1,3 +1,9 @@
+laptop-detect (0.12.2) unstable; urgency=low
+
+  * add patches to allow for verbosity and simplier dmidecode test 
+
+ -- Sven Mueller <[EMAIL PROTECTED]>  Wed,  9 Aug 2006 03:10:51 +0200
+
 laptop-detect (0.12.1) unstable; urgency=low
 
   * First upload to Debian. Add Otavio Salvador as an Uploader.
diff -urN laptop-detect-0.12.1.simplified/debian/rules 
laptop-detect-0.12.1.allow-verbose/debian/rules
--- laptop-detect-0.12.1.simplified/debian/rules        2006-08-09 
02:43:43.230298032 +0200
+++ laptop-detect-0.12.1.allow-verbose/debian/rules     2006-08-09 
03:06:30.257832114 +0200
@@ -22,10 +22,16 @@
 clean:
        dh_testdir
        dh_clean
+       -rm -f build-stamp laptop-detect.sh
 
-build:
+build: build-stamp
 
-install:
+build-stamp: laptop-detect.sh
+
+laptop-detect.sh: laptop-detect.sh.in
+       sed -e "s/@VERSION@/${VERSION}/g" < $< > $@
+
+install: build-stamp
        dh_testdir
        dh_testroot
        dh_clean -k
diff -urN laptop-detect-0.12.1.simplified/laptop-detect.sh 
laptop-detect-0.12.1.allow-verbose/laptop-detect.sh
--- laptop-detect-0.12.1.simplified/laptop-detect.sh    2006-08-09 
02:41:42.049122461 +0200
+++ laptop-detect-0.12.1.allow-verbose/laptop-detect.sh 2006-08-09 
03:13:49.665908487 +0200
@@ -1,10 +1,48 @@
 #!/bin/sh -e
 
+usage () {
+       echo "Usage: $0 [-h|--help|-v|--verbose]"
+       echo ""
+       echo "  -h | --help      print this help"
+       echo "  -v | --verbose   be verbose (messages go to STDOUT)"
+       echo "  -V | --version   print version information"
+       echo ""
+       echo " Possible return values:"
+       echo "  0  most likely running on a laptop"
+       echo "  1  most likely NOT running on a laptop"
+       echo "  2  called with unknown option, -h, --help, -V or --version"
+}
+
+PRINTIT="/bin/true" # /bin/true accepts any option but never prints anything
+
+# Check wether we were asked to be verbose
+
+if [ "$1" != "" ]; then
+       case "$1" in
+               "-v"|"--verbose")
+                       PRINTIT="echo"
+                       ;;
+               "-V"|"--version")
+                       echo "Version: @VERSION@"
+                       exit 2
+                       ;;
+               "-h"|"--help")
+                       usage
+                       exit 2
+                       ;;
+               *)
+                       echo "UNKNOWN OPTION: $1"
+                       usage
+                       exit 2
+                       ;;
+       esac
+fi
+
 # Are we a mac?
 if test -d /proc/pmu; then
         batteries=$(grep Battery /proc/pmu/info| cut -f2 -d:)
         if test "$batteries" -ne 0; then
-#                echo "We're a laptop" >&2;
+                $PRINTIT "We're a laptop (Mac: batteries found)" >&2;
                 exit 0
         fi
         exit 1
@@ -15,7 +53,7 @@
         dmitype=$(dmidecode --string chassis-type)
 
         if test "$dmitype" = "Notebook" || test "$dmitype" = "Portable"; then
-#               echo "We're a laptop" >&2;
+               $PRINTIT "We're a laptop (dmidecode returned $dmitype)" >&2;
                 exit 0;
         fi
 
@@ -28,10 +66,11 @@
         results=`find /proc/acpi/battery/ -mindepth 1 -type d`
         if [ ! -z "$results" ]; then
         #we're almost certainly a laptop
-#                echo "We're a laptop" >&2;
+                $PRINTIT "We're a laptop (ACPI batterie(s) found)" >&2;
                 exit 0
         fi
 fi
 
 #probably not a laptop; exit 
+$PRINTIT "We're not on a laptop (no relevant hint found)" >&2;
 exit 1
diff -urN laptop-detect-0.12.1.simplified/laptop-detect.sh.in 
laptop-detect-0.12.1.allow-verbose/laptop-detect.sh.in
--- laptop-detect-0.12.1.simplified/laptop-detect.sh.in 1970-01-01 
01:00:00.000000000 +0100
+++ laptop-detect-0.12.1.allow-verbose/laptop-detect.sh.in      2006-08-09 
03:13:47.143154965 +0200
@@ -0,0 +1,76 @@
+#!/bin/sh -e
+
+usage () {
+       echo "Usage: $0 [-h|--help|-v|--verbose]"
+       echo ""
+       echo "  -h | --help      print this help"
+       echo "  -v | --verbose   be verbose (messages go to STDOUT)"
+       echo "  -V | --version   print version information"
+       echo ""
+       echo " Possible return values:"
+       echo "  0  most likely running on a laptop"
+       echo "  1  most likely NOT running on a laptop"
+       echo "  2  called with unknown option, -h, --help, -V or --version"
+}
+
+PRINTIT="/bin/true" # /bin/true accepts any option but never prints anything
+
+# Check wether we were asked to be verbose
+
+if [ "$1" != "" ]; then
+       case "$1" in
+               "-v"|"--verbose")
+                       PRINTIT="echo"
+                       ;;
+               "-V"|"--version")
+                       echo "Version: @VERSION@"
+                       exit 2
+                       ;;
+               "-h"|"--help")
+                       usage
+                       exit 2
+                       ;;
+               *)
+                       echo "UNKNOWN OPTION: $1"
+                       usage
+                       exit 2
+                       ;;
+       esac
+fi
+
+# Are we a mac?
+if test -d /proc/pmu; then
+        batteries=$(grep Battery /proc/pmu/info| cut -f2 -d:)
+        if test "$batteries" -ne 0; then
+                $PRINTIT "We're a laptop (Mac: batteries found)" >&2;
+                exit 0
+        fi
+        exit 1
+fi
+
+if [ -x /usr/sbin/dmidecode ]; then
+        # dmidecode to grab the Chassis type
+        dmitype=$(dmidecode --string chassis-type)
+
+        if test "$dmitype" = "Notebook" || test "$dmitype" = "Portable"; then
+               $PRINTIT "We're a laptop (dmidecode returned $dmitype)" >&2;
+                exit 0;
+        fi
+
+        # turn back on for debugging
+        #echo "$dmitype"
+fi
+
+# check for any ACPI batteries
+if [ -d /proc/acpi/battery ]; then
+        results=`find /proc/acpi/battery/ -mindepth 1 -type d`
+        if [ ! -z "$results" ]; then
+        #we're almost certainly a laptop
+                $PRINTIT "We're a laptop (ACPI batterie(s) found)" >&2;
+                exit 0
+        fi
+fi
+
+#probably not a laptop; exit 
+$PRINTIT "We're not on a laptop (no relevant hint found)" >&2;
+exit 1

Reply via email to