#!/bin/sh

# lanoche - laptop or notebook check, generates HTML report

# Generated automatically from lanoche.in by configure.

# this is usually a good idea
set -e


# Parse the options

TEMP=`getopt -n lanoche -o \
o:\
hV \
--long \
output:,\
verbose,\
help,version -- "$@"`

if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi

# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"

while true ; do
    case "$1" in
	-o|--output) OFILE="$2"; shift 2 
	    ;;
	--verbose) VERBOSE="yes"; shift 
	    ;;
	-V|--version) echo "lanoche 0.6"; exit 0 ;;
	-h|--help)
	    echo "lanoche - laptop or notebook check, generates HTML report";
	    echo "usage: lanoche [options]";
	    echo "options:";
	    echo "  -o, --output NAME          send output to NAME instead of standard output, (not implemented yet)";
	    echo "  --verbose                  print more information";
	    echo "  -h, --help                 display this help and exit";
	    echo "  -V, --version              output version information and exit";

	    exit 0
	    ;;
	--) shift ; break ;;
	*) echo "Internal error!  no case for option \"$1\"" ; exit 1 ;;
    esac
done

# do the work
# there should be a conf file in $HOME oder the current dir, but not yet 
. /etc/lanoche/lanoche.conf

# functions

# to do show version -V of all helper tools

usage() { 
	case $1 in
	"-V")
	;;
	"-h")
	;;
	"")
	;;
	*)
	echo -e "usage: $0 -h -v -V -d\n" 
	;;
	esac ; }

header() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_header.html

<!-- generated with 'lanoche' v$0.6                                -->
<!--  MobiliX       http://mobilix.org/software.html             -->
<!--                                                              -->
<!--                                                              -->
<!--                                                              -->
<!--                                                              -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
  <head>
    <title>Linux on the $NOTEBOOK</title>
    <meta http-equiv="content-type" content=
    "text/html; charset=iso-8859-1">
    <meta name="author" content="$AUTHOR">
    <meta name="description" content=
    "Overview of the Linux related Features of the $NOTEBOOK">
    <meta name="keywords" content=
    "omnibook, linux, laptop, notebook">
    <meta name="date" content="`date -I`">
  </head>

  <body>

EOF
}


preface() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_preface.html

    <h1>Linux on the $NOTEBOOK</h1>

    <h2>Preface</h2>

    <p>
    This is a survey about Linux related hardware features of
    the $NOTEBOOK. I don't try to explain the usual
    installation details (for instance, which partitions I have
    made).
    </p>

    <p>
    <a href="mailto:$EMAIL">$AUTHOR</a> &lt;$EMAIL&gt;
    </p>

EOF
}

install() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_install.html

    <h2>Installation</h2>

    <p>
    On my $NOTEBOOK I have installed the <strong><a
    href="$URL_D">$DISTRIBUTION</a></strong> Linux distribution.
    </p>

EOF
}

general() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_general.html

    <h2>General Hardware Data</h2>

    <p>
    General system information:<br>
    <code>`uname -a`</code>
    </p>

    <pre>
`cat /proc/cpuinfo`
    </pre>

    <pre>
`df`
    </pre>

    <pre>
`fdisk -l`
    </pre>

EOF
}

harddisk() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_harddisk.html

    <h3>Hard Disk</h3>

    <pre>
`hdparm -i /dev/hda`
    </pre>

EOF
}

bios() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_bios.html

    <h3>BIOS</h3>

    <p>
    ...
    </p>

EOF
}

memory() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_memory.html

    <h3>Memory (RAM)</h3>

    <pre>
`free`
    </pre>

EOF
}

pcmcia() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_pcmcia.html

    <h3>PCMCIA</h3>

    <p>
    Output of <code>probe</code>:
    </p>

    <pre>
`probe` 
    </pre>

EOF
}

graphic() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_graphic.html

    <h3>Graphic-Chip</h3>

    <p>
    Output of <code>SuperProbe</code>:
    </p>
    <pre>
`SuperProbe 2>&1`
    </pre>

    <p>
    Output of <code>xviddetect</code>:
    </p>

    <pre>
`xviddetect`
    </pre>

EOF
}

sound() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_sound.html

    <h3>Sound</h3>

    <p>
    Output of <code>cat /dev/sndstat</code>:
    </p>

    <pre>
`cat /dev/sndstat`
    </pre>

EOF
}

irda() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_irda.html

    <h3>Infrared Port - IrDA(TM)</h3>

    <p>
    FIR
    </p>

    <pre>
`findchip`
    </pre>

    <p>
    SIR
    </p>

    <pre>
`dmesg | grep -i ttys`
    </pre>

EOF
}

mouse() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_mouse.html

    <h3>Mouse</h3>

    <p>
    ...
    </p>

EOF
}

cd() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_cd.html

    <h3>CD</h3>

    <pre>
`dmesg|grep CD`
    </pre>

EOF
}

floppy() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_floppy.html

    <h3>Floppydrive</h3>

    <pre>
`dmesg|grep -i floppy`
    </pre>

EOF
}

keyboard() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_keyboard.html

    <h3>Keyboard</h3>
     
    <p>
    ...
    </p>

EOF
}

apm() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_apm.html

    <h3>Advanced Power Management (APM)</h3>

    <p>
    ...
    </p>

EOF
}

battery() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_battery.html

    <h3>Battery</h3>

    <p>
    ...
    </p>


EOF
}

rtc() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_rtc.html

    <h3>Real Time Clock (RTC)</h3>

    <p>
    ...
    </p>

EOF
}

docking() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_docking.html

    <h3>Docking Station</h3>

    <p>
    ...
    </p>

EOF
}

pci() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_pci.html

    <h2>Survey PCI Devices</h2>

    <p>
    Output from <code>lspci</code>:
    </p>

    <pre>
`lspci`
    </pre>

EOF
}

pci2() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_pci2.html

    <p>
    Output from <code>cat /proc/pci</code>:
    </p>

    <pre>
`cat /proc/pci`
    </pre>

EOF
}

pnp() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_pnp.html
    <h2>Survey PnP Devices</h2>

    <p>
    Output from <code>pnpdump</code>:
    </p>

    <pre>
`pnpdump`
    </pre>

EOF
}

rs232() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_rs232.html

    <h2>Survey RS232</h2>

    <p>
    Output from <code>setserial</code>:
    </p>

    <pre>
`setserial -a -g /dev/ttyS?`  
    </pre>

EOF
}

todo() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_todo.html

    <h2>ToDo</h2>

    <ul>

    <li>
    N.N.
    </li>

    </ul>

EOF
}

disclaimer() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_disclaimer.html

    <h2>Disclaimer</h2>

    <p>
    This document has nothing to do with $MANUFACTURER, they
    don't even know it exists. There is no guarantee that the
    information on this page is accurate, please don't hold me
    responsible if your experience is different from the
    information here.
    </p>

EOF
}

credits() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_credits.html


    <h2>Credits</h2>

    <ul>

    <li>
    <a href="http://pcmcia-cs.sourceforge.net">
      David A. Hinds</a> maintainer of the PCMCIA-CS package
    </li>

    <li>
    <a href="http://irda.sourceforge.net">Linux/IrDA core team</a>
    </li>

    <li>
    <a href="http://www.cs.utexas.edu/users/kharker/linux-laptop/">Linux
     on Laptops</a> by Kenneth E. Harker
     &lt;kharker@cs.utexas.edu&gt;
    </li>

    <li>
    <a href= 
     "http://www.cs.utexas.edu/users/kharker/linux-laptop/volunteer-search.html">
    Linux Laptop Volunteer Support Database</a> by Kenneth E.
    Harker
    </li>

    <li>
    <a href="http://mobilix.org">MobiliX</a>
    </li>

    <li>
    The members of the linux-laptop@mobilix.org mailing list
    </li>

    <li>
    The members of the linux-laptop@vger.rutgers.edu mailing list
    </li>

    <li>
    Others whose names I forgot to record.
    </li>

    </ul>

EOF
}

history() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_history.html

    <h2>Revision History</h2>

EOF
}

footer() {
cat <<EOF>${TMP}/${OUTPUT_FILE}_footer.html

    <hr>
    <p>
    This report was generated by <code>lanoche</code> v0.6 `date`.
    </p>

    <p>
    The latest version of <code>lanoche</code> is
    available at <a href="http://mobilix.org/software.html">MobiliX - Software</a>.
    </p>

  </body>
</html>

EOF
}

# main, build it all together

rm -f ${TMP}/${OUTPUT_FILE}.html
 
for FILE in header \
            preface \
            install \
            general \
            harddisk \
            pcmcia \
            graphic \
            sound \
            irda \
            floppy \
            pci \
            pnp \
            rs232 \
            disclaimer \
            credits \
            footer
do

`$FILE`
cat ${TMP}/${OUTPUT_FILE}_${FILE}.html >> ${TMP}/${OUTPUT_FILE}.html

done

# clean up the HTML code

sed -e 's/\#/\&num;/g' \
    -e 's/<dwex@xfree86.org>/\&lt;dwex@xfree86.org\&gt;/' \
       ${TMP}/${OUTPUT_FILE}.html > ${OUTPUT_FILE}.html

toc() {

grep -i "<h2>" > ${TMP}/${OUTPUT_FILE}_toc.html 

}

echo -e "$0: output file: ${OUTPUT_FILE}.html \n"

# cleanup it up

rm -f ${TMP}/${OUTPUT_FILE}_*

exit 0
