modemprobe 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #!/bin/sh
  2. #Barry Kauler GPL 2007.
  3. #called from pupdial.
  4. #v405 july 2008: total overhaul.
  5. #v465 rerwin: v413 added module names for wireless modems
  6. #v477 rerwin: v413 handle both lspci formats (replacing v003).
  7. #v477 rerwin: v413 added more module names for wireless modems
  8. #101202 bk: choose erase, remove /var/local/pupdial/hotpluggable (see pupdial).
  9. #101203 wvdialconf will ignore many devs that are not /dev/ttyS*, for example /dev/ttyAGS3 (agrmodem).
  10. #101206 changes to pupdial_init_hotpluggable.
  11. #120201 rodin.s: internationalized.
  12. #131219 zigbert: gui (gtkdialog) improvements.
  13. export TEXTDOMAIN=modemprobe
  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. MODEMDEV=""
  22. if [ -h /dev/modem ];then
  23. MODEMDEV="`readlink /dev/modem`"
  24. MSGMDM3="
  25. $(gettext 'PORT: /dev/modem is currently linked to port') ${MODEMDEV}."
  26. fi
  27. #find all loaded modem modules...
  28. KERNVER=`uname -r` #v433
  29. ALSAMODEMINFO="`cat /proc/asound/pcm 2>/dev/null | grep ' Modem :'`"
  30. USBSERIALMODS="" #v433
  31. lsmod | grep -q '^usbserial ' \
  32. && USBSERIALMODS=" `grep -w 'usbserial.ko' /lib/modules/$KERNVER/modules.dep | grep -o '^[^:]*' | rev | cut -f 1 -d / | rev | sed -e 's/\.ko$//' -e 's/^/\|\^/' | tr '\n' ' '`" #v433
  33. MODEMMODS="`lsmod | grep -E "^agrmodem |^cdc_acm |^esscom |^Intel536 |^[iI]ntel537 |^intel537[ES][AP] |^ltmodem |^martian_dev |^mwave |^pctel |^slamr |^slusb |^snd_via82xx_modem |^snd_atiixp_modem |^snd_intel8x0m |^snd_hda_intel |^dgcusbdcp |^hso |^ipwireless |^nozomi |^hcfpcihw |^hsfcadmus2 |^hsfcadmus2smart |^hsfmc97ali |^hsfmc97ati |^hsfmc97ich |^hsfmc97sis |^hsfmc97via |^hsfpcibasic2 |^hsfpcibasic2bry |^hsfpcibasic2hsfi |^hsfpcibasic2smart |^hsfpcibasic3 |^hsfusbcd2 |^rfcomm$USBSERIALMODS" | cut -f 1 -d ' '`" #v413 v416 v432 v433
  34. [ "$ALSAMODEMINFO" = "" ] && MODEMMODS="`echo "$MODEMMODS" | grep -v '^snd_'`"
  35. SNDMOD="`echo "$MODEMMODS" | grep '^snd_' | head -n 1`"
  36. #v413 For usbserial, reject it unless force-loaded with vendor ID (for usb modems).
  37. [ "`grep '^ADDLIST=' /etc/rc.d/MODULESCONFIG | grep ' usbserial:vendor='`" = "" ] && MODEMMODS="`echo "$MODEMMODS" | grep -v '^usbserial$'`" #v413
  38. MODEMMODS="`echo "$MODEMMODS" | sort | tr '\n' ' '`"
  39. MMCNT=`echo "$MODEMMODS" | wc -w`
  40. MSGMDM2=""
  41. case $MMCNT in
  42. 0)
  43. #v412 Check for any driver of a modem that is not detected automatically.
  44. #v433 This check is no longer valid, since any such modem is now supported through the udev rules file /etc/udev/rules.d/60-dialup-modem.rules and, thus, will have its driver loaded. Logic removed.
  45. MSGMDM1="$(gettext 'Well, Puppy did not detect anything at bootup, so if the modem was turned-on then it probably is not supported by any of the drivers in Puppy. Tough, you need to get another modem -- an old serial modem is best. There are some USB modems that work well.')"
  46. ;;
  47. 1)
  48. MSGMDM1="$(gettext 'Puppy did detect a modem at bootup, and loaded this driver:')
  49. <b>${MODEMMODS}${MSGMDM2}${MSGMDM3}</b>"
  50. ;;
  51. *)
  52. MSGMDM1="$(gettext 'Puppy detected more than one modem at bootup and and loaded these drivers:')
  53. <b>${MODEMMODS}${MSGMDM2}${MSGMDM3}</b>"
  54. ;;
  55. esac
  56. export PupDial_Modem_Probe='
  57. <window title="'$(gettext 'PupDial modem selection')'" icon-name="gtk-connect">
  58. <vbox space-expand="true" space-fill="true">
  59. '"`/usr/lib/gtkdialog/xml_info fixed modem_search.svg 60 "$(gettext "Most modems are autodetected by Puppy at bootup, but it has to be turned on! (or plugged in).")" "${MSGMDM1}"`"'
  60. <notebook labels="'$(gettext 'Automatic probing')'|'$(gettext 'Detection control')'|'$(gettext 'Manual probing')'" space-expand="true" space-fill="true">
  61. <vbox space-expand="true" space-fill="true">
  62. <frame>
  63. <vbox space-expand="false" space-fill="false">
  64. <hbox border-width="5" space-expand="true" space-fill="true">
  65. <text use-markup="true" space-expand="false" space-fill="false"><label>"'$(gettext "This will use the 'wvdialconf' program to <b>automatically probe and setup a modem</b> for use by PupDial. If successful will create or update /etc/wvdial.conf and will set /dev/modem as a link to the correct modem port.")'"</label></text>
  66. <text space-expand="true" space-fill="true"><label>""</label></text>
  67. <vbox space-expand="false" space-fill="false">
  68. <button image-position="2" space-expand="false" space-fill="false">
  69. <label>'$(gettext 'Probe')'</label>
  70. '"`/usr/lib/gtkdialog/xml_button-icon modem_search.svg huge`"'
  71. <action type="exit">SETUP</action>
  72. </button>
  73. <text space-expand="true" space-fill="true"><label>""</label></text>
  74. </vbox>
  75. </hbox>
  76. </vbox>
  77. </frame>
  78. </vbox>
  79. <vbox space-expand="true" space-fill="true">
  80. <vbox space-expand="true" space-fill="true">
  81. <frame>
  82. <vbox space-expand="false" space-fill="false">
  83. <hbox space-expand="true" space-fill="true">
  84. <text use-markup="true" space-expand="false" space-fill="false"><label>"'$(gettext '<b>Blacklist</b> a modem module. Note that you will then have to click the ERASE button, then reboot Puppy so that autodetection can re-occur.')'"</label></text>
  85. <text space-expand="true" space-fill="true"><label>""</label></text>
  86. <button space-expand="false" space-fill="false">
  87. '"`/usr/lib/gtkdialog/xml_button-icon modem_no.svg big`"'
  88. <action>/usr/sbin/bootmanager blacklist & </action>
  89. </button>
  90. </hbox>
  91. <text height-request="5"><label>""</label></text>
  92. <hbox space-expand="true" space-fill="true">
  93. <text use-markup="true" space-expand="false" space-fill="false"><label>"'$(gettext "<b>Erase</b> current modem settings. This will delete /dev/modem thus allowing a fresh auto-probe and will cancel the 'Modem' entry in /etc/wvdial.conf. CLICKING THIS BUTTON WILL CAUSE EXIT FROM PupDial. A REBOOT WILL THEN BE REQUIRED TO PROPERLY RE-DETECT INTERNAL MODEMS (for external modem not essential to reboot)")'"</label></text>
  94. <text space-expand="true" space-fill="true"><label>""</label></text>
  95. <vbox space-expand="false" space-fill="false">
  96. <text space-expand="true" space-fill="true"><label>""</label></text>
  97. <button space-expand="false" space-fill="false">
  98. '"`/usr/lib/gtkdialog/xml_button-icon clear.svg big`"'
  99. <action>/usr/sbin/modemprobe_erase</action>
  100. </button>
  101. </vbox>
  102. </hbox>
  103. <text height-request="5"><label>""</label></text>
  104. </vbox>
  105. </frame>
  106. </vbox>
  107. </vbox>
  108. <vbox space-expand="true" space-fill="true">
  109. '"`/usr/lib/gtkdialog/xml_info fixed modem_config.svg 60 "$(gettext "If the 'Automatic probe' for some reason didn't satisfy you, consider some manual probing...")"`"'
  110. <vbox space-expand="true" space-fill="true">
  111. <frame '$(gettext 'Serial hardware modem')'>
  112. <hbox border-width="5" space-expand="true" space-fill="true">
  113. <vbox space-expand="false" space-fill="false">
  114. <text space-expand="false" space-fill="false"><label>'$(gettext "If you have a true-hardware external serial or internal ISA card (or in some rare cases an internal PCI card), or think you might, click a button to probe. Note that 'ttyS0' is the same as 'com1' in DOS/Windows. Note also, 'ttyS0' is the most likely port, unless you have some other serial device such as a mouse. If the test is succesful then you will be offered to set /dev/modem and basic setup of /etc/wvdial.conf. (Note that these modems are not autodetected at bootup by Puppy, but are probed by the automatic probing.)")'</label></text>
  115. <text space-expand="true" space-fill="true"><label>""</label></text>
  116. </vbox>
  117. <text space-expand="true" space-fill="true"><label>""</label></text>
  118. <hbox space-expand="false" space-fill="false">
  119. <vbox space-expand="true" space-fill="true">
  120. <button>
  121. <label>" ttyS0 "</label>
  122. <action>/usr/sbin/modemtest ttyS0 &</action>
  123. <action type="exit">TTYSN</action>
  124. </button>
  125. <button>
  126. <label>" ttyS1 "</label>
  127. <action>/usr/sbin/modemtest ttyS1 &</action>
  128. <action type="exit">TTYSN</action>
  129. </button>
  130. <button>
  131. <label>" ttyS2 "</label>
  132. <action>/usr/sbin/modemtest ttyS2 &</action>
  133. <action type="exit">TTYSN</action>
  134. </button>
  135. <button>
  136. <label>" ttyS3 "</label>
  137. <action>/usr/sbin/modemtest ttyS3 &</action>
  138. <action type="exit">TTYSN</action>
  139. </button>
  140. <button>
  141. <label>" ttyS4 "</label>
  142. <action>/usr/sbin/modemtest ttyS4 &</action>
  143. <action type="exit">TTYSN</action>
  144. </button>
  145. </vbox>
  146. </hbox>
  147. </hbox>
  148. </frame>
  149. </vbox>
  150. </vbox>
  151. </notebook>
  152. <hbox space-expand="false" space-fill="false">
  153. <button space-expand="false" space-fill="false">
  154. <label>'$(gettext "Help")'</label>
  155. '"`/usr/lib/gtkdialog/xml_button-icon help`"'
  156. <action>/usr/sbin/modemprobe_help &</action>
  157. </button>
  158. <text space-expand="true" space-fill="true"><label>""</label></text>
  159. <button space-expand="false" space-fill="false">
  160. <label>'$(gettext "Quit")'</label>
  161. '"`/usr/lib/gtkdialog/xml_button-icon quit`"'
  162. <action>exit:Quit</action>
  163. </button>
  164. </hbox>
  165. </vbox>
  166. </window>'
  167. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  168. RETSTRING="`gtkdialog -p PupDial_Modem_Probe`"
  169. #v405 getting some weird stuff on stdout from gtkdialog3, fix...
  170. #all lines must have format: variable="value" ...
  171. xRETSTRING="`echo "$RETSTRING" | grep -E '^[a-zA-Z0-9]+=\".*\"$'`"
  172. eval "$xRETSTRING"
  173. [ "$EXIT" != "SETUP" ] && exit
  174. #101202
  175. if [ ! -f /var/local/pupdial/hotpluggable ];then #101202 see also pupdial, erase button above.
  176. export HOTDIALOG="
  177. <window title=\"$(gettext 'PupDial modem Internet dialer')\" icon-name=\"gtk-connect\">
  178. <vbox>
  179. <text><label>$(gettext 'Before probing, a basic question: do you want to connect to the Internet using an internal fixed modem, or a removable (USB, serial, PCMCIA) modem?')</label></text>
  180. <text><label>`gettext \"The reason for asking this, is an internal modem will have been detected at bootup, but a 'hotpluggable' external modem may not have have been detected if plugged in after bootup. Also, if you have both, say an internal analog dialup modem, plus a USB modem, PupDial may choose the wrong one -- ticking or unticking the checkbox here will avoid that confusion...\"`</label></text>
  181. <checkbox><label>$(gettext 'Tick checkbox if external modem')</label><variable>CHK_HOT</variable></checkbox>
  182. <hbox><button ok></button></hbox>
  183. </vbox>
  184. </window>"
  185. RETSTRING="`gtkdialog --center -p HOTDIALOG`"
  186. CHK_HOT="`echo "$RETSTRING" | grep '^CHK_HOT' | cut -f 2 -d '"'`" #'geany
  187. [ "$CHK_HOT" = "" ] && CHK_HOT='false'
  188. echo -n "$CHK_HOT" > /var/local/pupdial/hotpluggable
  189. if [ "$CHK_HOT" = "true" ];then
  190. #rm -f /dev/modem
  191. pupdial_init_hotpluggable
  192. fi
  193. fi
  194. MODEMDEV=''
  195. [ -h /dev/modem ] && MODEMDEV="`readlink /dev/modem`"
  196. #101203 wvdialconf will ignore many devs that are not /dev/ttyS*, for example /dev/ttyAGS3 (agrmodem)...
  197. #note, also have this same code in /usr/sbin/pupdial.
  198. if [ "$MODEMDEV" ];then
  199. MODEMDEV="`echo -n "$MODEMDEV" | sed -e 's%/dev/%%'`"
  200. MODEMBASE="`basename $MODEMDEV`" #ex: modems/mwave becomes: mwave
  201. if [ "`echo -n "$MODEMBASE" | cut -c 1-4`" != "ttyS" ];then
  202. #some that are recognised by wvdialconf: ttyUSB* (v1.51), ttyLT* (v1.50), ttyACM*, ttyI* (v0.12)
  203. OK=0
  204. if [ "`echo -n "$MODEMBASE" | cut -c 1-3`" = "tty" ];then
  205. CHARS3="`echo -n "$MODEMBASE" | cut -c 4-6`"
  206. case $CHARS3 in
  207. USB) OK=1 ;;
  208. LT*) OK=1 ;;
  209. ACM) OK=1 ;;
  210. I*) OK=1 ;;
  211. esac
  212. fi
  213. if [ $OK -eq 0 ];then
  214. SMODEMDEV='ttyS_'"`echo -n "$MODEMBASE" | sed -e 's%^tty%%' | cut -c 1-20`"
  215. ln -snf $MODEMDEV /dev/$SMODEMDEV
  216. ln -snf $SMODEMDEV /dev/modem #so that wvdialconf will look here first.
  217. MODEMDEV="$SMODEMDEV"
  218. fi
  219. fi
  220. fi
  221. /usr/lib/gtkdialog/box_splash -placement center -text "$(gettext 'Please wait, probing for modems...')" &
  222. X1PID=$!
  223. #100918 If no modem selected, check bluetooth modem and set as /dev/modem...
  224. if [ "$MODEMDEV" = "" ] && which rfcomm >/dev/null;then
  225. BTMODEMDEVS="`get_bluetooth_connection DUN`"
  226. for ONEBTMODEMDEV in $BTMODEMDEVS;do
  227. RFCOMMNUM="`echo "$ONEBTMODEMDEV" | grep -o [0-9]*`"
  228. if [ "`rfcomm $RFCOMMNUM | grep 'clean'`" != "" ];then
  229. rfcomm $ONEBTMODEMDEV connect &
  230. X10PID=$!
  231. sleep 5
  232. fi
  233. [ "`rfcomm $RFCOMMNUM | grep 'connected'`" != "" ] \
  234. && ln -snf $BTMODEMDEV /dev/modem \
  235. && break
  236. done
  237. fi
  238. rm -f /tmp/wvdial.conf 2>/dev/null
  239. #v4.06 begin
  240. DEVM=""
  241. [ -f /etc/wvdial.conf ] && CONFDIR="etc" || CONFDIR="tmp"
  242. wvdialconf /$CONFDIR/wvdial.conf >/tmp/logwvdialprobe 2>&1
  243. RETVAL=$?
  244. if [ $RETVAL -eq 0 ];then #found a modem and set it in wvdial.conf
  245. if [ "`grep '/dev/modem' /$CONFDIR/wvdial.conf`" != "" ];then #modem = /dev/modem - substitute /dev/modem target
  246. SEDSCRIPT="s%/dev/modem%/dev/`readlink /dev/modem`%" #v416
  247. sed -i -e "$SEDSCRIPT" /$CONFDIR/wvdial.conf #v416
  248. elif [ "`grep '/dev/ttyS_' /$CONFDIR/wvdial.conf`" != "" ];then
  249. #Convert ttyS_ link name to actual node name (e.g., ttyS_536ep -> 536ep)
  250. TMPDEVM="`cat /$CONFDIR/wvdial.conf | tr -s ' ' | grep '^Modem = ' | head -n 1 | cut -f 3 -d ' ' | cut -f 3 -d '/'`" #file name
  251. if [ -h /dev/$TMPDEVM ];then #it's a link to the correct device node name
  252. SEDSCRIPT="s%/dev/$TMPDEVM%/dev/`readlink /dev/$TMPDEVM`%" #v416
  253. sed -i -e "$SEDSCRIPT" /$CONFDIR/wvdial.conf #v416
  254. fi
  255. fi
  256. DEVM="`cat /$CONFDIR/wvdial.conf | tr -s ' ' | grep '^Modem = ' | head -n 1 | cut -f 3,4 -d '/'`" #v433
  257. #v432 Add possible alternate modem device
  258. sed -i -e '/#Modem =/d' /$CONFDIR/wvdial.conf
  259. DEVMALT="`get_modem_alternate_device $DEVM`"
  260. [ "$DEVMALT" != "" ] \
  261. && aPATTERN="s%^Modem = .*%&\n#Modem = /dev/${DEVMALT}%" \
  262. && sed -i -e "$aPATTERN" /$CONFDIR/wvdial.conf #v432 end
  263. else #v433
  264. [ "$MODEMDEV" = "" ] && rm -f /dev/modem #v433
  265. fi
  266. #v4.06 end
  267. kill $X1PID
  268. if [ "$DEVM" != "" ];then #4.06 probe found a modem (and not /dev/modem)
  269. ln -snf $DEVM /dev/modem #v4.06 v433
  270. touch /tmp/.pupdial-modem_detected #v433
  271. if [ -f /tmp/wvdial.conf ];then
  272. grep -v '^;' /tmp/wvdial.conf > /etc/wvdial.conf
  273. rm -f /tmp/wvdial.conf
  274. echo 'Carrier Check = no
  275. Dial Command = ATDT
  276. [Dialer isp1]
  277. Phone = MYISPPHONENUM
  278. Username = MYUSERNAME
  279. Password = MYPASSWORD
  280. [Dialer isp1apn]
  281. Init5 = AT+CGDCONT=1,\"IP\",\"\"
  282. [Dialer isp2]
  283. Phone = MY2ISPPHONENUM
  284. Username = MY2USERNAME
  285. Password = MY2PASSWORD
  286. [Dialer isp2apn]
  287. Init5 = AT+CGDCONT=1,\"IP\",\"\"
  288. [Dialer pin]
  289. Init1 = AT+CPIN=
  290. [Dialer wireless]
  291. #Init4 = AT+COPS=0,0,\"MYOPS\",
  292. #Init6 = AT+CGEQMIN=1,4,64,384,64,384
  293. #Init7 = AT+CGEQREQ=1,4,64,384,64,384
  294. #Init8 = AT+CGDCONT?
  295. #Init9 = AT+COPS?' >> /etc/wvdial.conf
  296. fi
  297. else #v433
  298. rm -f /tmp/.pupdial-modem_detected #v433
  299. fi
  300. sync
  301. #leafpad /tmp/logwvdialprobe
  302. exit $RETVAL #v4.06 Notify caller whether wvdialconf found a modem