modemtest 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #!/bin/sh
  2. #Barry Kauler 2007 LGPL
  3. #called from /usr/sbin/modemprobe, pupdial
  4. #v405 overhauled.
  5. #v408 rerwin: bugfix.
  6. #v465 rerwin: v413 move init string to Init3
  7. #v477 rerwin: v413 wait longer for modem response; add splash message during sleep
  8. #v424 rerwin: reset skip-PIN flag
  9. #101203 bk: message modification.
  10. #101220 bk: info box if get empty string.
  11. #120201 rodin.s: internationalized.
  12. #120329 Xdialog bug --yesno supposed to "yes" "No" buttons, but they are "OK" "Cancel".
  13. export TEXTDOMAIN=modemtest
  14. export TEXTDOMAINDIR=/usr/share/locale
  15. export OUTPUT_CHARSET=UTF-8
  16. eval_gettext () {
  17. local myMESSAGE=$(gettext "$1")
  18. eval echo \"$myMESSAGE\"
  19. }
  20. export LANGORG=$LANG
  21. Yes_lbl="$(gettext 'Yes')"
  22. No_lbl="$(gettext 'No')"
  23. #[ ! $1 ] && exit
  24. DEVM=$1
  25. PARAM2=$2
  26. MODEMDEV=""
  27. if [ -h /dev/modem ];then
  28. MODEMDEV="`readlink /dev/modem`"
  29. fi
  30. #a fallback if user runs this script directly...
  31. [ "$DEVM" = "" ] && [ "$MODEMDEV" = "" ] && exit
  32. [ "$DEVM" = "" ] && [ "$MODEMDEV" != "" ] && DEVM="$MODEMDEV"
  33. if [ "$PARAM2" = "initonly" ];then
  34. MSGSUCCESS="`gettext \"Okay, the modem was probed and it responded, confirming that it does exist,\n
  35. now the probe can be done to determine a suitable initialization string.\n
  36. Click the 'Yes' button to do this (recommended), or\n
  37. 'No' if you already have a suitable initialization string for this modem in\n
  38. /etc/wvdial.conf (the configuration file for PupDial) ...that would probably\n
  39. be the case if you had used this modem the last time that you ran PupDial.\n
  40. \n
  41. Note: For some modern modems, the default 'ATZ' initialization string is\n
  42. sufficient and you do not have to do this probe, however it does not do any\n
  43. harm to do so (and gives further confirmation the modem works)...\"`"
  44. else
  45. MSGSUCCESS="`eval_gettext \"Success, the modem responds as \\\$DEVM! (The modem is there; getting it to dial out is another matter!)\n
  46. Click the 'yes' button if you would like /dev/modem to be a link to \\\${DEVM} and the Wvdial\n
  47. configuration file /etc/wvdial.conf set with entry 'Modem = /dev/\\\${DEVM}. An attempt will\n
  48. also be made to determine appropriate modem initialization strings.\"`"
  49. fi
  50. #return the IRQ that respond to a given device...
  51. irq_from_device_func() { #device passed in, ex: /dev/ttyS0
  52. #v1.0.2 it seems that setserial may be more trouble than its worth...
  53. #in the case of linmodems it often doesn't work...
  54. case ${1} in
  55. /dev/ttyS[0-9])
  56. set -- `setserial -v -b ${1} auto_irq skip_test autoconfig session_lockout`
  57. [ "$6" ] && echo $6 | tr -d \)
  58. ;;
  59. esac
  60. }
  61. #talk to modem, wait for response...
  62. chat_with_func() { #device passed in.
  63. rm -f /tmp/answer.txt
  64. #TODO maybe send +++ to return modem to command-mode.
  65. #hangs if modem unplugged or turned off (contrary to what docs say)...
  66. modem-stats -c "ATZ" $1 > /tmp/answer.txt &
  67. sleep 5 #v413
  68. killall modem-stats
  69. if [ -e /tmp/answer.txt ];then
  70. if [ -s /tmp/answer.txt ];then #nonzero size.
  71. grep "^OK" /tmp/answer.txt > /dev/null 2>&1
  72. [ $? -eq 0 ] && return 0 #success
  73. fi
  74. fi
  75. return 1
  76. }
  77. #v433 Set config file Modem line(s), including possible alternate USB modem device.
  78. modem_device_to_conf_func() {
  79. #Argument is modem device for config file - current or tested
  80. DEVMCONF="$1"
  81. DEVMALT="`get_modem_alternate_device $DEVM`"
  82. if [ "$DEVMALT" = "" ];then
  83. if [ "$DEVM" = "$MODEMDEV" -a "$PARAM2" = "" ];then
  84. grep -q '^#Modem =' /etc/wvdial.conf \
  85. || return 1
  86. fi
  87. aPATTERN="s%^Modem = .*%Modem = /dev/${DEVMCONF}%"
  88. else
  89. aPATTERN="s%^Modem = .*%Modem = /dev/${DEVMCONF}\n#Modem = /dev/${DEVMALT}%"
  90. fi
  91. sed -i \
  92. -e '/#Modem =/d' \
  93. -e "$aPATTERN" /etc/wvdial.conf
  94. return 0
  95. } #v433 end
  96. modem_test_func() {
  97. [ "$DEVM" = "" ] && DEVM='invalid'
  98. /usr/lib/gtkdialog/box_splash -outline 0 -margin 4 -text "$(gettext 'Verifying modem is present...')" &
  99. X8PID=$! #v413
  100. IRQM=$(irq_from_device_func /dev/${DEVM})
  101. fuser -k /dev/${DEVM} 2>/dev/null #kill processing attached to device.
  102. chat_with_func /dev/$DEVM
  103. if [ $? -eq 0 ];then
  104. kill $X8PID #v413
  105. modem_device_to_conf_func $DEVM #v433 set tested dev
  106. if [ "$DEVM" = "$MODEMDEV" -a "$PARAM2" = "" ];then
  107. Xdialog --left --wmclass "pupdial" --title "$(gettext 'PupDial: modem test')" --no-cancel --msgbox "`eval_gettext \"Success, the modem responds as \\\$DEVM! (The modem is there; getting it to dial out is another matter!)\"`" 0 0
  108. else
  109. Xdialog --left --wmclass "pupdial" --title "$(gettext 'PupDial: modem test')" --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "${MSGSUCCESS}" 0 0
  110. if [ $? -eq 0 ];then
  111. /usr/lib/gtkdialog/box_splash -outline 0 -margin 4 -text "$(gettext 'Please wait, updating settings...')" &
  112. X9PID=$!
  113. ln -snf $DEVM /dev/modem
  114. waitmax 29 gen_modem_init_string > /dev/null #writes to /tmp/mymodeminitstring
  115. FLAGBADINITSTRING='no' #101220
  116. if [ -s /tmp/mymodeminitstring ];then
  117. INITSTRING="`cat /tmp/mymodeminitstring | sed 's/\&/\\\&/g' | tr -s ' '`" #v433 sed problem with &
  118. if [ "$INITSTRING" = "" -o "$INITSTRING" = " " ];then #101220
  119. FLAGBADINITSTRING='yes' #101220
  120. else
  121. bPATTERN="s/^Init3.*/Init3 = ${INITSTRING}/" #v413
  122. sed -i -e "$bPATTERN" /etc/wvdial.conf #v433
  123. fi
  124. else
  125. FLAGBADINITSTRING='yes' #101220
  126. fi
  127. kill $X9PID
  128. if [ "$FLAGBADINITSTRING" = "yes" ];then #101220
  129. Xdialog --left --wmclass "pupdial" --title "$(gettext 'PupDial: Initialization string')" --msgbox "$(gettext 'There is a problem, probing did not generate an initialization string. You could try\n
  130. unplugging the modem, reboot Puppy then plug-in the modem and try again with PupDial.\n
  131. Alternatively, in the PupDial main GUI window, try one of these strings in the second\n
  132. initialization-string entry box (write them down!)'):\n\n
  133. AT &FE0 V1 X1 &D2 &C1 s0=0\n
  134. AT Q0 V1 E1 S0=0 &C1 &D2" 0 0
  135. fi
  136. else
  137. #101203...
  138. INIT3="`cat /etc/wvdial.conf | grep '^Init3' | tr -d ' ' | cut -f 2-9 -d '='`"
  139. if [ "$INIT3" ];then
  140. Xdialog --left --wmclass "pupdial" --title "$(gettext 'PupDial: Initialization string')" --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "`gettext \"The PupDial configuration file /etc/wvdial.conf does have initialization\n
  141. strings in it from previous usage of PupDial. Would you like to reset\n
  142. them to the default ('ATZ' only)?\n
  143. Note, you might want to do this if you have changed modems and you know\n
  144. that the defaults are sufficient. If in doubt, click 'No'...\"`" 0 0
  145. if [ $? -eq 0 ];then
  146. #modify [Dialer Defaults] only...
  147. echo -n "" > /tmp/wvdial.conf-modemtest
  148. cat /etc/wvdial.conf |
  149. while read ONELINE
  150. do
  151. if [ "`echo -n "$ONELINE" | cut -c 1`" = "[" ];then
  152. WVSECTION=0
  153. [ "$ONELINE" = "[Dialer Defaults]" ] && WVSECTION=1
  154. fi
  155. if [ $WVSECTION -eq 1 ];then
  156. NEWONE="`echo -n "$ONELINE" | sed -e 's%^Init3 =.*%Init3 = %' -e 's%^Init2 =.*%Init2 = ATZ%' -e 's%^Init1 =.*%Init1 = %'`"
  157. echo "$NEWONE" >> /tmp/wvdial.conf-modemtest
  158. else
  159. echo "$ONELINE" >> /tmp/wvdial.conf-modemtest
  160. fi
  161. done
  162. cp -f /tmp/wvdial.conf-modemtest /etc/wvdial.conf
  163. fi
  164. fi
  165. fi
  166. rm -f /tmp/.pupdial_pin_sent #v433
  167. fi
  168. touch /tmp/.pupdial-modem_detected #v433
  169. else
  170. kill $X8PID #v413
  171. modem_device_to_conf_func $MODEMDEV #v433 set current dev
  172. Xdialog --left --wmclass "pupdial" --title "$(gettext 'PupDial: modem test')" --no-cancel --msgbox "$(gettext 'Sorry, the modem was not detected as') $DEVM." 0 0
  173. rm -f /tmp/.pupdial_pin_sent #v433
  174. rm -f /tmp/.pupdial-modem_detected #v433
  175. fi
  176. }
  177. modem_test_func
  178. ###END###