home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / opt0.4.lcm / bin / probe_synch.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2004-02-26  |  5.7 KB  |  240 lines

  1. #!/bin/sh
  2.  
  3. # probe device's VIDs and PIDs
  4.  
  5.  
  6. function version()
  7. {
  8.     echo "$VERSION"
  9.     exit 0
  10. }
  11.  
  12. function commandlinehelp()
  13. {
  14.     echo "Usage:"
  15.     echo "          $BASE [<switch>..] [dir]"
  16.     echo "Switches:"
  17.     echo "          --try-all              try all the synch .bin even if one is OK"
  18.     echo "          --usb-init             reset modem between each synch .bin test"
  19.     echo "          --no-prompt            don't prompt before loading firmware (only enabled if --usb-init is set)"
  20.     echo "          --batch                disable default interactive mode"
  21.     echo "          --version or -v        show version number then exit"
  22.     echo "          --help or -h           show this help then exit"
  23.     exit $1
  24. }
  25.  
  26. function prompt()
  27. {
  28.     echo -ne "\n$1 your modem now, press ENTER to continue"
  29.     read
  30. }
  31.  
  32. function reset_usb()
  33. {
  34.     lsmod | grep $HUB > /dev/null
  35.     if [ $? -eq 0 ]
  36.     then
  37.         if [ $PROMPT -eq 1 ]
  38.         then
  39.             prompt "Unplug"
  40.         fi
  41.         echo -e "\nResetting USB HUB.."
  42.         modprobe -r $HUB > /dev/null
  43.         if [ $? -ne 0 ]
  44.         then
  45.             echo "*** unable to unload $HUB, this might be an USB issue and you must reset is manually"
  46.             exit 1
  47.         fi
  48.         sleep 1
  49.         MSG="Replug"
  50.     else
  51.         MSG="Plug in"
  52.     fi
  53.     modprobe $HUB > /dev/null
  54.     if [ $? -ne 0 ]
  55.     then
  56.         echo "*** unable to load $HUB, this might be an USB issue"
  57.         exit 1
  58.     fi
  59.     if [ $PROMPT -eq 1 ]
  60.     then
  61.         prompt "$MSG"
  62.     fi
  63.     sleep 1
  64. }
  65.  
  66. function init_modem()
  67. {
  68.     echo -e "\nLoading firmware.."
  69.     $BIN_DIR/eci-load1 $ECILOAD1_OPTIONS 0x$VID1 0x$PID1 0x$VID2 0x$PID2 "$FIRMWARE" > /dev/null 2>&1
  70.     if [ $? -eq 0 ]
  71.     then
  72.         echo "Firmware loaded"
  73.     else
  74.         echo "*** failed to load firmware, aborting"
  75.         exit 1
  76.     fi
  77. }
  78.  
  79.  
  80. # <CONFIG>
  81. BIN_DIR="/usr/local/bin"
  82. ETC_DIR="/etc"
  83. CONF_DIR="/etc/eciadsl/"
  84. PPPD_DIR="/etc/ppp"
  85. VERSION=""
  86. # </CONFIG>
  87.  
  88. BASE=${0##*/}
  89. DIR=""
  90. declare -i ALL=0 INTERACTIVE=1 FULL_INIT=0 PROMPT=1
  91.  
  92. while [ -n "$1" ]
  93. do
  94.     case "$1" in
  95.         "--usb-init")        let FULL_INIT=1;;
  96.         "--no-prompt")        let PROMPT=0;;
  97.         "--try-all")        let ALL=1;;
  98.         "--batch")            let INTERACTIVE=0;;
  99.         "--version"|"-v")    version;;
  100.         "--help"|"-h")        commandlinehelp 0;;
  101.         *)                    test -z "$DIR" && DIR=$1 || break;;
  102.     esac
  103.     shift
  104. done
  105.  
  106. if [ $UID -ne 0 ]
  107. then
  108.     echo -e "\nYou must be root to run this script!"
  109. #    exit 1
  110. fi
  111.  
  112.  
  113. echo -e "\nWARNING: if no $CONF_DIR/eciadsl.conf file exists,"
  114. echo "default VID/PID will be assumed. This eciadsl.conf file is generated using"
  115. echo "eciconf.sh or eciconftxt.sh, please read the INSTALL file to properly install"
  116. echo "and configure the driver"
  117. echo "This script requires your modem to be supported by the driver, and that"
  118. echo "you've installed some extra synch .bin (the official synch_bin package for instance)"
  119. echo "It might be also necessary to unplug/wait/replug your modem before your"
  120. echo -e "this script and to ensure that no pppd/pppoeci instance is running\n"
  121.  
  122. ECILOAD1_OPTIONS=""
  123. ECILOAD2_OPTIONS=""
  124. if [ -f "$CONF_DIR/eciadsl.conf" ]; then
  125.     VID1=`grep -iE "^[ \t]*VID1[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -d " \t"`
  126.     PID1=`grep -iE "^[ \t]*PID1[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -d " \t"`
  127.     VID2=`grep -iE "^[ \t]*VID2[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -d " \t"`
  128.     PID2=`grep -iE "^[ \t]*PID2[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -d " \t"`
  129.     FIRMWARE=`grep -iE "^[ \t]*FIRMWARE[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -s "\t" " "`
  130.     ECILOAD1_OPTIONS=`grep -iE "^[ \t]*ECILOAD1_OPTIONS[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -s " \t" " "`
  131.     ECILOAD2_OPTIONS=`grep -iE "^[ \t]*ECILOAD2_OPTIONS[ \t]*=" "$CONF_DIR/eciadsl.conf" | tail -1 | cut -f 2 -d '=' | tr -s " \t" " "`
  132.     echo -e "\nConfig read from $CONF_DIR/eciadsl.conf"
  133. else
  134.     echo -e "\nDefault config assumed"
  135. fi
  136. test -z "$VID1" && VID1="0547"
  137. test -z "$PID1" && PID1="2131"
  138. test -z "$VID2" && VID2="0915"
  139. test -z "$PID2" && PID2="8000"
  140. test -z "$FIRMWARE" && FIRMWARE="$CONF_DIR/firmware00.bin"
  141. test -z "$DIR" && DIR=$CONF_DIR
  142.  
  143. if [ $INTERACTIVE -eq 1 ]
  144. then
  145.     echo -e "\nType in a directory where to find the synch .bin"
  146.     echo -en "[default is $DIR]: "
  147.     read USERDIR
  148.     test -n "$USERDIR" && DIR="$USERDIR"
  149. fi
  150.  
  151. if [ ! -d "$DIR" ]
  152. then
  153.     echo -e "\n*** cannot access to $DIR"
  154.     exit 1
  155. fi
  156.  
  157. LIST=""
  158. for FILE in $(find "$DIR" -maxdepth 1 -name "*.bin" | grep -v firm)
  159. do
  160.     test -n "$LIST" && LIST="$LIST\n${FILE##*/}" || LIST="${FILE##*/}"
  161. done
  162.  
  163. if [ -z "$LIST" ]
  164. then
  165.     echo -e "\n*** no synch .bin has been found in $DIR, aborting"
  166.     exit 1
  167. fi
  168.  
  169. echo -e "\nThese synch .bin will be tested:"
  170. echo -e "$LIST"
  171. if [ $INTERACTIVE -eq 1 ]
  172. then
  173.     echo -en "Start the tests now? (Y/n) "
  174.     read CONFIRM
  175.     case $CONFIRM in
  176.     Y|y|"")    ;;
  177.     *)        echo "*** cancelled by user, exiting"
  178.             exit 1;;
  179.     esac
  180. fi
  181.  
  182. # HUB=usb-uhci
  183.  
  184. if [ $FULL_INIT -eq 0 ]
  185. then
  186.     init_modem
  187. else
  188.     echo -en "\nWhich USB HUB module is yours (common values are usb-uhci, usb-ohci or uhci)? "
  189.     HUB=""
  190.     while [ -z "$HUB" ]
  191.     do
  192.         read HUB
  193.         if [ -z "$HUB" ]
  194.         then
  195.             echo -n "* you must enter a valid USB HUB module name, try again: "
  196.         fi
  197.     done
  198.     reset_usb
  199. fi
  200.  
  201. OLDIFS="$IFS"
  202. IFS="
  203. "
  204. for FILE in $(echo -e "$LIST")
  205. do
  206.     if [ $FULL_INIT -eq 1 ]
  207.     then
  208.         init_modem
  209.     fi
  210.  
  211.     echo -e "\nTesting synch with $DIR/$FILE.."
  212.     $BIN_DIR/eci-load2 $ECILOAD2_OPTIONS 0x$VID2 0x$PID2 "$DIR/$FILE"
  213.     if [ $? -eq 0 ]
  214.     then
  215.         test -n "$LISTOK" && LISTOK="$LISTOK\n$FILE" || LISTOK="$FILE"
  216.         echo "$DIR/$FILE seems OK"
  217.         test $ALL -eq 0 && break
  218.     fi
  219.     echo "Trying the next one.."
  220.     sleep 1
  221.  
  222.     if [ $FULL_INIT -eq 1 ]
  223.     then
  224.         reset_usb
  225.     fi
  226. done
  227. IFS="$OLDIFS"
  228.  
  229. if [ -z "$LISTOK" ]
  230. then
  231.     echo -e "\n** No valid synch .bin has been found"
  232.     echo "There are many possible issues"
  233.     echo "and it may be necessary to generate your own one. Please refer to"
  234.     echo "the documentation in both cases."
  235. else
  236.     echo -e "\nThese synch .bin are supposed to be OK:"
  237.     echo -e "$LISTOK"
  238. fi
  239. exit
  240.