#!/bin/bash
# HOWTO:
#
# 1) THIS IS BOTH A HOWTO FILE AND AN EXECUTABLE SCRIPT
# 2) YOU NEED TO HAVE THREE FILES IN THE SAME DIRECTORY:
#     - conexant_192-1ubuntu-1.tar.gz
#     - THIS SCRIPT
#     - modem-hsfpci-0.1 SUB DIRECTORY
# 3) YOU CAN DOWNLOAD conexant_192-1ubuntu-1.tar.gz FROM EITHER:
#  http://www.surak.eti.br/linux/ubuntu/deb/conexant/conexant_192-1ubuntu-1.tar.gz
#  ftp://ftp.wizzy.com/pub/wizzy/conexant/conexant_192-1ubuntu-1.tar.gz
# 4) YOU ALREADY USED tar xjvf modem-hsfpci.tar.bz2 TO UNPACK THIS FILE AND
#    THE modem-hsfpci-0.1 SUB DIRECTORY IN THE SAME DIRECTORY
# 5) YOU ALSO HAVE TO HAVE fakeroot, build-essential, linux-headers for
#    your specific kernel, and debhelper INSTALLED ALREADY. THESE ARE AVAILABLE
#     ON THE (K)UBUNTU INSTALL CD. TRY:
#      apt-get install fakeroot
#      apt-get install debhelper
#      apt-get install build-essential
#      apt-get linux-headers-`uname -r`   (NOTICE THE ` SYMBOL IS NOT A QUOTE '
#    AND IS OFTEN FOUND ON THE SAME KEY THAT HAS THE ~ SYMBOL
# 6) RUN THIS SCRIPT BY OPENING A TERMINAL, CHANGING TO THIS DIRECTORY, AND
#    ENTERING ./HOWTO.hsf AT THE PROMPT
# 7) THE SCRIPT WILL CHECK FOR ALL THE ABOVE AND GIVE YOU AN ERROR MESSAGE IF
#    ANYTHING IS MISSING.  ONCE EVERYTHING IS OK, IT WILL UNPACK
#    conexant_192-1ubuntu-1.tar.gz AND MOVE IT TO modem-hsfpci-0.1/ AND THEN
#    BUILD THE PACKAGE.  THE PACKAGE WILL BE IN THIS MAIN DIRECTORY.
# 8) USE dpkg -i modem-hsfpci_0.1-0ubuntu1_i386.deb TO INSTALL IT
# 9) CHECK /usr/share/doc/modem-hsfpci/README.Debian FOR INSTRUCTIONS TO
#    BUILD YOUR DRIVER
#
#####################################################################################
# This script will add an update patch to conexant_192-1ubuntu-1.tar.gz to
# enable compiling it with other kernels and supported hsf modems
# RUN THIS SCRIPT IN A TERMINAL WITH THE COMMAND:
#       ./HOWTO.txt
#

CWD=`pwd`

# we need the source file and the patch file in the same directory as this script
if ! [ -f $CWD/conexant_192-1ubuntu-1.tar.gz ] ; then
cat <<ENDDL

You need to have the file conexant_192-1ubuntu-1.tar.gz present in this directory.
You can download it using either source:
  http://www.surak.eti.br/linux/ubuntu/deb/conexant/conexant_192-1ubuntu-1.tar.gz
  ftp://ftp.wizzy.com/pub/wizzy/conexant/conexant_192-1ubuntu-1.tar.gz

ENDDL
exit 1
fi

# Let's make sure we didn't get separated from the rest of our package
if ! [ -d $CWD/modem-hsfpci-0.1 ] ; then
  echo
  echo "Run this script in the same directory with the modem-hsfpci-0.1 directory"
  exit 1
fi

# Make sure these packages are installed
if ! ( dpkg -l | grep fakeroot >> /dev/null ) ; then
  echo
  echo "please apt-get install fakeroot from the installation CD"
  exit 1
fi

if ! ( dpkg -l | grep debhelper >> /dev/null ) ; then
  echo
  echo "please apt-get install debhelper from the installation CD"
  exit 1
fi

if ! ( dpkg -l | grep build-essential >> /dev/null ) ; then
  echo
  echo "please apt-get install build-essential from the installation CD"
  exit 1
fi

if ! ( dpkg -l | grep linux-headers-`uname -r` >> /dev/null ) ; then
  echo
  echo "please apt-get linux-headers-`uname -r` on the installation CD"
  exit 1
fi

# ok, we're ready to start repackaging
tar xzvf conexant_192-1ubuntu-1.tar.gz && \
mv -v $CWD/conexant $CWD/conexant-192-1ubuntu && \
mv -v $CWD/conexant-192-1ubuntu $CWD/modem-hsfpci-0.1/

# ok, we're ready to make the package
cd $CWD/modem-hsfpci-0.1 && \
dpkg-buildpackage -rfakeroot -uc -us && \
cd $CWD && \
cat <<INSIT

++++++++++++++ SUCCESS ! ++++++++++++++++++++++++

OK, the package should be in this directory, you can install it with

  "sudo dpkg -i modem-hsfpci_0.1-0ubuntu1_i386.deb"

and then read the file /usr/share/doc/modem-hsfpci/README.Debian for instructions.
INSIT
exit 0
