home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / modem-wizard < prev    next >
Encoding:
Text File  |  2006-06-30  |  15.3 KB  |  446 lines

  1. #!/bin/sh
  2. #(c)copyright Barry Kauler modem wizard 2003,2004,2005. www.puppylinux.org
  3.  
  4. KERNVER="`uname -r`"
  5.  
  6. MODTYPE="ko"
  7. MODCONF="modprobe.conf"
  8. #k2.6, need to load core serial modules...
  9. #modprobe 8250_pci 2> /dev/null
  10. #...no, i changed config so built-in the kernel. but, still need for 2.6.11.7 build.
  11.  
  12. PCISUMMARY="`lspci -b`"
  13. MODEMINFOx="`cat /proc/pci | grep -i "modem" | head -n 1`"
  14. #outputs a leading line number...
  15. MODEMINFO2="`cat /proc/pci | grep -ni "modem" | head -n 1`"
  16. if [ "$MODEMINFO2" ];then
  17.  MODEMLINE2=`echo -n $MODEMINFO2 | cut -f 1 -d ':'`
  18.  MODEMLINE1=`expr $MODEMLINE2 - 1`
  19.  MODEMINFO1="`cat /proc/pci | head -n $MODEMLINE1 | tail -n 1`"
  20.  BUSNUMBER="`echo -n $MODEMINFO1 | tr -s ' ' | cut -f 2 -d ' ' | cut -f 1 -d ','`"
  21.  DEVNUMBER="`echo -n $MODEMINFO1 | tr -s ' ' | cut -f 4 -d ' ' | cut -f 1 -d ','`"
  22.  FUNCNUMBER="`echo -n $MODEMINFO1 | tr -s ' ' | cut -f 6 -d ' ' | cut -f 1 -d ':'`"
  23.  VENDCHIPNUMS="`lspci -b | grep "$BUSNUMBER:$DEVNUMBER.$FUNCNUMBER" | tr -s ' ' | cut -f 2 -d ' '`"
  24. fi
  25.  
  26. DEVM=""
  27. IRQM=""
  28.  
  29. # return the IRQ that respond to a given device
  30. irq_from_device()
  31. {
  32.  local dev=$1
  33.  #v1.0.2 it seems that setserial may be more trouble than its worth...
  34.  #in the case of linmodems it often doesn't work...
  35.  set -- `setserial -v -b $dev auto_irq \
  36.  skip_test autoconfig session_lockout`
  37.  [ "$6" ] && echo $6 | tr -d \) 
  38. }
  39.  
  40. # kill processing attached to device
  41. kill_users()
  42. {
  43. [ "`which fuser`" ] && fuser -k $1 2>/dev/null
  44. }
  45.  
  46. #talk to modem, wait for response
  47. chat_with()
  48. {
  49. rm -f /tmp/answer.txt
  50. ##note, ^M is equivalent to a carriage-return, and modem
  51. ## ...no, that does not work.
  52. ##should respond to "AT" with "OK"...
  53. ##(
  54. ## #echo -e "AT^M"
  55. ##  echo -n -e "AT\r\n"
  56. ##  tee > /tmp/answer.txt &
  57. ## sleep 1
  58. ## killall tee
  59. ##) < $1 > $1
  60. #dd bs=1 count=10 > /tmp/answer.txt < $1 &
  61. #DDID=$!
  62. #echo -n -e "ATC1\r\n" > $1
  63. #sleep 1
  64. ##killall dd 
  65. #kill $DDID
  66.  
  67. #the above method used to work k2.4, not k2.6. now do it like this...
  68. #no, with one modem at least, it hangs, also only works with atz...
  69. #also hangs if modem unplugged or turned off (contrary to what docs say)...
  70. #modem-stats -c "AT" $1 > /tmp/answer.txt
  71. modem-stats -c "ATZ" $1 > /tmp/answer.txt &
  72. sleep 2
  73. killall modem-stats
  74.  
  75.  
  76. if [ -e /tmp/answer.txt ];then
  77.  if [ -s /tmp/answer.txt ];then
  78.   #...filesize is nonzero.
  79.   #the modem should have answered with "OK"...
  80.   grep "^OK" /tmp/answer.txt > /dev/null 2>&1
  81.   [ $? -eq 0 ] && return 1 #success
  82.  fi
  83. fi
  84. return 0
  85. }
  86.  
  87. testmodem()
  88. {
  89. dev=$1
  90. DEVM=$1
  91. local irq
  92. echo -n "" >/tmp/modemtest.txt
  93. irq=$(irq_from_device $dev)
  94. if [ -z "$irq" ];then
  95.  #wavplay -q /usr/share/audio/error.wav &
  96.  echo "FAIL, $dev does not seem to have an irq assigned" >>/tmp/modemtest.txt
  97.  echo "There is probably nothing on that port so try another..." >>/tmp/modemtest.txt
  98.  echo "HOWEVER, for linmodems, maybe some other types, this irq" >>/tmp/modemtest.txt
  99.  echo "test may have failed but the modem may still work, so" >>/tmp/modemtest.txt
  100.  echo "continuing with testing port $dev..." >>/tmp/modemtest.txt
  101.  echo " "  >>/tmp/modemtest.txt
  102.  IRQM="unknown"
  103.  #return 1
  104. fi
  105. IRQM="$irq"
  106. kill_users $dev
  107. chat_with $dev
  108. if [ $? -eq 1 ];then
  109.  wavplay -q /usr/share/audio/generic.wav &
  110.  #DEVM="$dev"
  111.  echo "SUCCESS, $dev seems to be a modem, using irq=$irq" >>/tmp/modemtest.txt
  112.  echo "however if uncertain check the others" >>/tmp/modemtest.txt
  113.  echo -n -e "(if confident modem found, press \"SAVE\" button)"  >>/tmp/modemtest.txt
  114. else
  115.  wavplay -q /usr/share/audio/error.wav &
  116.  #echo "FAIL, there is something at $dev (and irq=$IRQM) but" >/tmp/modemtest.txt
  117.  echo -e "FAIL: $dev does not seem to be a modem. Try another \"tty*\" port..." >>/tmp/modemtest.txt
  118.  echo -n -e "(or, if you really want to use this one, press \"SAVE\")" >>/tmp/modemtest.txt
  119. fi
  120. }
  121.  
  122. TTYLT0=""
  123. MODLTMODEM="/lib/modules/$KERNVER/ltmodem/ltmodem.ko"
  124. if [ -e /lib/modules/$KERNVER/ltmodem/ltmodem.ko ];then
  125.  TTYLT0='ttyLT0:20,'
  126. fi
  127. TTYSL0=""
  128. MODSLMODEM="/lib/modules/$KERNVER/slmodem/slamr.ko"
  129. if [ -e /lib/modules/$KERNVER/slmodem/slamr.ko ];then
  130.  TTYSL0='ttySL0:21,'
  131. fi
  132.  
  133. BUTTONS="ttyS0":10,"ttyS1":11,"ttyS2":12,"ttyS3":13,"ttyS4":14,${TTYLT0}${TTYSL0}"SAVE":15,"ERASE":16,"HELP":17,"EXIT":18
  134.  
  135. if [ -e /etc/modemdevice ];then
  136.  DEVM="`cat /etc/modemdevice`"
  137.  echo "You previously selected $DEVM" >/tmp/modemtest.txt
  138.  echo -e "...if you do not want to use a modem anymore press \"ERASE\"" >>/tmp/modemtest.txt
  139.  echo >>/tmp/modemtest.txt
  140.  if [ "`echo "$DEVM" | grep --extended-regexp "ttyLT0|ttySL0"`" = "" ];then
  141.   echo "Note, $DEVM is for a true hardware modem, but Puppy does support" >>/tmp/modemtest.txt
  142.   echo "the Lucent and Smartlink software modems. However, they are" >>/tmp/modemtest.txt
  143.   echo "packages that you have to download with PupGet." >>/tmp/modemtest.txt
  144.   echo "When the Lucent package is installed, you will see the ttyLT0 button." >>/tmp/modemtest.txt
  145.   echo "When the Smartlink package is installed, you will see the ttySL0 button." >>/tmp/modemtest.txt
  146.   echo  >>/tmp/modemtest.txt
  147.  fi
  148.  echo -e "If uncertain, press the \"HELP\" button, otherwise" >>/tmp/modemtest.txt
  149.  echo -n -e "Press a \"tty*\" button to test if a modem is present..." >>/tmp/modemtest.txt
  150. else
  151.  DEVM=""
  152.  echo "WELCOME! Try your luck with Puppy analog Modem Wizard" >/tmp/modemtest.txt
  153.  
  154.  if [ ! "$MODEMINFO2" = "" ];then
  155.   echo " " >>/tmp/modemtest.txt
  156.   echo "Puppy has found a PCI modem:" >>/tmp/modemtest.txt
  157.   echo "$MODEMINFO1" >>/tmp/modemtest.txt
  158.   echo "$MODEMINFOx" >>/tmp/modemtest.txt
  159.   #echo "$BUSNUMBER" >>/tmp/modemtest.txt
  160.   #echo "$DEVNUMBER" >>/tmp/modemtest.txt
  161.   #echo "$FUNCNUMBER" >>/tmp/modemtest.txt
  162.   echo -n "The vendor:chip numbers are (hex): " >>/tmp/modemtest.txt
  163.   echo "$VENDCHIPNUMS" >>/tmp/modemtest.txt
  164.  fi
  165.  
  166.  echo " " >>/tmp/modemtest.txt
  167.  echo "If you think that this is a Lucent Linmodem (Linux-compatible" >>/tmp/modemtest.txt
  168.  echo -e "software modem), press the \"ttyLT0\" button to test it." >>/tmp/modemtest.txt
  169.  if [ ! "$TTYLT0" ];then
  170.   echo "HOWEVER, first download the Lucent modem package from the pupget folder" >>/tmp/modemtest.txt
  171.   echo -e "on ibiblio.org, run PupGet package manager to install." >>/tmp/modemtest.txt
  172.   echo "Then, rerun this Wizard and will see \"ttyLT0\" button." >>/tmp/modemtest.txt
  173.  fi
  174.  echo " " >>/tmp/modemtest.txt
  175.  
  176.  echo "If you think that this is a Smart Link HAMR5600 based AMR/CNR/" >>/tmp/modemtest.txt
  177.  echo "MDC/ACR PCI linmodem, SmartPCI56/561/562/563 based PCI linmodem," >>/tmp/modemtest.txt
  178.  echo "or SmartUSB56 based USB linmodem, press the \"ttySL0\" button." >>/tmp/modemtest.txt
  179.  if [ ! "$TTYSL0" ];then
  180.   echo "HOWEVER, first download the Smartlink modem package from the pupget folder" >>/tmp/modemtest.txt
  181.   echo -e "on ibiblio.org, run PupGet to install, then REBOOT Puppy." >>/tmp/modemtest.txt
  182.   echo "Then, rerun this Wizard and will see \"ttySL0\" button." >>/tmp/modemtest.txt
  183.  fi
  184.  echo " " >>/tmp/modemtest.txt
  185.  
  186.  echo "If you have a hardware modem, PCI, ISA bus or external serial,"  >>/tmp/modemtest.txt
  187.  echo -e "you can press one of the \"ttyS*\" buttons to find out which" >>/tmp/modemtest.txt
  188.  echo "port it is on." >>/tmp/modemtest.txt
  189.  echo "Note, ttyS0 is COM1, ttyS1 is COM2, etc." >>/tmp/modemtest.txt
  190.  echo " " >>/tmp/modemtest.txt
  191.  
  192.  echo -e "If uncertain, press the \"HELP\" button, otherwise" >>/tmp/modemtest.txt
  193.  echo -en "press a \"tty*\" button to test if a modem is present..." >>/tmp/modemtest.txt
  194.  
  195. fi
  196.  
  197. while :; do
  198. xmessage -bg "#c0c0ff" -center -name "xutilities" -title "Puppy Modem Wizard" -buttons \
  199.  "$BUTTONS" -file /tmp/modemtest.txt
  200.  
  201. case ${?} in
  202.    10)# ttyS0
  203.      testmodem /dev/ttyS0
  204.      ;;
  205.    11)# 
  206.      testmodem /dev/ttyS1
  207.      ;;
  208.    12)# 
  209.      testmodem /dev/ttyS2
  210.      ;;
  211.    13)# 
  212.      testmodem /dev/ttyS3
  213.      ;;
  214.    14)# 
  215.      testmodem /dev/ttyS4
  216.      ;;
  217.    15)# = save
  218.      if [ ! "$DEVM" ];then
  219.       wavplay -q /usr/share/audio/error.wav &
  220.       xmessage -bg "#ffc0c0" -center -name "xutilities" -title "Puppy Modem Wizard" -file -<<MSG1
  221. Huh? You have not yet selected a modem port,
  222. so nothing to save.
  223. MSG1
  224.      else
  225.       echo -n "$DEVM" >/etc/modemdevice
  226.       #note, rc.local0 will link /dev/modem to this at bootup,
  227.       #however do it now also (not remembered next bootup)...
  228.       rm -f /dev/modem
  229.       ln -s $DEVM /dev/modem
  230.       wavplay -q /usr/share/audio/ok.wav &
  231.       echo "You have configured Puppy for $DEVM (and irq=$IRQM)" >/tmp/modemtest.txt
  232.       #echo "Note, a dialup icon has been created on the desktop," >>/tmp/modemtest.txt
  233.       #echo "but you need to restart the window manager to see it." >>/tmp/modemtest.txt
  234.       echo "Note, there is a 'connect' icon on the desktop." >>/tmp/modemtest.txt
  235.       echo -n -e "Press \"EXIT\" to get out..." >>/tmp/modemtest.txt
  236.       BUTTONS="EXIT:18"
  237.       echo '#!/bin/sh' > /usr/local/bin/defaultconnect
  238.       echo 'exec gkdial' >> /usr/local/bin/defaultconnect
  239.       ##v1.0.5 this also done in rc.local0 if not here...
  240.       #if [ "`cat /root/Choices/ROX-Filer/PuppyPin | grep "defaultdialup"`" = "" ];then
  241.       # if [ "`cat /root/Choices/ROX-Filer/PuppyPin | grep 'x=\"32\" y=\"512\"'`" = "" ];then
  242.       #  echo '<icon x="32" y="512" label="dialup">/usr/local/bin/defaultdialup</icon>' >> /root/Choices/ROX-Filer/PuppyPin
  243.       # else
  244.       #  echo '<icon x="224" y="512" label="dialup">/usr/local/bin/defaultdialup</icon>' >> /root/Choices/ROX-Filer/PuppyPin
  245.       # fi
  246.       # cat /root/Choices/ROX-Filer/PuppyPin | grep -v '/pinboard' > /tmp/PuppyPin-CPY
  247.       # sync
  248.       # cp -f /tmp/PuppyPin-CPY /root/Choices/ROX-Filer/PuppyPin
  249.       # echo '</pinboard>' >> /root/Choices/ROX-Filer/PuppyPin
  250.       #fi
  251.      fi
  252.      ;;
  253.    16)# = erase
  254.      echo "All configuration of the modem, if any, has been erased" >/tmp/modemtest.txt
  255.      echo -n -e "Press \"EXIT\" to get out..." >>/tmp/modemtest.txt
  256.      rm -f /dev/modem
  257.      rm -f /etc/modemdevice
  258.      grep -v --extended-regexp "ltserial|slamr|slusb" /etc/modprobe.conf > /tmp/modprobe.conf
  259.      sync
  260.      mv -f /tmp/modprobe.conf /etc/modprobe.conf
  261.      BUTTONS="EXIT:18"
  262.      ;;
  263.    17)# HELP
  264.      dillo file:///usr/share/doc/HOWTO_Internet.htm &
  265.      ;;
  266.    18)# = exit
  267.      break;;
  268.    0)# exit
  269.      break;;
  270.    1)# exit
  271.      break;;
  272.    20) #Lucent Linmodem (refer rc.network)
  273.     if [ -e /lib/modules/2.4 ];then
  274.       lsmod | grep "lt_serial" > /dev/null 2>&1
  275.       if [ ! $? -eq 0 ];then #=0 found.
  276.        if [ "`cat /etc/$MODCONF | grep "lt_serial"`" = "" ];then
  277.         #rc.network will do this properly at next boot...
  278.         echo "#Needed for Lucent Linmodem..." >> /etc/$MODCONF
  279.         echo "alias char-major-62 lt_serial" >> /etc/$MODCONF
  280.         echo "alias /dev/ttyLT0 lt_serial" >> /etc/$MODCONF
  281.         echo "alias /dev/modem lt_serial" >> /etc/$MODCONF
  282.        fi
  283.        modprobe lt_serial #also loads lt_modem
  284.        if [ ! $? -eq 0 ];then
  285.         xmessage -center "Failed to load module. Did you remember to reboot Puppy
  286. after installing the Lucent driver PupGet package?
  287. Click OK button to continue..."
  288.        fi
  289.        sleep 1
  290.       fi
  291.     else
  292.       lsmod | grep "ltserial" > /dev/null 2>&1
  293.       if [ ! $? -eq 0 ];then #=0 found.
  294.        if [ "`cat /etc/$MODCONF | grep "ltserial"`" = "" ];then
  295.         #rc.network will do this properly at next boot...
  296.         echo "alias char-major-62 ltserial" >> /etc/$MODCONF
  297.         echo "alias /dev/ttyLT0 ltserial" >> /etc/$MODCONF
  298.         echo "alias /dev/modem ltserial" >> /etc/$MODCONF
  299.        fi
  300.        modprobe serial_core 2> /dev/null
  301.        ##cannot use modprobe...
  302.        ##this k2.6 version of insmod cannot handle compressed modules...
  303.        #gunzip -c /usr/lib/modules/ltmodem/ltmodem.ko.gz | insmod -
  304.        #gunzip -c /usr/lib/modules/ltmodem/ltserial.ko.gz | insmod -
  305.        modprobe ltmodem
  306.        modprobe ltserial
  307.        sleep 1
  308.       fi
  309.     fi
  310.       testmodem /dev/ttyLT0
  311.      ;;
  312.    21) #smartlink linmodem (refer rc.network)
  313.      #v2.02 rerwin, remove lsmod and if...
  314.       #lsmod | grep "slamr" > /dev/null 2>&1
  315.       #if [ ! $? -eq 0 ];then #=0 found.
  316.       #v2.02 rerwin, code block moved down below else...
  317.       #fi
  318.       #need to choose country...
  319.       SLCOUNTRY="`Xdialog --wmclass "smartlinkwizard" --title "Smart-Link Modem Wizard" --stdout --no-tags \
  320.  --menubox "Please choose your country:"  0 0 0 \
  321.  ALGERIA Algeria \
  322.  ARGENTINA Argentina \
  323.  AUSTRALIA Australia \
  324.  AUSTRIA Austria \
  325.  BAHREIN Bahrein \
  326.  BELGIUM Belgium \
  327.  BRAZIL Brazil \
  328.  BRUNEI Brunei \
  329.  BULGARIA Bulgaria \
  330.  CANADA Canada \
  331.  CHILE Chile \
  332.  CHINA China \
  333.  CTR21EUROPE CTR21_Europe \
  334.  CYPRUS Cyprus \
  335.  CZECH_REPUBLIC Czech_Replublic \
  336.  DENMARK Denmark \
  337.  EGYPT Egypt \
  338.  ESTONIA Estonia \
  339.  FINLAND Finland \
  340.  FRANCE France \
  341.  GERMANY Germany \
  342.  GREECE Greece \
  343.  HONG_KONG Hong_Kong \
  344.  HUNGARY Hungary \
  345.  ICELAND Iceland \
  346.  INDIA India \
  347.  INDONESIA Indonesia \
  348.  IRELAND Ireland \
  349.  ISRAEL Israel \
  350.  ITALY Italy \
  351.  JAPAN Japan \
  352.  JORDAN Jordan \
  353.  KOREA Korea \
  354.  KUWAIT Kuwait \
  355.  LATVIA Latvia \
  356.  LEBANON Lebanon \
  357.  LITHUANIA Lithuania \
  358.  LUXEMBOURG Luxembourg \
  359.  MALAYSIA Malaysia \
  360.  MALTA Malta \
  361.  MEXICO Mexico \
  362.  MOROCCO Morocco \
  363.  NETHERLANDS Netherlands \
  364.  NEW_ZEALAND New_Zealand \
  365.  NORWAY Norway \
  366.  OMAN Oman \
  367.  PAKISTAN Pakistan \
  368.  PERU Peru \
  369.  PHILIPPINES Philippines \
  370.  POLAND Poland \
  371.  PORTUGAL Portugal \
  372.  ROMANIA Romania \
  373.  RUSSIA Russia \
  374.  SAUDIARABIA Saudi_Arabia \
  375.  SINGAPORE Singapore \
  376.  SLOVAKIA Slovakia \
  377.  SLOVENIA Slovenia \
  378.  SOUTHAFRICA South_Africa \
  379.  SOUTHKOREA South_Korea \
  380.  SPAIN Spain \
  381.  SRILANKA Sr_Lanka \
  382.  SWEDEN Sweden \
  383.  SWITZERLAND Switzerland \
  384.  TAIWAN Taiwan \
  385.  THAILAND Thailand \
  386.  TUNISIA Tunisia \
  387.  TURKEY Turkey \
  388.  UAE UAE \
  389.  UK UK \
  390.  URUGUAY Uruguay \
  391.  USA USA \
  392.  VIETNAM Vietnam 2> /dev/null`"
  393.  
  394.       if [ ! $? -eq 0 ];then
  395.        xmessage "ABORT: You did not select a country!!!"
  396.       else
  397.        #v2.02 rerwin, code block moved down...
  398.        if [ "`cat /etc/$MODCONF | grep "slamr"`" = "" ];then
  399.         #rc.network will do this properly at next boot...
  400.         #echo "#Needed for Smartlink Linmodem..." >> /etc/$MODCONF
  401.         #v2.01 rerwin found 212,213 need to be changed to 242,243...
  402.         echo "alias char-major-242 slamr" >> /etc/$MODCONF
  403.         #v2.02 rerwin...
  404.         echo 'install slamr modprobe --ignore-install ungrab-winmodem ; modprobe --ignore-install slamr' >> /etc/modprobe.conf
  405.         echo "alias char-major-243 slusb" >> /etc/$MODCONF
  406.        fi
  407.        #v2.01 modprobe usbcore 2> /dev/null
  408.        #v2.01 bug, rerwin found needs ungrab-winmodem before load slamr...
  409.        #v2.02 rerwin, rmmod...
  410.        rmmod slamr #unload for ungrab, in case slamr misloaded as serial driver.
  411.        modprobe ungrab-winmodem
  412.        modprobe slamr
  413.        [ ! $? -eq 0 ] && xmessage -center "Failed to load slamr module."
  414.        if [ ! "`lsmod | grep '^usbcore'`" = "" ];then #v2.01
  415.         modprobe slusb
  416.         [ ! $? -eq 0 ] && xmessage -center "Failed to load slusb module."
  417.        fi
  418.  
  419.        #choose usb or pci modem...
  420.        MYSLMODEM="`Xdialog --wmclass "smartlinkwizard" --title "Smart Link Modem Wizard" --stdout --no-tags \
  421.  --menubox "Please choose type of Smart-Link modem:"  0 0 0 \
  422.  slusb "USB" \
  423.  slamr "PCI (internal card)" 2> /dev/null`"
  424.        if [ ! $? -eq 0 ];then
  425.         xmessage "ABORT: You did not choose modem type!!!"
  426.        else
  427.         #start slmodemd...
  428.         echo "#/bin/sh" > /usr/sbin/slmodemdshell
  429.         echo "/usr/sbin/slmodemd --country=$SLCOUNTRY /dev/${MYSLMODEM}0" >> /usr/sbin/slmodemdshell
  430.         sync
  431.         chmod 755 /usr/sbin/slmodemdshell
  432.         /usr/sbin/slmodemdshell &
  433.         sleep 1
  434.         #test modem...
  435.         testmodem /dev/ttySL0
  436.        fi
  437.       fi
  438.      
  439.      ;;
  440. esac
  441. done
  442. rm -f /tmp/modemtest.txt
  443. rm -f /tmp/answer.txt
  444.  
  445. #END#
  446.