s243a

/usr/sbin/net-setup-sh (Precise 5.7.1)

Apr 26th, 2015
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 58.96 KB | None | 0 0
  1. #!/bin/bash
  2. #(c) copyright Barry Kauler 2004 www.puppylinux.org
  3. #Puppy ethernet network setup script.
  4. #I got some bits of code from:
  5. # trivial-net-setup, by Seth David Schoen <[email protected]> (c)2002
  6. # and the little executables and, or, dotquad from the
  7. # lnx-bbx Linux project. ipcalc app from Redhat 7.
  8. # Thanks to GuestToo and other guys on the Puppy Forum for bug finding.
  9. # Rarsa (Raul Suarez) reorganized the code and cleaned up the user interface
  10. # Ported to gtkdialog3 and abused by Dougal, June 2007
  11. # Update: Jul.  4th: redesign main dialog, change "Load module" dialog
  12. # Update: Jul. 10th: change INTERFACEBUTTONS format, add findInterfaceInfo function
  13. # Update: Jul. 11th: move findLoadedModules into tryLoadModule
  14. # Update: Jul. 12th: move "save" and "unload" buttons out of main dialog
  15. # Update: Jul. 13th: add "sleep 3" after loading usb modules, fixed bug in findInterfaceInfo
  16. # Update: Jul. 13th: fix problem with tree height
  17. # Update: Jul. 19th: add recognition of prism2_usb interfaces as wireless
  18. # Update: Aug.  1st: fix spelling...
  19. # Update: Dec. 30th: add "-I ''" to lines 840 and 863 to fix Rerwin's problem)
  20. # Update: Mar. 2008: squash dialogs down a bit
  21. # Update: Jun. 25th: add some updates from Barry's version:
  22. #                       - ndiswrapper check for native module already loaded
  23. #                       - compat for dhcpcd using /var
  24. #                       - ndiswrapper mention in text for "load module" button
  25. #                    also improve finding device-info
  26. # Update: Jun. 29th: add check for /sys/class/net/$INTERFACE/wireless (in checkIfIsWireless)
  27. # Update: Jul.  6th: add use of cleanUpInterface
  28. # Update: Jul.  7th: cancel the cd into APPDIR!
  29. # Update: Jul. 10th: disable all the usb-autoloading code -- udev handles it
  30. # Update: Jul. 10th: add cleanUpTmp
  31. # Update: Jul. 15th: convert to new config setup
  32. # Update: Jul. 20th: try and add support for static ip with wireless
  33. # Update: Jul. 23rd: add message for failed wireless profile config
  34. #                    change DEBUG_OUTPUT for the debug case to stderr
  35. # Update: Jul. 27th: remove usage of lspci from pcmcia check
  36. #                    find info on usb devices directly from /sys
  37. # Update: Jul. 28th: add getting interface info from module, if none found otherwise
  38. # Update: Jul. 30th: change redirection to DEBUG_OUTPUT to _append_
  39. # Update: Aug.  1st: move configuration files into /etc/network-wizard
  40. # Update: Aug. 18th: reinstate IS_WIRELESS, needed for message in testInterface, also add to config file
  41. # Update: Aug. 23rd: add use of killDhcpcd
  42. # Update: Sep.  1st: add firewire code
  43. # Update: Sep.  3rd: add blanking of gateway if it's 0.0.0.0
  44. #                    fix one nameserver being read twice in showStaticIPWindow
  45. # Update: Sep.  4th: if user blanked dns servers, set them to 0.0.0.0
  46. # Update: Sep. 15th: disable bringing interface down/up when setting static ip
  47. #                    add "dev $INTERFACE" to route commands
  48. # Update: Sep. 16th: add clean_up_gtkdialog support and rename dialog variables
  49. #                    replace all `` subshells with $()
  50. # Update: Sep. 18th: add "non-Vista" comment for Ndiswrapper button.
  51. # Update: Sep. 24th: kill dhcpcd if it returns error!
  52. #                    move setupDHCP over to wag-profiles.sh, so it can be used by rc.network
  53. # Update: Sep. 28th: add unloadSpecificModule: "Unload" button in "Load Module" dialog
  54. # Update: Sep. 30th: rewrite loadSpecificModule in gtkdialog
  55. #                    change tryLoadModule to recognize module params and add ERROR display
  56. #                    change various error messages to use giveErrorDialog+ERROR
  57. # Update: Oct.  5th: add askWhichInterfaceForNdiswrapper and offerToBlacklistModule
  58. #                    move ndiswrapper to a separate tab in the "Load module" dialog
  59. # Update: Oct. 22nd: add Barry's code to clean up old-wizard config files
  60. # Update: Oct. 23rd: in showLoadModuleWindow, add sleeping up to 10sec to wait for new int.
  61. #                    add blacklist_module, to handle adding module to skiplist
  62. #                    remove the "dev..." from the end of route commands...
  63. # Update: Oct. 25th: start localizing
  64. # Update: Oct. 26th: finish localizing
  65. #                    add giveAcxDialog, to offer the user to blacklist rather than unload
  66. # Update: Oct. 28th: tidy up the code for finding new interfaces
  67. # Update: Oct. 31st: check for locale files both of type "ab_CD" and "ab"
  68. # Update: Nov.  7th: add deleting old backups of resolve.conf
  69. # Update: Feb. 8th 2009: Clean up static ip info from profile if changed (PaulBx1 suggested)
  70. # Update: Feb. 22nd: change the backing up of resolve.conf so it only saves as resolv.conf.old
  71. # Update: Mar. 19th: add wireless scan files to cleanUpTmp, change shebang to bash
  72. # Update: Apr.  1st: improve finding of usb device info from /sys
  73. # 25feb10: shinobar: old and new ifplugstatus
  74. #111015 BK: strip out chars that might upset gtkdialog.
  75.  
  76. APPDIR="$(dirname $0)"
  77. [ "$APPDIR" = "." ] && APPDIR="$(pwd)"
  78.  
  79. # Dougal: add localization
  80. mo=net-setup.mo
  81. #lng=${LANG%.*}
  82. # always start by sourceing the English version (to fill in gaps)
  83. . "/usr/share/locale/en/LC_MESSAGES/$mo"
  84. if [ -f "/usr/share/locale/${LANG%.*}/LC_MESSAGES/$mo" ];then
  85.   . "/usr/share/locale/${LANG%.*}/LC_MESSAGES/$mo"
  86. elif [ -f "/usr/share/locale/${LANG%_*}/LC_MESSAGES/$mo" ];then
  87.   . "/usr/share/locale/${LANG%_*}/LC_MESSAGES/$mo"
  88. fi
  89.  
  90. # Check if output should go to the console
  91. if [ "${1}" = "-d" ] ; then
  92.     DEBUG_OUTPUT=/dev/stderr
  93. else
  94.     DEBUG_OUTPUT=/dev/null
  95. fi
  96.  
  97. # basic configuration info for interface
  98. # named $HWADDRESS.conf (assuming the HWaddress is more unique than interface name...)
  99. # mainly intended to know if interface has been "configured"...
  100. NETWORK_INTERFACES_DIR='/etc/network-wizard/network/interfaces'
  101. [ -d $NETWORK_INTERFACES_DIR ] || mkdir -p $NETWORK_INTERFACES_DIR
  102.  
  103. # file used to list blacklisted modules
  104. #BLACKLIST_FILE="/etc/rc.d/blacklisted-modules.$(uname -r)"
  105.  
  106. #  Dougal: need some elegant way to find out if we're running from X
  107. #+ (pidof X isn't good, since we might be running in the background at boot...)
  108. # for now, just set it from here (wag-profiles isn't really used alone)
  109. HAVEX='yes'
  110.  
  111. ## Dougal: put this into a variable
  112. BLANK_IMAGE=/usr/share/pixmaps/net-setup_btnsize.png
  113.  
  114. #=============================================================================
  115. #============= FUNCTIONS USED IN THE SCRIPT ==============
  116. #=============================================================================
  117. . ${APPDIR}/ndiswrapperGUI.sh
  118. . ${APPDIR}/wag-profiles.sh
  119.  
  120. showMainWindow()
  121. {
  122.     MAIN_RESPONSE=""
  123.  
  124.     while true
  125.     do
  126.  
  127.         buildMainWindow
  128.  
  129.         I=$IFS; IFS=""
  130.         for STATEMENT in  $(gtkdialog3 --program NETWIZ_Main_Window); do
  131.             eval $STATEMENT 2>/dev/null
  132.         done
  133.         IFS=$I
  134.         clean_up_gtkdialog NETWIZ_Main_Window
  135.         unset NETWIZ_Main_Window
  136.  
  137.         # Dougal: this is simpler than all the grep business.
  138.         # Could integrate into main case-structure, but not sure about MAIN_RESPONSE
  139.         case "$EXIT" in
  140.           Interface_*) INTERFACE=${EXIT#Interface_} ; MAIN_RESPONSE=13 ;;
  141.           *) MAIN_RESPONSE=${EXIT} ;;
  142.         esac
  143.        
  144.         # Dougal: blank the "Done" button, in case we go to 13 and back
  145.         DONEBUTTON=""
  146.            
  147.         case $MAIN_RESPONSE in
  148.             10) showLoadModuleWindow ;;
  149.             17) saveNewModule ;;
  150.             18) unloadNewModule ;;
  151.             19) break ;;
  152.             13) showConfigureInterfaceWindow "$INTERFACE" ;;
  153.             66) AutoloadUSBmodules ;;
  154.             #21) showHelp  ;;
  155.             abort) break ;;
  156.         esac
  157.  
  158.     done
  159.  
  160. } # end of showMainWindow
  161.  
  162. #=============================================================================
  163. getInterfaceList(){
  164.   #we need to know what ethernet interfaces are there...
  165.   INTERFACE_NUM=$(ifconfig -a | grep -Fc 'Link encap:Ethernet')
  166.   INTERFACES="$(ifconfig -a | grep -F 'Link encap:Ethernet' | cut -f1 -d' ' | tr '\n' ' ')"
  167.   # Dougal: this is for ethernet-over-firewire
  168.   for ONE in $(grep -w 24 /sys/class/net/*/type | cut -d '/' -f5) ; do
  169.     case $INTERFACES in *$ONE*) continue ;; esac
  170.     INTERFACES="$INTERFACES $ONE"
  171.     INTERFACE_NUM=$((INTERFACE_NUM+1))
  172.   done
  173.   INTERFACEBUTTONS=""
  174.   INTERFACE_DATA=""
  175. }
  176.  
  177. #=============================================================================
  178. refreshMainWindowInfo ()
  179. {
  180.   # Dougal: comment out and move to the showLoadModuleWindow -- only used there...
  181.   #findLoadedModules
  182.   getInterfaceList
  183.   #rm -f /tmp/interface-modules
  184.  
  185.   for INTERFACE in $INTERFACES
  186.   do
  187.     [ "$INTERFACE" ] || continue
  188.     # Dougal: use function for finding/setting info to be used in tree (below)
  189.     findInterfaceInfo "$INTERFACE"
  190.    
  191.     ## Dougal: use a tree to display interface info
  192.     INTERFACE_DATA="$INTERFACE_DATA <item>$INTERFACE|$INTTYPE|$FI_DRIVER|$TYPE: $INFO</item>"
  193.     # add to display list
  194.     INTERFACEBUTTONS="
  195. ${INTERFACEBUTTONS}
  196. <vbox>
  197.     <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  198.     <button>
  199.         <label>${INTERFACE}</label>
  200.         <action>EXIT:Interface_${INTERFACE}</action>
  201.     </button>  
  202. </vbox>"
  203.   done
  204.  
  205.   if [ "$INTERFACE_DATA" ] ; then
  206.     # Get the right height for the tree...
  207.     case "$INTERFACE_NUM" in
  208.      1) HEIGHT=70 ;;
  209.      2) HEIGHT=100 ;;
  210.      3) HEIGHT=125 ;;
  211.      4) HEIGHT=150 ;;
  212.      5) HEIGHT=175 ;;
  213.      6) HEIGHT=200 ;;
  214.     esac
  215.     INTERFACEBUTTONS="
  216.    <tree>
  217.         <label>$L_LABEL_Interface_Tree_Header</label>
  218.         $INTERFACE_DATA
  219.         <height>$HEIGHT</height><width>350</width>
  220.         <variable>SELECTED_INTERFACE</variable>
  221.     </tree>
  222.     <hbox>
  223.         $INTERFACEBUTTONS
  224.     </hbox>"
  225.   fi
  226.  
  227.   case $INTERFACE_NUM in
  228.     0) # no interfaces
  229.       echo "$L_ECHO_No_Interfaces_Message" > /tmp/net-setup_MSGINTERFACES.txt
  230.       ;;
  231.     1) # only one
  232.       echo "$L_ECHO_One_Interface_Message"  > /tmp/net-setup_MSGINTERFACES.txt
  233.       ;;
  234.     *) # more than one interface
  235.       echo "$L_ECHO_Multiple_Interfaces_Message"  > /tmp/net-setup_MSGINTERFACES.txt
  236.       ;;
  237.   esac
  238.  
  239.     #echo "Puppy has done a quick check to see which network driver modules are currently loaded. Here they are (the relevant interface is in brackets):
  240.  #${LOADEDETH}" > /tmp/net-setup_MSGMODULES.txt
  241.  
  242. } # end refreshMainWindowInfo
  243.  
  244. #=============================================================================
  245. buildMainWindow ()
  246. {
  247.     echo "${TOPMSG}" > /tmp/net-setup_TOPMSG.txt
  248.  
  249.  
  250.     export NETWIZ_Main_Window="<window title=\"$L_TITLE_Puppy_Network_Wizard\" icon-name=\"gtk-network\" window-position=\"1\">
  251. <vbox>
  252.    
  253.     <text><label>\"$(cat /tmp/net-setup_TOPMSG.txt)\"</label></text>   
  254.     <frame  $L_FRAME_Interfaces >
  255.         <vbox>
  256.             <text>
  257.                 <label>\"$(cat /tmp/net-setup_MSGINTERFACES.txt)\"</label>
  258.             </text>
  259.            
  260.             ${INTERFACEBUTTONS}
  261.         </vbox>
  262.     </frame>
  263.    
  264.     <frame  $L_FRAME_Network_Modules >
  265.       ${USB_MODULE_BUTTON}
  266.       ${MODULEBUTTONS}
  267.     </frame>
  268.     <hbox>
  269.         <button help>
  270.             <action>$HELP_COMMAND > /dev/null 2>&1 & </action>
  271.         </button>
  272.         <button>
  273.              <label>$L_BUTTON_Exit</label>
  274.              <input file stock=\"gtk-quit\"></input>
  275.              <action>EXIT:19</action>
  276.         </button>
  277.     </hbox>
  278. </vbox>
  279. </window>"
  280. }
  281.  
  282. #=============================================================================
  283. showLoadModuleWindow()
  284. {
  285.   findLoadedModules
  286.   echo -n "" > /tmp/ethmoduleyesload.txt
  287.   MODULELIST=$(cat /etc/networkmodules | sort | tr "\n" " ")
  288.   # Dougal: create list of modules (pipe delimited)
  289.   sort /etc/networkmodules | tr '"' '|' | tr ':' '|' | sed 's%|$%%g' | tr -s ' ' >/tmp/module-list
  290.  
  291.   export NETWIZ_LOAD_MODULE_DIALOG="<window title=\"$L_TITLE_Load_Network_Module\" icon-name=\"gtk-execute\" window-position=\"1\">
  292. <vbox>
  293. <notebook labels=\"$L_NOTEBOOK_Modules_Header\">
  294.  <vbox>
  295.   <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  296.   <hbox>
  297.    <text><label>\"$L_TEXT_Select_Module_Tab\"</label></text>
  298.    <text><label>\"     \"</label></text>
  299.    <vbox>
  300.     <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  301.     <button>
  302.       <label>$L_BUTTON_Load</label>
  303.       <input file stock=\"gtk-apply\"></input>
  304.       <action>EXIT:load</action>
  305.     </button>
  306.    </vbox>
  307.   </hbox>
  308.   <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  309.   <tree>
  310.    <label>$L_LABEL_Module_Tree_Header</label>
  311.    <input>cat /tmp/module-list</input>
  312.    <height>200</height><width>550</width>
  313.    <variable>NEW_MODULE</variable>
  314.   </tree>
  315.  </vbox>
  316.  
  317.  <vbox>
  318.   <text><label>\"     \"</label></text>
  319.  
  320.    <text use-markup=\"true\">
  321.     <label>\"$L_TEXT_Ndiswrapper_Tab\"</label>
  322.    </text>
  323.    <text>
  324.     <label>\"     \"</label>
  325.    </text>
  326.     <hbox>
  327.      <button>
  328.       <label>$L_BUTTON_Use_Ndiswrapper</label>
  329.       <input file stock=\"gtk-execute\"></input>
  330.       <action>EXIT:ndiswrapper</action>
  331.     </button>
  332.    </hbox>
  333.  </vbox>
  334.  
  335.  <vbox>
  336.   <text><label>\"     \"</label></text>
  337.   <hbox>
  338.    <text use-markup=\"true\">
  339.     <label>\"$L_TEXT_More_Tab\"</label>
  340.    </text>
  341.    <text>
  342.     <label>\"     \"</label>
  343.    </text>
  344.    <vbox>
  345.     <text>
  346.      <label>\"     \"</label>
  347.     </text>
  348.     <button>
  349.       <label>$L_BUTTON_Specify</label>
  350.       <input file stock=\"gtk-index\"></input>
  351.       <action>EXIT:specify</action>
  352.     </button>
  353.     <button>
  354.       <label>$L_BUTTON_Unload</label>
  355.       <input file stock=\"gtk-undo\"></input>
  356.       <action>EXIT:unload</action>
  357.     </button>
  358.     <button>
  359.       <label>$L_BUTTON_Autoprobe</label>
  360.       <input file stock=\"gtk-refresh\"></input>
  361.       <action>EXIT:auto</action>
  362.     </button>
  363.    </vbox>
  364.   </hbox>
  365.  </vbox>
  366.  
  367.  </notebook>
  368.  <hbox>
  369.   <button cancel></button>
  370.  </hbox>
  371. </vbox>
  372. </window>"
  373.  
  374.   I=$IFS; IFS=""
  375.   for STATEMENT in  $(gtkdialog3 --program NETWIZ_LOAD_MODULE_DIALOG); do
  376.     eval $STATEMENT 2>/dev/null
  377.   done
  378.   IFS=$I
  379.   clean_up_gtkdialog NETWIZ_LOAD_MODULE_DIALOG
  380.   unset NETWIZ_LOAD_MODULE_DIALOG
  381.  
  382.   case "$EXIT" in
  383.     auto)   autoLoadModule ;;
  384.     unload) unloadSpecificModule ; showLoadModuleWindow ;  return ;;
  385.     ndiswrapper)    loadNdiswrapperModule ;;
  386.     specify)    loadSpecificModule ;;
  387.     load)   if [ "$NEW_MODULE" ] ; then
  388.               tryLoadModule "$NEW_MODULE"
  389.             else
  390.               TOPMSG="$L_TOPMSG_Load_Module_None_Selected"
  391.             fi ;;
  392.     cancel) TOPMSG="$L_TOPMSG_Load_Module_Cancel"  ;;
  393.   esac
  394.  
  395.   #NEWLOADED="$(cat /tmp/ethmoduleyesload.txt)"
  396.   #NEWLOADf1=${NEWLOADED%% *} #remove any extra params.
  397.   read NEWLOADED </tmp/ethmoduleyesload.txt
  398.   NEWLOADf1=${NEWLOADED%% *}
  399.   if [ "${NEWLOADED}" ];then
  400.     ##### add new code here: find new interface, then give window naming it
  401.     ##### and offering to save/unload
  402.     ##### ONLY AFTER that refresh main window  
  403.     # Save the old interface list
  404.     OLD_INTERFACES="$INTERFACES"
  405.     OLD_NUM="$INTERFACE_NUM"
  406.     # Dougal: add sleeping a few seconds, in case it takes time to initialize
  407.     for i in $(seq 1 10)
  408.     do
  409.       #NEW_NUM=$(ifconfig -a | grep -Fc "Link encap:Ethernet")
  410.       getInterfaceList
  411.       [ $INTERFACE_NUM -gt $OLD_NUM ] && break
  412.       sleep 1
  413.     done
  414.    
  415.     #NEW_NUM=$(ifconfig -a | grep -Fc "Link encap:Ethernet")
  416.     NEW_INTERFACES=""
  417.     NEW_DATA=""
  418.     NEW_INTERFACES_FRAME=""
  419.     if [ $INTERFACE_NUM -gt $OLD_NUM ] ; then # got a new interface
  420.       DIFF=$((INTERFACE_NUM-OLD_NUM))
  421.      
  422.       #for ANEW in $(ifconfig -a | grep -F 'Link encap:Ethernet' |cut -f1 -d' ')
  423.       for ANEW in $INTERFACES
  424.       do
  425.         case "$OLD_INTERFACES" in *$ANEW*) continue ;; esac
  426.         # If we got here, it's a new one
  427.         NEW_INTERFACES="$NEW_INTERFACES $ANEW"
  428.       done
  429.      
  430.       for ANEW in $NEW_INTERFACES
  431.       do
  432.         # get info for it
  433.         findInterfaceInfo $ANEW
  434.         # add to code for new interface dialog
  435.         NEW_DATA="$NEW_DATA <item>$ANEW|$INTTYPE|$FI_DRIVER|$TYPE: $INFO</item>"
  436.       done
  437.       # Set message telling about new interfaces
  438.       if [ $DIFF -eq 1 ] ; then
  439.         NEW_MESSAGE="$L_MESSAGE_One_New_Interface"
  440.       else
  441.         NEW_MESSAGE="$L_MESSAGE_Multiple_New_Interfaces"
  442.       fi
  443.       # create the frame with the new interfaces
  444.       case "$DIFF" in
  445.        1) HEIGHT=65 ;;
  446.        2) HEIGHT=100 ;;
  447.        3) HEIGHT=125 ;;
  448.        4) HEIGHT=150 ;;
  449.        5) HEIGHT=175 ;;
  450.        6) HEIGHT=200 ;;
  451.       esac
  452.       NEW_INTERFACES_CODE="
  453.  <frame  $L_FRAME_New_Interfaces >
  454.    <text><label>$NEW_MESSAGE</label></text>
  455.    <tree>
  456.         <label>$L_LABEL_New_Interfaces_Tree_Header</label>
  457.         $NEW_DATA
  458.         <height>$HEIGHT</height><width>400</width>
  459.         <variable>SELECTED_INTERFACE</variable>
  460.     </tree>
  461.  </frame>
  462.  
  463.    <text>
  464.      <label>\"$L_TEXT_New_Interfaces_p1 $NEWLOADf1 $L_TEXT_New_Interfaces_p2\"</label>
  465.    </text>
  466.    <hbox>
  467.      
  468.       <button>
  469.         <label>$L_BUTTON_Save</label>
  470.         <input file stock=\"gtk-save\"></input>
  471.         <action>EXIT:save</action>
  472.       </button>
  473.    
  474.  "
  475.    
  476.     else #if [ $NEW_NUM -gt $INTERFACE_NUM ] ; then
  477.       NEW_INTERFACES_CODE="
  478.  <text><label>$L_TEXT_No_New_Interfaces1</label></text>
  479.  <text><label>\" \"</label></text>
  480.  
  481.    <text>
  482.      <label>\"$L_TEXT_No_New_Interfaces2\"</label>
  483.    </text>    
  484.    <hbox>
  485.       <button>
  486.         <label>$L_BUTTON_Unload</label>
  487.         <input file stock=\"gtk-undo\"></input>
  488.         <action>EXIT:unload</action>
  489.       </button>
  490.    "
  491.     fi #if [ $NEW_NUM -gt $INTERFACE_NUM ]
  492.     # give dialog with two buttons and appropriate message
  493.     export NETWIZ_NEW_MODULE_DIALOG="<window title=\"$L_TITLE_New_Module_Loaded\" icon-name=\"gtk-execute\" window-position=\"1\">
  494. <vbox>
  495.  <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  496.  <text><label>\"$L_TEXT_New_Module_Loaded $NEWLOADf1\"</label></text>
  497.  <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  498.  $NEW_INTERFACES_CODE
  499.  
  500.   <button cancel></button>
  501.  </hbox>
  502. </vbox>
  503. </window>"
  504.    
  505.     # Run new dialog
  506.     I=$IFS; IFS=""
  507.     for STATEMENT in  $(gtkdialog3 --program NETWIZ_NEW_MODULE_DIALOG); do
  508.       eval $STATEMENT 2>/dev/null
  509.     done
  510.     IFS=$I
  511.     clean_up_gtkdialog NETWIZ_NEW_MODULE_DIALOG
  512.     unset NETWIZ_NEW_MODULE_DIALOG
  513.    
  514.     # Do what we're asked
  515.     case "$EXIT" in
  516.      save)
  517.        saveNewModule
  518.        TOPMSG="$L_TOPMSG_New_Module_Save"
  519.        ;;
  520.      unload)
  521.        unloadNewModule
  522.        TOPMSG="$L_TOPMSG_New_Module_Unload"
  523.        ;;
  524.      *) TOPMSG="$L_TOPMSG_New_Module_Cancelled"
  525.        ;;
  526.     esac
  527.    
  528.     # refresh main
  529.     refreshMainWindowInfo
  530.     # set new message for main dialog
  531.     #TOPMSG="REPORT ON LOADING OF MODULE: Module '$NEWLOADf1' successfully loaded"
  532.    
  533.   else
  534.     BGCOLOR="#ffc0c0"
  535.     TOPMSG="$L_TOPMSG_Load_Module_None_Loaded"
  536.   fi #if [ "${NEWLOADED}" ];then
  537. } # end of showLoadModuleWindow
  538.  
  539. #=============================================================================
  540. tryLoadModule ()
  541. {
  542.     #  Dougal: this used to be called with the argument quoted, which was
  543.     #+ bad, since if the user specifies parameters, the grep will return
  544.     #+ false, while the driver might already be loaded! Trying to reload
  545.     #+ will then not do anything, I assume... so remove quotes (in loadSpecificModule).
  546.     MODULE_NAME="$1"
  547.     if grep -q "$MODULE_NAME" /tmp/loadedeth.txt ; then
  548.         Xdialog --screen-center --title "$L_TITLE_Netwiz_Hardware" \
  549.                 --msgbox "$L_MESSAGE_Driver_Loaded" 0 0
  550.         echo -n "${MODULE_NAME}" > /tmp/ethmoduleyesload.txt
  551.         return 0
  552.     else
  553.         # Dougal: this had just "$MODULE_NAME", change to include parameters
  554.         if ERROR=$(modprobe $@ 2>&1) ; then
  555.             echo -n "$*" > /tmp/ethmoduleyesload.txt
  556.             case "$NETWORK_MODULES" in *" $MODULE_NAME "*) ;;
  557.              *) echo "$@" >> /etc/networkusermodules ;;
  558.             esac
  559.             Xdialog --left --wrap --stdout --title "$L_TITLE_Netwiz_Hardware" --msgbox "$L_MESSAGE_Driver_Success_p1 $MODULE_NAME $L_MESSAGE_Driver_Success_p2" 0 0
  560.             return 0
  561.         else
  562.             #Xdialog --stdout --msgbox "Loading ${MODULE_NAME} failed; try a different driver." 0 0
  563.             giveErrorDialog "$L_MESSAGE_Driver_Failed_p1 $MODULE_NAME ${L_MESSAGE_Driver_Failed_p2}$ERROR
  564. $L_MESSAGE_Driver_Failed_p3"
  565.             return 1
  566.         fi
  567.     fi
  568. } # end tryLoadModule
  569.  
  570. #=============================================================================
  571. giveAcxDialog(){
  572.     export NETWIZ_Acx_Module_Dialog="<window title=\"$L_TITLE_Puppy_Network_Wizard\" icon-name=\"gtk-network\" window-position=\"1\">
  573. <vbox>
  574.  <pixmap icon_size=\"6\">
  575.      <input file stock=\"gtk-dialog-warning\"></input>
  576.    </pixmap>
  577.  <text>
  578.    <label>\"$L_TEXT_Acx_Module_p1 $1. $L_TEXT_Acx_Module_p2\"</label>
  579.  </text>  
  580.  <hbox>
  581.    <button>
  582.      <label>$L_BUTTON_Blacklist</label>
  583.      <input file stock=\"gtk-yes\"></input>
  584.      <action>EXIT:Blacklist</action>
  585.    </button>
  586.    <button>
  587.       <label>$L_BUTTON_Unload</label>
  588.       <input file stock=\"gtk-undo\"></input>
  589.       <action>EXIT:Unload</action>
  590.     </button>
  591.     <button cancel></button>
  592.  </hbox>
  593. </vbox>
  594. </window>"
  595.  
  596.     I=$IFS; IFS=""
  597.     for STATEMENT in  $(gtkdialog3 --program NETWIZ_Acx_Module_Dialog); do
  598.         eval $STATEMENT
  599.     done
  600.     IFS=$I
  601.     clean_up_gtkdialog NETWIZ_Acx_Module_Dialog
  602.     unset NETWIZ_Acx_Module_Dialog
  603.      
  604.     case $EXIT in
  605.      Blacklist) blacklist_module "$1" ; return 1 ;;
  606.      Unload) return 0 ;; # askWhichInterfaceForNdiswrapper will continue to unload it
  607.     esac
  608.     return 1
  609. }
  610.  
  611. #=============================================================================
  612. askWhichInterfaceForNdiswrapper(){
  613.     TEMP=""
  614.     for ONE in $INTERFACES
  615.     do
  616.       [ "$ONE" ] || continue
  617.       TEMP="$TEMP
  618.     <button>
  619.      <label>$ONE</label>
  620.      <action>EXIT:$ONE</action>
  621.    </button>"  
  622.     done
  623.     # don't ask if there are no interfaces at all...
  624.     [ "$TEMP" ] || return 0
  625.    
  626.     export NETWIZ_Select_Ndiswrapper_Interface_Dialog="<window title=\"$L_TITLE_Puppy_Network_Wizard\" icon-name=\"gtk-network\" window-position=\"1\">
  627. <vbox>
  628.  <pixmap icon_size=\"6\">
  629.      <input file stock=\"gtk-dialog-question\"></input>
  630.    </pixmap>
  631.  <text use-markup=\"true\">
  632.    <label>\"$L_TEXT_Ask_Which_Interface_For_Ndiswrapper\"</label>
  633.  </text>  
  634.  <hbox>
  635.    $TEMP
  636.    <button>
  637.      <label>$L_BUTTON_None</label>
  638.      <action>EXIT:none</action>
  639.    </button>
  640.    <button cancel></button>
  641.  </hbox>
  642. </vbox>
  643. </window>"
  644.  
  645.     I=$IFS; IFS=""
  646.     for STATEMENT in  $(gtkdialog3 --program NETWIZ_Select_Ndiswrapper_Interface_Dialog); do
  647.     eval $STATEMENT
  648.     done
  649.     IFS=$I
  650.     clean_up_gtkdialog NETWIZ_Select_Ndiswrapper_Interface_Dialog
  651.     unset NETWIZ_Select_Ndiswrapper_Interface_Dialog
  652.    
  653.     case $EXIT in
  654.      none) return 0 ;;
  655.      Cancel|abort) return 1 ;;
  656.     esac
  657.     # if we got here, it's an interface
  658.     AMOD=$(readlink /sys/class/net/$EXIT/device/driver/module)
  659.     AMOD=${AMOD##*/}
  660.     AMOD=${AMOD//_/-}
  661.     #echo $AMOD
  662.     ##  Need to have an exception for the acx modules, since unloading them
  663.     ##+ causes the kernel to become unstable
  664.     case $AMOD in acx*) giveAcxDialog "$AMOD" || return 1 ;; esac
  665.     # Try removing module
  666.     if ERROR=$(rmmod $AMOD 2>&1) ; then
  667.       # ask the user if to blacklist
  668.       offerToBlacklistModule "$AMOD"
  669.       # need to refresh the main gui, since # of interfaces has changed
  670.       setDefaultMODULEBUTTONS
  671.       refreshMainWindowInfo
  672.       return 0
  673.     else # failed to remove: give message
  674.       giveErrorDialog "$L_MESSAGE_Remove_Module_Failed_p1 $AMOD.
  675. $L_MESSAGE_Remove_Module_Failed_p2
  676. $ERROR"
  677.       return 1
  678.     fi
  679. } # end askWhichInterfaceForNdiswrapper
  680.  
  681. #=============================================================================
  682. loadNdiswrapperModule ()
  683. {
  684.     #  Dougal: ask the user if there's an interface for the HW, so we know
  685.     #+ to remove the driver for it.
  686.     askWhichInterfaceForNdiswrapper || return
  687.     showNdiswrapperGUI
  688.     [ $? -eq 0 ] || return
  689.     ndiswrapper -m
  690.     #v4.00 bugfix...
  691.     NATIVEMOD=""
  692.     nwINTERFACE="$(grep '^alias .* ndiswrapper$' /etc/modprobe.conf | cut -f 2 -d ' ')"
  693.     #most likely 'wlan0'
  694.     #if this interface is already claimed by a native linux driver,
  695.     #then get rid of it...
  696.     ## Dougal: this isn't good: the interface name is not the problem, it's the HW!
  697.     ## Add a dialog at the top for it.
  698.     if [ -n "$nwINTERFACE" -a -e "/sys/class/net/$nwINTERFACE" ];then
  699.       NATIVEMOD="$(readlink /sys/class/net/${nwINTERFACE}/device/driver/module)"
  700.       NATIVEMOD=${NATIVEMOD##*/}
  701.       if [ "$NATIVEMOD" != "ndiswrapper" ];then
  702.         #note 'ndiswrapper -l' also returns the native linux module.
  703.         if iwconfig | grep "^${nwINTERFACE} " | grep 'IEEE' | grep -q 'ESSID' ;then
  704.           rmmod "$NATIVEMOD"
  705.           sleep 6
  706.           [ $INTERFACE_NUM -gt 0 ] && INTERFACE_NUM=$((INTERFACE_NUM-1))
  707.           #...needed later to determine that number of interfaces has changed with ndiswrapper.
  708.           #INTERFACES="$(ifconfig -a | grep -F 'Link encap:Ethernet' | cut -f1 -d' ' | tr '\n' ' ')"
  709.           getInterfaceList
  710.           #...also needed later.
  711.         fi
  712.       else
  713.         NATIVEMOD=""
  714.       fi
  715.     fi
  716.        
  717.     tryLoadModule "ndiswrapper"
  718.     ndRETVAL=$?
  719.    
  720.     #v4.00...
  721.     if [ $ndRETVAL -eq 0 ];then
  722.       #well let's be radical, blacklist the native driver...
  723.       if [ "$NATIVEMOD" != "" ];then
  724.         #if ! grep "^${NATIVEMOD}$" "$BLACKLIST_FILE" ;then
  725.         . /etc/rc.d/MODULESCONFIG
  726.         case $SKIPLIST in *" $NATIVEMOD "*|*" ${NATIVEMOD//_/-} "*) ;; *)
  727.           Xdialog --title "$L_TITLE_Puppy_Network_Wizard" --yesno \
  728. "$L_MESSAGE_Blacklist_Nativemod_p1 ${NATIVEMOD} $L_MESSAGE_Blacklist_Nativemod_p2" 0 0
  729.           if [ $? -eq 0 ] ; then
  730.             #echo "$NATIVEMOD" >> "$BLACKLIST_FILE"
  731.             blacklist_module "$NATIVEMOD"
  732.           fi
  733.           ;;
  734.         esac
  735.         #fi
  736.       fi
  737.     fi #if [ $ndRETVAL -eq 0 ];then
  738.     return $ndRETVAL
  739. } # end loadNdiswrapperModule
  740.  
  741. #=============================================================================
  742. #loadSpecificModule ()
  743. #{
  744.     #RESPONSE=$(Xdialog --stdout --title "$L_TITLE_Puppy_Network_Wizard" --inputbox "Please type the name of a specific module to load\n(extra parameters allowed, but don't type tab chars)." 0 0 "" 2> /dev/null)
  745.     #if [ $? -eq 0 ];then
  746.         #tryLoadModule "${RESPONSE}"
  747.     #fi
  748. #} # end loadSpecificModule
  749.  
  750. loadSpecificModule (){
  751.   export NETWIZ_Load_Specific_Module_Window="<window title=\"$L_TITLE_Load_A_Module\" icon-name=\"gtk-network\" window-position=\"1\">
  752. <vbox>
  753.  <text>
  754.    <label>\"$L_TEXT_Load_A_Module\"</label>
  755.  </text>
  756.  <entry>
  757.    <variable>SPECIFIED_MODULE</variable>
  758.  </entry>
  759.  <hbox>
  760.   <button>
  761.     <label>$L_BUTTON_Load</label>
  762.     <input file stock=\"gtk-ok\"></input>
  763.     <action>EXIT:Load</action>
  764.   </button>
  765.   <button cancel></button>
  766.  </hbox>
  767. </vbox>
  768. </window>"
  769.  
  770.   I=$IFS; IFS=""
  771.   for STATEMENT in  $(gtkdialog3 --program NETWIZ_Load_Specific_Module_Window); do
  772.     eval $STATEMENT 2>/dev/null
  773.   done
  774.   IFS=$I
  775.   clean_up_gtkdialog NETWIZ_Load_Specific_Module_Window
  776.   unset NETWIZ_Load_Specific_Module_Window
  777.  
  778.   if [ "$EXIT" = "Load" ] ; then
  779.     if [ "$SPECIFIED_MODULE" ] ; then #making sure there was something
  780.       tryLoadModule $SPECIFIED_MODULE 2>&1
  781.     fi
  782.   fi
  783. } # end loadSpecificModule
  784.  
  785. #=============================================================================
  786. autoLoadModule ()
  787. {
  788.     #this is the autoloading...
  789.     SOMETHINGWORKED=false
  790.     #clear
  791.     for CANDIDATE in $NETWORK_MODULES
  792.     do
  793.         #if have pcmcia, do not try loading the others...
  794.         MDOIT="no"
  795.         case "$CANDIDATE" in
  796.          *_cs*) [ "$MPCMCIA" = "yes" ] && MDOIT="yes" ;;
  797.          *)     [ "$MPCMCIA" = "yes" ] || MDOIT="yes" ;;
  798.         esac
  799.        
  800.         #also, do not try if it is already loaded...?
  801.         grep -q "$CANDIDATE" /tmp/loadedeth.txt && MDOIT="no"
  802.  
  803.         #in case of false-hits, ignore anything already tried this session...
  804.         grep -q "$CANDIDATE" /tmp/logethtries.txt && MDOIT="no"
  805.  
  806.         if [ "$MDOIT" = "yes" ];then
  807.             echo; echo "*** Trying $CANDIDATE."
  808.             if modprobe "$CANDIDATE"
  809.             then
  810.                 SOMETHINGWORKED=true
  811.                 WHATWORKED=$CANDIDATE
  812.                 #add it to the log for this session...
  813.                 echo "$CANDIDATE" >> /tmp/logethtries.txt
  814.                 break
  815.             fi
  816.         fi
  817.  
  818.     done
  819.     sleep 2
  820.     if $SOMETHINGWORKED
  821.     then
  822.         Xdialog --left --wrap --title "$L_TITLE_Puppy_Network_Wizard" --msgbox "$L_MESSAGE_Success_Loading_Module_p1 $WHATWORKED $L_MESSAGE_Success_Loading_Module_p2" 0 0
  823.         echo -n "$WHATWORKED" > /tmp/ethmoduleyesload.txt
  824.     else
  825.         MALREADY="$(cat /tmp/loadedeth.txt)"
  826.         Xdialog --msgbox "${L_MESSAGE_No_Module_Loaded}\n${MALREADY}" 0 0
  827.         return 1
  828.     fi
  829. } # end autoLoadModule
  830.  
  831. #=============================================================================
  832. # A function to add a module to the SKIPLIST
  833. blacklist_module(){
  834.   MODULE="$1"
  835.   if grep -Fq 'SKIPLIST=' /etc/rc.d/MODULESCONFIG ; then
  836.     sed -i "s/^SKIPLIST=.*/SKIPLIST=\"$SKIPLIST ${MODULE//_/-} \"/" /etc/rc.d/MODULESCONFIG
  837.   else
  838.     echo "SKIPLIST=\" ${MODULE//_/-} \"" >>/etc/rc.d/MODULESCONFIG
  839.   fi
  840. }
  841.  
  842.  
  843. #=============================================================================
  844. # A function that gives a dialog offering to blabklist a just-removed module
  845. # $1: the modules
  846. offerToBlacklistModule(){
  847.     AMODULE="$1"
  848.     # see if not already blacklisted
  849.     . /etc/rc.d/MODULESCONFIG
  850.     case $SKIPLIST in *" $AMODULE "*|*" ${AMODULE//_/-} "*) return ;; esac
  851.    
  852.     export NETWIZ_Blacklist_Module_Dialog="<window title=\"$L_TITLE_Puppy_Network_Wizard\" icon-name=\"gtk-network\" window-position=\"1\">
  853. <vbox>
  854.  <pixmap icon_size=\"6\">
  855.      <input file stock=\"gtk-dialog-question\"></input>
  856.    </pixmap>
  857.  <text>
  858.    <label>\"$L_TEXT_Blacklist_Module_p1 $AMODULE $L_TEXT_Blacklist_Module_p2\"</label>
  859.  </text>  
  860.  <hbox>
  861.    <button>
  862.      <label>$L_BUTTON_Blacklist</label>
  863.      <input file stock=\"gtk-yes\"></input>
  864.      <action>EXIT:Blacklist</action>
  865.    </button>
  866.    <button>
  867.       <label>$L_BUTTON_No</label>
  868.       <input file stock=\"gtk-no\"></input>
  869.       <action>EXIT:cancel</action>
  870.     </button>
  871.  </hbox>
  872. </vbox>
  873. </window>"
  874.  
  875.     I=$IFS; IFS=""
  876.     for STATEMENT in  $(gtkdialog3 --program NETWIZ_Blacklist_Module_Dialog); do
  877.         eval $STATEMENT
  878.     done
  879.     IFS=$I
  880.     clean_up_gtkdialog NETWIZ_Blacklist_Module_Dialog
  881.     unset NETWIZ_Blacklist_Module_Dialog
  882.      
  883.     case $EXIT in Blacklist)
  884.         #echo "$AMODULE" >> "$BLACKLIST_FILE"
  885.         blacklist_module "$AMODULE"
  886.         ;;
  887.     esac    
  888. } # end offerToBlacklistModule
  889.  
  890. #=============================================================================
  891. unloadSpecificModule(){
  892.   TOPMSG=""
  893.   LOADED_ITEMS=""
  894.   while read ONE
  895.   do
  896.     [ "$ONE" ] || continue
  897.     LOADED_ITEMS="$LOADED_ITEMS <item>$ONE</item>"
  898.   done</tmp/loadedeth.txt
  899.  
  900.   # see if there's anything at all...
  901.   if [ ! "$LOADED_ITEMS" ] ; then
  902.     giveErrorDialog "$L_MESSAGE_No_Loaded_Items"
  903.     return
  904.   fi
  905.  
  906.   export NETWIZ_Unload_Module_Window="<window title=\"$L_TITLE_Unload_A_Module\" icon-name=\"gtk-network\" window-position=\"1\">
  907. <vbox>
  908.  <text>
  909.    <label>\"$L_TEXT_Unload_A_Module\"</label>
  910.  </text>
  911.  <hbox>
  912.    <text>
  913.      <label>$L_COMBO_Module</label>
  914.    </text>
  915.    <combobox>
  916.      <variable>COMBOBOX</variable>
  917.      $LOADED_ITEMS
  918.    </combobox>
  919.  </hbox>
  920.  <hbox>
  921.   <button>
  922.     <label>$L_BUTTON_Unload</label>
  923.     <input file stock=\"gtk-undo\"></input>
  924.     <action>EXIT:Unload</action>
  925.   </button>
  926.   <button cancel></button>
  927.  </hbox>
  928. </vbox>
  929. </window>"
  930.  
  931.   I=$IFS; IFS=""
  932.   for STATEMENT in  $(gtkdialog3 --program NETWIZ_Unload_Module_Window); do
  933.     eval $STATEMENT 2>/dev/null
  934.   done
  935.   IFS=$I
  936.   clean_up_gtkdialog NETWIZ_Unload_Module_Window
  937.   unset NETWIZ_Unload_Module_Window
  938.  
  939.   if [ "$EXIT" = "Unload" ] ; then
  940.     if [ "$COMBOBOX" ] ; then #making sure there was something
  941.       if ERROR=$(rmmod $COMBOBOX 2>&1) ; then # it worked, remove from list
  942.         sed -i "/^ $COMBOBOX*/d" /tmp/loadedeth.txt
  943.         # ask the user about blacklisting
  944.         offerToBlacklistModule "$COMBOBOX"
  945.         # need to refresh the main gui, since # of interfaces has changed
  946.         setDefaultMODULEBUTTONS
  947.         refreshMainWindowInfo
  948.       else # failed to remove: give message
  949.         giveErrorDialog "$L_MESSAGE_Remove_Module_Failed_p1 $COMBOBOX.
  950. $L_MESSAGE_Remove_Module_Failed_p2
  951. $ERROR"
  952.       fi #if rmmod $COMBOBOX ; then
  953.    
  954.     fi #if [ "$COMBOBOX" ] ; then
  955.   fi #if [ "$EXIT" = "Unload" ] ; then
  956. } # end unloadSpecificModule
  957.  
  958. #=============================================================================
  959. findLoadedModules ()
  960. {
  961.   echo -n " " > /tmp/loadedeth.txt
  962.  
  963.   LOADED_MODULES="$(lsmod | cut -f1 -d' ' | sort)"
  964.   NETWORK_MODULES=" $(cat /etc/networkmodules /etc/networkusermodules  2>/dev/null | cut -f1 -d' ' | tr '\n' ' ') "
  965.  
  966.   COUNT_MOD=0
  967.   for MOD in $LOADED_MODULES
  968.   do    COUNT_MOD=$((COUNT_MOD+1))
  969.   done
  970.  
  971.   (
  972.         for AMOD in $LOADED_MODULES
  973.         do
  974.             echo "X"
  975.             # Dougal: use a case structure for globbing
  976.             # Also try and retain original module names (removed "tr '-' '_')
  977.             case "$NETWORK_MODULES" in
  978.              *" $AMOD "*)
  979.                echo "$AMOD" >> /tmp/loadedeth.txt
  980.                echo -n " " >> /tmp/loadedeth.txt #space separation
  981.                ;;
  982.              *" ${AMOD/_/-} "*) # kernel shows module with underscore...
  983.               echo "${AMOD/_/-}" >> /tmp/loadedeth.txt
  984.               echo -n " " >> /tmp/loadedeth.txt #space separation
  985.               ;;
  986.             esac
  987.         done
  988.   ) | Xdialog --title "$L_TITLE_Puppy_Network_Wizard" --progress "$L_PROGRESS_Checking_Loaded_Modules" 0 0 $COUNT_MOD
  989.  
  990. } # end of findLoadedModules
  991. #=============================================================================
  992. testInterface()
  993. {
  994.   INTERFACE="$1"
  995.  
  996.   (
  997.     UNPLUGGED="false"
  998.     ifconfig "$INTERFACE" | grep ' UP ' >> $DEBUG_OUTPUT 2>&1
  999.     if [ ! $? -eq 0 ];then #=0 if found
  1000.         #cleanUpInterface "$INTERFACE" >> $DEBUG_OUTPUT 2>&1
  1001.         # Dougal: add check for error -- maybe it fails to be raised?
  1002.         if ! ERROR=$(ifconfig "$INTERFACE" up 2>&1) ; then
  1003.           giveErrorDialog "$L_MESSAGE_Failed_Raise_Interface_p1 $INTERFACE.
  1004. $L_MESSAGE_Failed_Raise_Interface_p2 ifconfig $INTERFACE up
  1005. $L_MESSAGE_Failed_Raise_Interface_p3
  1006. $ERROR
  1007. "
  1008.         fi
  1009.     fi
  1010.     #BK1.0.7 improved link-beat detection...
  1011.     echo "X"
  1012.   #091108 old ifplugstatus now -0.18, latest is just 'ifplugstatus'...
  1013.   # 25feb10: shinobar: old and new ifplugstatus
  1014.   IFPLUGOLD=ifplugstatus
  1015.   IFPLUGNEW=ifplugstatus
  1016.   [ -x /sbin/ifplugstatus-0.18 ] && IFPLUGOLD=ifplugstatus-0.18
  1017.   [ -x /sbin/ifplugstatus-0.25 ] && IFPLUGNEW=ifplugstatus-0.25
  1018.     if ! $IFPLUGOLD "$INTERFACE" | grep -F -q 'link beat detected' ;then
  1019.       sleep 2
  1020.       echo "X"
  1021.       if ! $IFPLUGNEW "$INTERFACE" | grep -F -q 'link beat detected' ;then
  1022.         sleep 2
  1023.         echo "X"
  1024.         if ! $IFPLUGOLD "$INTERFACE" | grep -F -q 'link beat detected' ;then
  1025.           sleep 2
  1026.           echo "X"
  1027.           if ! $IFPLUGNEW "$INTERFACE" | grep -F -q 'link beat detected' ;then
  1028.             # add ethtool test, just in case it helps at times...
  1029.             sleep 1
  1030.             echo "X"
  1031.             if ! ethtool "$INTERFACE" | grep -Fq 'Link detected: yes' ; then
  1032.               UNPLUGGED="true"
  1033.             fi
  1034.           fi
  1035.         fi
  1036.       fi
  1037.     fi
  1038.     echo "${UNPLUGGED}" > /tmp/net-setup_UNPLUGGED.txt
  1039.   ) | Xdialog --title "$L_TITLE_Network_Wizard" --progress "$L_PROGRESS_Testing_Interface ${INTERFACE}" 0 0 5
  1040.  
  1041.   UNPLUGGED=$(cat /tmp/net-setup_UNPLUGGED.txt)
  1042.  
  1043.   if [ "$UNPLUGGED" != "false" ];then #BK1.0.7
  1044.     #no cable plugged in, no network connection possible...
  1045.     ifconfig "$INTERFACE" down
  1046.     BGCOLOR="#ffc0c0"
  1047.     if [ "${IS_WIRELESS}" ] ; then
  1048.       TOPMSG="$(eval echo $L_TOPMSG_Report_On_Test)
  1049. $L_TOPMSG_Unplugged_Wireless"
  1050.     else
  1051.       TOPMSG="$(eval echo $L_TOPMSG_Report_On_Test)
  1052. $L_TOPMSG_Unplugged_Wired"
  1053.     RETTEST=1
  1054.     fi
  1055.   else
  1056.     BGCOLOR="#e0ffe0"
  1057.     TOPMSG="$(eval echo $L_TOPMSG_Report_On_Test)
  1058. $L_TOPMSG_Network_Alive"
  1059.         RETTEST=0
  1060.   fi
  1061.  
  1062.   return $RETTEST
  1063. } # end of testInterface
  1064.  
  1065. #=============================================================================
  1066. showConfigureInterfaceWindow()
  1067. {
  1068.   INTERFACE="$1"
  1069.  
  1070.   initializeConfigureInterfaceWindow
  1071.  
  1072.   RETVALUE=""
  1073.   # 1=Close window 19=Back Button 22=Save configuration
  1074.   while true
  1075.   do
  1076.     buildConfigureInterfaceWindow
  1077.    
  1078.     I=$IFS; IFS=""
  1079.     for STATEMENT in  $(gtkdialog3 --program NETWIZ_Configure_Interface_Window); do
  1080.       eval $STATEMENT
  1081.     done
  1082.     IFS=$I
  1083.     clean_up_gtkdialog NETWIZ_Configure_Interface_Window
  1084.     unset NETWIZ_Configure_Interface_Window
  1085.  
  1086.     RETVALUE=$EXIT
  1087.     [ "$RETVALUE" = "abort" ] && RETVALUE=1
  1088.  
  1089.     RETSETUP=99
  1090.     case $RETVALUE in
  1091.        1 | 19) # close window
  1092.           TOPMSG="$(eval echo $L_TOPMSG_Configuration_Cancelled)"
  1093.           break
  1094.           ;;
  1095.       66) # Dougal: add "Done" button to exit (there was a wrong message)
  1096.           cleanUpTmp
  1097.           exit
  1098.           ;;
  1099.       10) # AutoDHCP
  1100.           # Must kill old dhcpcd first
  1101.           killDhcpcd "$INTERFACE"
  1102.           sleep 3
  1103.           setupDHCP
  1104.           RETSETUP=$?
  1105.           ;;
  1106.       11) # StaticIP
  1107.           showStaticIPWindow
  1108.           RETSETUP=$?
  1109.           ;;
  1110.       13) # Test
  1111.           testInterface "$INTERFACE"
  1112.           RETSETUP=$?
  1113.           ;;
  1114.       14) # Wireless
  1115.           configureWireless "$INTERFACE"
  1116.           ;;
  1117.       #21) # Help
  1118.           #showHelp
  1119.           #;;
  1120.       22) # Save configuration
  1121.           break
  1122.           ;;
  1123.     esac
  1124.    
  1125.     # Dougal: define the "Done" button here, so it doesn't appear the first time around...
  1126.     DONEBUTTON="<button>
  1127.                     <label>$L_BUTTON_Done</label>
  1128.                     <input file stock=\"gtk-apply\"></input>
  1129.                     <action>EXIT:66</action>
  1130.                 </button>"
  1131.    
  1132.     if [ $RETVALUE -eq 10 ] || [ $RETVALUE -eq 11 ] ; then
  1133.       if [ $RETSETUP -ne 0 ] ; then
  1134.         TOPMSG="$(eval echo $L_TOPMSG_Configuration_Unsuccessful)
  1135. $L_TOPMSG_Configuration_Offer_Try_Again"
  1136.       else
  1137.         RETVALUE=1
  1138.         Xdialog --yesno "$(eval echo $L_TOPMSG_Configuration_Successful)
  1139. $L_TOPMSG_Configuration_Offer_To_Save" 0 0
  1140.         if [ $? -eq 0 ] ; then
  1141.           saveInterfaceSetup "$INTERFACE"
  1142.           # Dougal: might add some info in here
  1143.           TOPMSG="$(eval echo $L_TOPMSG_Configuration_Successful)
  1144. $L_TOPMSG_Configuration_Offer_To_Finish"
  1145.         else
  1146.           TOPMSG="$(eval echo $L_TOPMSG_Configuration_Successful)
  1147. $L_TOPMSG_Configuration_Not_Saved"
  1148.         fi
  1149.       fi
  1150.     fi
  1151.  
  1152.   done
  1153.  
  1154. } # end showConfigureInterfaceWindow
  1155.  
  1156. #=============================================================================
  1157. buildConfigureInterfaceWindow ()
  1158. {
  1159.     export NETWIZ_Configure_Interface_Window="<window title=\"$(eval echo $L_TITLE_Configure_Interface)\" icon-name=\"gtk-network\" window-position=\"1\">
  1160. <vbox>
  1161.     <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1162.     <text><label>\"${TOPMSG}\"</label></text>
  1163.     ${WIRELESSSECTION}
  1164.     <frame  $L_FRAME_Test_Interface >
  1165.         <hbox>
  1166.             <text><label>\"${TESTMSG}\"</label></text>
  1167.             <vbox>
  1168.                 <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1169.                 <button>
  1170.                     <label>$(eval echo $L_BUTTON_Test_Interface)</label>
  1171.                     <action>EXIT:13</action>
  1172.                 </button>
  1173.             </vbox>
  1174.         </hbox>
  1175.     </frame>
  1176.     <frame  $L_FRAME_Configure_Interface >
  1177.         <hbox>
  1178.             <text><label>\"${DHCPMSG}\"</label></text>
  1179.             <vbox>
  1180.                 <text><label>\" \"</label></text>
  1181.                 <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1182.                 <button>
  1183.                     <label>$L_BUTTON_Auto_DHCP</label>
  1184.                     <action>EXIT:10</action>
  1185.                 </button>
  1186.             </vbox>
  1187.         </hbox>
  1188.         <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1189.         <hbox>
  1190.             <text><label>\"${STATICMSG}\"</label></text>
  1191.             <vbox>
  1192.                 <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1193.                 <button>
  1194.                     <label>$L_BUTTON_Static_IP</label>
  1195.                     <action>EXIT:11</action>
  1196.                 </button>
  1197.             </vbox>
  1198.         </hbox>
  1199.     </frame>
  1200.     <hbox>
  1201.         $DONEBUTTON
  1202.         <button help>
  1203.             <action>$HELP_COMMAND > /dev/null 2>&1 & </action>
  1204.         </button>
  1205.         ${SAVE_SETUP_BUTTON}
  1206.         <button>
  1207.             <label>$L_BUTTON_Back</label>
  1208.             <input file stock=\"gtk-go-back\"></input>
  1209.             <action>EXIT:19</action>
  1210.         </button>
  1211.     </hbox>
  1212. </vbox>
  1213. </window>"
  1214. } # end buildConfigureInterfaceWindow
  1215.  
  1216. #=============================================================================
  1217. initializeConfigureInterfaceWindow ()
  1218. {
  1219.     TOPMSG="$L_TOPMSG_Initial_Lets_try $INTERFACE."
  1220.  
  1221.     TESTMSG="$L_TESTMSG_Initial_p1 $INTERFACE $L_TESTMSG_Initial_p2"
  1222.  
  1223.     DHCPMSG="$L_DHCPMSG_Initial"
  1224.  
  1225.     STATICMSG="$L_STATICMSG_Initial"
  1226.  
  1227.     if checkIfIsWireless "$INTERFACE" ; then
  1228.         WIRELESSSECTION="<frame  $L_FRAME_Configure_Wireless >
  1229. <hbox>
  1230.     <text><label>\"$L_TEXT_Configure_Wireless_p1 $INTERFACE $L_TEXT_Configure_Wireless_p2\"</label></text>
  1231.     <vbox>
  1232.         <text><label>\" \"</label></text>
  1233.         <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1234.         <button>
  1235.             <label>$L_BUTTON_Wireless</label>
  1236.             <action>EXIT:14</action>
  1237.         </button>
  1238.     </vbox>
  1239. </hbox>
  1240. </frame>"
  1241.     else
  1242.         WIRELESSSECTION=""
  1243.     fi
  1244.     SAVE_SETUP_BUTTON=""
  1245. } # end initializeConfigureInterfaceWindow
  1246.  
  1247. #=============================================================================
  1248. checkIfIsWireless ()
  1249. {
  1250.   INTERFACE="$1"
  1251.   IS_WIRELESS=""
  1252.   INTMODULE=$(readlink /sys/class/net/$INTERFACE/device/driver)
  1253.   INTMODULE=${INTMODULE##*/}
  1254.  
  1255.   if [ -d "/sys/class/net/$INTERFACE/wireless" ] || \
  1256.      [ "$INTMODULE" = "prism2_usb" ] || \
  1257.      grep -q "$INTERFACE" /proc/net/wireless
  1258.   then IS_WIRELESS="yes" ; return 0
  1259.   fi
  1260.   return 1
  1261. }
  1262.  
  1263. #=============================================================================
  1264. configureWireless()
  1265. {
  1266.     INTERFACE="$1"
  1267.     showProfilesWindow "$INTERFACE"
  1268.     case $? in
  1269.       0)
  1270.         testInterface "$INTERFACE"
  1271.         ;;
  1272.       2) # Dougal: add this for failed useProfile
  1273.         TOPMSG="$L_TOPMSG_Wireless_Config_Failed_p1 $INTERFACE $L_TOPMSG_Wireless_Config_Failed_p2"
  1274.         ;;
  1275.       *)
  1276.         TOPMSG="$L_TOPMSG_Wireless_Config_Cancelled_p1 $INTERFACE $L_TOPMSG_Wireless_Config_Cancelled_p2"
  1277.         ;;
  1278.     esac
  1279. } # end configureWireless
  1280.  
  1281. #=============================================================================
  1282. # this expanded and moved to wag-profiles.sh, so can be used by rc.network
  1283. #setupDHCP()
  1284. #{
  1285.     #{
  1286.         ## Must kill old dhcpcd first
  1287.         #killDhcpcd "$INTERFACE"
  1288.         #sleep 5
  1289.         #if dhcpcd -d -I '' "$INTERFACE"
  1290.         #then
  1291.             #HAS_ERROR=0
  1292.         #else
  1293.             #HAS_ERROR=1
  1294.         #fi
  1295.         #echo "${HAS_ERROR}" > /tmp/net-setup_HAS_ERROR.txt
  1296.         #echo "XXXX"
  1297.     #} | Xdialog --no-buttons --title "$L_TITLE_Puppy_Network_Wizard: DHCP" --infobox "There may be a delay of up to 60 seconds while Puppy waits for the
  1298. #DHCP server to respond. Please wait patiently..." 0 0 0
  1299.  
  1300.   #HAS_ERROR=$(cat /tmp/net-setup_HAS_ERROR.txt)
  1301.  
  1302.   #if [ $HAS_ERROR -eq 0 ]
  1303.   #then
  1304.     ## Dougal: not sure about this -- maybe add something? need to know we've used it
  1305.     #MODECOMMANDS=""
  1306.   #else
  1307.     #MODECOMMANDS=""
  1308.     ## need to kill dhcpcd, since it keeps running even with an error!
  1309.     #killDhcpcd "$INTERFACE"
  1310.   #fi
  1311.  
  1312.   #return $HAS_ERROR
  1313. #} #end of setupDHCP
  1314.  
  1315. #=============================================================================
  1316. showStaticIPWindow()
  1317. {
  1318.     IP_ADDRESS="$(ifconfig $INTERFACE | grep 'inet addr' | sed 's/.*inet addr://' | cut -d" " -f1)"
  1319.     NETMASK="$(ifconfig $INTERFACE | grep 'inet addr' | sed 's/.*Mask://')"
  1320.     GATEWAY="$(iproute | grep default | cut -d" " -f3)"
  1321.     # get current dns servers
  1322.     NUM=1
  1323.     while read A B ; do
  1324.       if [ "$A" = "nameserver" ] && dotquad "$B" ; then # being really paranoid...
  1325.         eval DNS_SERVER$NUM="$B"
  1326.         NUM=$((NUM+1))
  1327.       fi
  1328.     done<<EOF
  1329. $( grep -m2 nameserver /etc/resolv.conf )
  1330. EOF
  1331.    
  1332.     EXIT=""
  1333.     while true
  1334.     do
  1335.         buildStaticIPWindow
  1336.         I=$IFS; IFS=""
  1337.         for STATEMENT in  $(gtkdialog3 --program NETWIZ_Static_IP_Window); do
  1338.             eval $STATEMENT
  1339.         done
  1340.         IFS=$I
  1341.         clean_up_gtkdialog NETWIZ_Static_IP_Window
  1342.         unset NETWIZ_Static_IP_Window
  1343.  
  1344.         case "$EXIT" in
  1345.             abort|Cancel) # close window
  1346.                 break
  1347.                 ;; # Do Nothing, It will exit without doing anything
  1348.             #"21" ) # Help
  1349.                 #showHelp
  1350.                 #;;
  1351.             "OK" ) # OK
  1352.                 if validateStaticIP ; then
  1353.                     setupStaticIP || EXIT=""
  1354.                 else
  1355.                     EXIT=""
  1356.                 fi
  1357.                 break
  1358.                 ;;
  1359.         esac
  1360.     done
  1361.    
  1362.     if [ "${EXIT}" = "OK" ] ; then
  1363.         return 0
  1364.     else
  1365.         return 1
  1366.     fi
  1367. } # end showStaticIPWindow
  1368.  
  1369. #=============================================================================
  1370. buildStaticIPWindow()
  1371. {
  1372.     [ -z "$IP_ADDRESS" ] && IP_ADDRESS="0.0.0.0"
  1373.     [ -z "$NETMASK" ] && NETMASK="255.255.255.0"
  1374.     [ -z "$GATEWAY" ] && GATEWAY="0.0.0.0"
  1375.     [ -z "$DNS_SERVER1" ] && DNS_SERVER1="0.0.0.0"
  1376.     [ -z "$DNS_SERVER2" ] && DNS_SERVER2="0.0.0.0"
  1377.  
  1378.     export NETWIZ_Static_IP_Window="<window title=\"$L_TITLE_Set_Static_IP\" icon-name=\"gtk-network\" window-position=\"1\">
  1379. <vbox>
  1380.     <text><label>\"$L_TEXT_Set_Static_IP\"</label></text>
  1381.     <frame  $L_FRAME_Static_IP_Parameters >
  1382.         <hbox>
  1383.             <vbox>
  1384.                 <text><label>$L_ENTRY_IP_Address</label></text>
  1385.                 <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1386.             </vbox>
  1387.             <entry>
  1388.                 <variable>IP_ADDRESS</variable>
  1389.                 <default>${IP_ADDRESS}</default>
  1390.             </entry>
  1391.         </hbox>
  1392.         <hbox>
  1393.             <vbox>
  1394.                 <text><label>$L_ENTRY_Net_Mask</label></text>
  1395.                 <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1396.             </vbox>
  1397.             <entry>
  1398.                 <variable>NETMASK</variable>
  1399.                 <default>${NETMASK}</default>
  1400.             </entry>
  1401.         </hbox>
  1402.         <hbox>
  1403.             <vbox>
  1404.                 <text><label>$L_ENTRY_Gateway</label></text>
  1405.                 <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1406.             </vbox>
  1407.             <entry>
  1408.                 <variable>GATEWAY</variable>
  1409.                 <default>${GATEWAY}</default>
  1410.             </entry>
  1411.         </hbox>
  1412.     </frame>
  1413.     <frame  $L_FRAME_DNS_Parameters >
  1414.         <hbox>
  1415.             <vbox>
  1416.                 <text><label>$L_ENTRY_DNS_Primary</label></text>
  1417.                 <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1418.             </vbox>
  1419.             <entry>
  1420.                 <variable>DNS_SERVER1</variable>
  1421.                 <default>${DNS_SERVER1}</default>
  1422.             </entry>
  1423.         </hbox>
  1424.         <hbox>
  1425.             <vbox>
  1426.                 <text><label>$L_ENTRY_DNS_Secondary</label></text>
  1427.                 <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1428.             </vbox>
  1429.             <entry>
  1430.                 <variable>DNS_SERVER2</variable>
  1431.                 <default>${DNS_SERVER2}</default>
  1432.             </entry>
  1433.         </hbox>
  1434.     </frame>
  1435.     <hbox>
  1436.         <button help>
  1437.             <action>$HELP_COMMAND > /dev/null 2>&1 & </action>
  1438.         </button>
  1439.         <button ok></button>
  1440.         <button cancel></button>
  1441.     </hbox>
  1442. </vbox>
  1443. </window>"
  1444. } # end buildStaticIPWindow
  1445.  
  1446. #=============================================================================
  1447. validateStaticIP()
  1448. {
  1449.     # Dougal: this was set as default, but obviously not used...
  1450.     [ "$GATEWAY" = "0.0.0.0" ] && GATEWAY=""
  1451.     # user might have blanked them out...
  1452.     [ -z "$DNS_SERVER1" ] && DNS_SERVER1="0.0.0.0"
  1453.     [ -z "$DNS_SERVER2" ] && DNS_SERVER2="0.0.0.0"
  1454.     ERROR_MSG=""
  1455.     if ! validip "${IP_ADDRESS}" ; then
  1456.         ERROR_MSG="${ERROR_MSG}\n- $L_ERROR_Invalid_IP_Address"
  1457.     fi
  1458.     if ! validip "${NETMASK}" ; then
  1459.         ERROR_MSG="${ERROR_MSG}\n- $L_ERROR_Invalid_Netmask"
  1460.     fi
  1461.     if [ ! -z "$GATEWAY" ] ; then
  1462.         if ! validip "${GATEWAY}"  ; then
  1463.             ERROR_MSG="${ERROR_MSG}\n- $L_ERROR_Invalid_Gateway"
  1464.         fi
  1465.     fi
  1466.     if ! validip "${DNS_SERVER1}"  ; then
  1467.         ERROR_MSG="${ERROR_MSG}\n- $L_ERROR_Invalid_DNS1"
  1468.     fi
  1469.     if ! validip "${DNS_SERVER2}"  ; then
  1470.         ERROR_MSG="${ERROR_MSG}\n- $L_ERROR_Invalid_DNS2"
  1471.     fi
  1472.    
  1473.     if [ "${ERROR_MSG}" != "" ] ; then
  1474.         #Xdialog --left --title "$L_TITLE_Netwiz_Static_IP" \
  1475.                 #   --msgbox "Some of the addresses provided are invalid\n${ERROR_MSG}" 0 0
  1476.         # change \n to newlines for gtkdialog...
  1477.         ERROR_MSG="$(echo -e "$ERROR_MSG" )"
  1478.         giveErrorDialog "$L_MESSAGE_Bad_addresses
  1479. $ERROR_MSG
  1480. "
  1481.         return 1
  1482.     fi 
  1483.    
  1484.     DEFAULTMASK=$(ipcalc --netmask "$IP_ADDRESS" | cut -d= -f2)
  1485.    
  1486.     if [ "x${NETMASK}" != "x${DEFAULTMASK}" ] ; then
  1487.         Xdialog --center --title "$L_TITLE_Netwiz_Static_IP" \
  1488.                     --yesno "$L_MESSAGE_Bad_Netmask" 0 0
  1489.         if [ $? -eq 1 ] ; then
  1490.             return 1
  1491.         fi
  1492.     fi
  1493.    
  1494.     # Check that network is right
  1495.     if [ -z "$GATEWAY" ];then
  1496.         # It is legitimate not to have a gateway at all.  In that case, it
  1497.         # doesn't have a network. :-)
  1498.         unset HOSTNET
  1499.         unset GATENET
  1500.     else
  1501.         HOSTNUM=$(dotquad "$IP_ADDRESS")
  1502.         MASKNUM=$(dotquad "$NETMASK")
  1503.         GATENUM=$(dotquad "$GATEWAY")
  1504.         HOSTNET=$(and "$MASKNUM" "$HOSTNUM")
  1505.         GATENET=$(and "$MASKNUM" "$GATENUM")
  1506.     fi
  1507.    
  1508.     if [ "x${HOSTNET}" != "x${GATENET}" ] ; then
  1509.         #Xdialog --center --wrap --title "$L_TITLE_Netwiz_Static_IP" \
  1510.                 #   --msgbox "Your gateway $GATEWAY is not on this network! Please try again.\n(You may have entered your address, gateway or netmask incorrectly.)" 0 0  0 0
  1511.         giveErrorDialog "$L_MESSAGE_Bad_Gateway_p1 $GATEWAY $L_MESSAGE_Bad_Gateway_p2"
  1512.         return 1
  1513.     fi
  1514.    
  1515.     return 0
  1516. } #end of validateStaticIP
  1517.  
  1518. #=============================================================================
  1519. # Dougal: change MODECOMMANDS entirely -- just include the basic info
  1520. setupStaticIP()
  1521. {
  1522.     ifconfig "$INTERFACE" | grep ' UP ' >> $DEBUG_OUTPUT 2>&1
  1523.     if [ ! $? -eq 0 ];then # wired interface (wireless will be up by now)
  1524.         cleanUpInterface "$INTERFACE"
  1525.         #ifconfig "$INTERFACE" up
  1526.     fi
  1527.     BROADCAST=$(ipcalc -b "$IP_ADDRESS" "$NETMASK" | cut -d= -f2)
  1528.    
  1529.     #ifconfig "$INTERFACE" down
  1530.    
  1531.     CONVO="ifconfig $INTERFACE $IP_ADDRESS netmask $NETMASK broadcast $BROADCAST"
  1532.     CONVG="route add -net default gw $GATEWAY" #dev $INTERFACE"
  1533.    
  1534.     # Dougal: add a cleanup, just in case
  1535.     #cleanUpInterface "$INTERFACE" >> $DEBUG_OUTPUT 2>&1
  1536.     # do the work
  1537.     # Dougal: add getting error message
  1538.     ERROR=$(ifconfig "$INTERFACE" "$IP_ADDRESS" netmask "$NETMASK" broadcast "$BROADCAST" 2>&1) #up
  1539.     if [ $? -eq 0 ];then
  1540.         MODECOMMANDS="STATIC_IP='yes'\nIP_ADDRESS='$IP_ADDRESS'\nNETMASK='$NETMASK'"
  1541.         # Configure a nameserver, if we're supposed to.
  1542.         # This now replaces any existing resolv.conf, which
  1543.         # we will try to back up.
  1544.         if [ "$DNS_SERVER1" != "0.0.0.0" ] ; then
  1545.             # remove old backups
  1546.             rm /etc/resolv.conf.[0-9][0-9]* 2>/dev/null
  1547.             # backup previous one
  1548.             mv -f /etc/resolv.conf /etc/resolv.conf.old
  1549.             echo "nameserver $setupStaticIP1" > /etc/resolv.conf
  1550.             if [ "$DNS_SERVER2" != "0.0.0.0" ] ; then
  1551.                 echo "nameserver $DNS_SERVER2" >> /etc/resolv.conf
  1552.             fi
  1553.         fi
  1554.         MODECOMMANDS="$MODECOMMANDS\nDNS_SERVER1='$DNS_SERVER1'"
  1555.         MODECOMMANDS="$MODECOMMANDS\nDNS_SERVER2='$DNS_SERVER2'"
  1556.        
  1557.         # add default route, if we're supposed to
  1558.         if [ "$GATEWAY" ] ; then
  1559.             # Dougal: add getting error message
  1560.             ERROR=$(route add -net default gw "$GATEWAY" 2>&1)
  1561.             if [ $? -eq 0 ];then #0=ok.
  1562.                 Xdialog --center --title "$L_TITLE_Netwiz_Static_IP" --msgbox "$(eval echo $L_MESSAGE_Route_Set)" 0 0
  1563.                 MODECOMMANDS="${MODECOMMANDS}\nGATEWAY='$GATEWAY'"
  1564.             else
  1565.                 giveErrorDialog "$L_MESSAGE_Route_Failed_p1 $GATEWAY.
  1566. $L_MESSAGE_Route_Failed_p2
  1567. $CONVG
  1568. $L_MESSAGE_Route_Failed_p3
  1569. $ERROR
  1570. "
  1571.                 ifconfig "$INTERFACE" down
  1572.                 return 1
  1573.             fi
  1574.         fi
  1575.        
  1576.         return 0
  1577.     else
  1578.         giveErrorDialog "$L_MESSAGE_Ifconfig_Failed_p1
  1579. $CONVO
  1580. $L_MESSAGE_Ifconfig_Failed_p2
  1581. $ERROR
  1582. $L_MESSAGE_Ifconfig_Failed_p3"
  1583.         ifconfig "$INTERFACE" down
  1584.         MODECOMMANDS=""
  1585.         return 1
  1586.     fi
  1587. } #end of setupStaticIP
  1588.  
  1589. #=============================================================================
  1590. saveNewModule()
  1591. {
  1592.   # save newly loaded module
  1593.   if ! grep "$NEWLOADED" /etc/ethernetmodules ;then
  1594.     echo "$NEWLOADED" >> /etc/ethernetmodules
  1595.   fi
  1596.   TOPMSG="$L_TOPMSG_Module_Saved_p1 '$NEWLOADED' $L_TOPMSG_Module_Saved_p2"
  1597.   setDefaultMODULEBUTTONS
  1598. } # end saveNewModule
  1599.  
  1600. #=============================================================================
  1601. unloadNewModule()
  1602. {
  1603.   # unload newly loaded module
  1604.   modprobe -r "$NEWLOADED"
  1605.   grep -v "$NEWLOADED" /etc/ethernetmodules > /etc/ethernetmodules.tmp
  1606.   #sync
  1607.   mv -f /etc/ethernetmodules.tmp /etc/ethernetmodules
  1608.   TOPMSG="$L_TOPMSG_Module_Unloaded_p1 '$NEWLOADED' $L_TOPMSG_Module_Unloaded_p2 '$NEWLOADED' $L_TOPMSG_Module_Unloaded_p3"
  1609.  
  1610.   setDefaultMODULEBUTTONS
  1611.  
  1612.   refreshMainWindowInfo
  1613. } # end unloadNewModule
  1614.  
  1615. #=============================================================================
  1616. validip() {
  1617.   # uses dotquad.c to parse $1 as a dotted-quad IP address
  1618.   if dotquad "$1" > /dev/null 2>&1
  1619.   then
  1620.     return 0
  1621.   else
  1622.     return 1
  1623.   fi
  1624. } #end of validip function
  1625.  
  1626. #=============================================================================
  1627. setDefaultMODULEBUTTONS ()
  1628. {
  1629.   MODULEBUTTONS="
  1630. <hbox>
  1631.     <text>
  1632.         <label>\"$L_TEXT_Default_Module_Buttons\"</label>
  1633.     </text>
  1634.     <vbox>
  1635.         <pixmap><input file>$BLANK_IMAGE</input></pixmap>
  1636.         <button>
  1637.             <label>$L_BUTTON_Load_Module</label>
  1638.             <action>EXIT:10</action>
  1639.         </button>
  1640.     </vbox>
  1641. </hbox>"
  1642. } # end setDefaultMODULEBUTTONS
  1643.  
  1644. #=============================================================================
  1645. # Dougal: a function to find info about interface:
  1646. findInterfaceInfo()
  1647. {
  1648.   local INT="$1"
  1649.   TYPE=""
  1650.   INFO=""
  1651.    
  1652.   local DEVICE=$(readlink /sys/class/net/$INT/device)
  1653.   DEVICE=${DEVICE##*/}
  1654.  
  1655.   FI_DRIVER=$(readlink /sys/class/net/$INT/device/driver)
  1656.   case "$FI_DRIVER" in
  1657.    */bus/usb*) TYPE="usb" ;;
  1658.    */bus/ieee1394*) TYPE="firewire" ;;
  1659.    *) # pcmcia and pci apparently both appear as pci...
  1660.       if grep "^${FI_DRIVER##*/} " /etc/networkmodules |grep -q 'pcmcia:' ; then
  1661.         TYPE="pcmcia"
  1662.       else
  1663.         TYPE="pci"
  1664.       fi
  1665.       ;;
  1666.   esac
  1667.   FI_DRIVER=${FI_DRIVER##*/}
  1668.  
  1669.   if [ -d "/sys/class/net/$INT/wireless" ] || \
  1670.      [ "$FI_DRIVER" = "prism2_usb" ] || \
  1671.      grep -q "$INT" /proc/net/wireless
  1672.   then INTTYPE="$L_INTTYPE_Wireless"
  1673.   else INTTYPE="$L_INTTYPE_Ethernet"
  1674.   fi
  1675.  
  1676.   case "$TYPE" in
  1677.    pci|pcmcia) # pci device, get info from scanpci
  1678.      ## Try and replace below with actually getting the device and vendor values
  1679.      #DEVICE=$(cat /sys/class/net/$INT/device/device)
  1680.      read DEVICE <  /sys/class/net/$INT/device/device
  1681.      #VENDOR=$(cat /sys/class/net/$INT/device/vendor)
  1682.      read VENDOR < /sys/class/net/$INT/device/vendor
  1683.      INFO=$(scanpci | grep -Fi -A1 "vendor $VENDOR device $DEVICE" | tail -n1 | cut -d' ' -f1-3,5- | tr -d '[]' | sed 's%Corporation%%g ; s%Co\.%%g ; s%Ltd\.%%g ; s%Inc\.%%g ; s% ,%,%g' | tr -s ' ')
  1684.      #DEVICE=${DEVICE#*:}
  1685.      #local BUS=${DEVICE%:*}
  1686.      #local CARD=${DEVICE#*:} ; CARD=${CARD%.*}
  1687.      #local FUNC=${DEVICE#*.}
  1688.      #INFO=$(scanpci | grep -Fi -A1 "bus 0x00$BUS cardnum 0x$CARD function 0x$FUNC" | tail -n1 | cut -d' ' -f1-3,5- | tr -d '[]' | sed 's%Corporation%%g ; s%Co\.%%g ; s%Ltd\.%%g ; s% ,%,%g' | tr -s ' ')
  1689.      # if nothing found (pcmcia??), try lspci
  1690.      if [ ! "$INFO" ];then
  1691.        DEVICE=$(readlink /sys/class/net/$INT/device)
  1692.        DEVICE=${DEVICE#*:}
  1693.        INFO=$(lspci | grep -m1 "^${DEVICE} " | cut -d: -f3- | sed 's%Corporation%%g ; s%Co\.%%g ; s%Ltd\.%%g ; s% ,%,%g ; s%(rev [0-9a-z].)%%g' | tr -s ' ')
  1694.      fi
  1695.      ;;
  1696.    usb) # need to try and find info from both /proc/bus/usb/devices and lsusb
  1697.      ## 1) find device and vendor:
  1698.      #DEVICE=`cat /sys/class/net/$INT/device/device 2>/dev/null`
  1699.      #local VENDOR=`cat /sys/class/net/$INT/device/vendor 2>/dev/null`
  1700.      ## those files might not exist...try getting by module name
  1701.      #if [ -z "$DEVICE" -o -z "$VENDOR" ] ; then
  1702.        #local DEVINFO="`grep -F -B5 "Driver=$FI_DRIVER" /proc/bus/usb/devices | grep  '^P' | tr ' ' '\n' | grep -E 'Vendor|ProdID' | tr '\n' ' '`"
  1703.        #DEVICE=${DEVINFO#* } ; DEVICE=${DEVICE#*=} ; DEVICE=${DEVICE% }
  1704.        #VENDOR=${DEVINFO%% *} ; VENDOR=${VENDOR#*=}
  1705.      #fi
  1706.      ## 2) try looking for info in /proc/bus/usb/devices
  1707.      #if [ -n "$DEVICE" -a -n "$VENDOR" ] ; then
  1708.        #grep -Fi -A2 "Vendor=$VENDOR ProdID=$DEVICE" /proc/bus/usb/devices | grep '^S:' >/tmp/proc-info
  1709.        ### /tmp/proc-info can be blank, have lines with bad info or lines with good info...
  1710.        #local MANU="`grep -F 'Manufacturer=' /tmp/proc-info | cut -d= -f2`"
  1711.        #local PROD="`grep -F 'Product=' /tmp/proc-info | cut -d= -f2`"
  1712.        #rm /tmp/proc-info
  1713.        ### need to somehow decide if info (assuming we got it) is good
  1714.        ### (maybe if we have MANU or not)
  1715.        #if [ -n "$MANU" -a -n "$PROD" ] ; then
  1716.          #case "$PROD" in
  1717.           #*"$MANU"*) INFO="$PROD" ;;
  1718.           #*) INFO="$MANU $PROD" ;;
  1719.          #esac
  1720.        #else
  1721.          ## 3) try looking is lsusb output:
  1722.          #INFO="`lsusb -d $VENDOR:$DEVICE 2>/dev/null| head -n1 | cut -d' ' -f7-`"
  1723.        #fi
  1724.      #fi
  1725.      
  1726.      # possible alternative to all the above:
  1727.      # get the link to the device in dir in /sys/devices
  1728.      # (we only want the part of the top dir for it, like usb1/1-8
  1729.      local DEV_LINK=$(readlink /sys/class/net/$INT/device | grep -o ".*/usb[0-9]/[0-9]-[0-9]*")
  1730.      if [ -z "$DEV_LINK" ] ; then
  1731.        DEV_LINK=$(readlink /sys/class/net/$INT | grep -o ".*/usb[0-9]/[0-9]-[0-9]*")
  1732.        read PROD < /sys/class/net/$DEV_LINK/product
  1733.        read MANU < /sys/class/net/$DEV_LINK/manufacturer
  1734.      else
  1735.        read PROD < /sys/class/net/$INT/$DEV_LINK/product
  1736.        read MANU < /sys/class/net/$INT/$DEV_LINK/manufacturer
  1737.      fi
  1738.      if [ -n "$MANU" -a -n "$PROD" ] ; then
  1739.        case "$PROD" in
  1740.          *"$MANU"*) INFO="$PROD" ;;
  1741.          *) INFO="$MANU $PROD" ;;
  1742.        esac
  1743.      else # get info from module
  1744.        INFO=$(modinfo $FI_DRIVER |grep -m1 '^description' |tr -s ' ' |cut -d' ' -f2-)
  1745.      fi
  1746.      ;;
  1747.    #pcmcia) # I have no idea... try something generic
  1748.      # 1) find device and vendor:
  1749.    #  DEVICE=$(cat /sys/class/net/$INT/device/device)
  1750.    #  local VENDOR=$(cat /sys/class/net/$INT/device/vendor)
  1751.      # maybe use lspcmcia?
  1752.    #  ;;
  1753.    firewire)
  1754.      FI_DRIVER="eth1394"
  1755.      INFO="$L_INFO_Eth_Firewire"
  1756.      ;;
  1757.   esac
  1758.   #111015 strip out chars that might upset gtkdialog...
  1759.   [ "$MANU" ] && MANU="`echo -n "$MANU" | sed -e 's%[^a-zA-Z0-9 .]%%g'`"
  1760.   [ "$PROD" ] && PROD="`echo -n "$PROD" | sed -e 's%[^a-zA-Z0-9 .]%%g'`"
  1761.   [ "$INFO" ] && INFO="`echo -n "$INFO" | sed -e 's%[^a-zA-Z0-9 .]%%g'`"
  1762. } # end findInterfaceInfo
  1763.  
  1764. #=============================================================================
  1765. saveInterfaceSetup()
  1766. {
  1767.   INTERFACE="$1"
  1768.   # Dougal: use HWaddress for the config files!
  1769.   #HWADDRESS=`cat /sys/class/net/$1/address | tr a-z A-Z`
  1770.   # need to address from ifconfig, for firewire (/sys.../address gives 24-bit)
  1771.   HWADDRESS=$(ifconfig "$1" | grep "^$1" | tr -s ' ' | cut -d' ' -f5)
  1772.  
  1773. # create config file
  1774.        
  1775.   #if [ -e "/tmp/wireless-config" ] ; then
  1776.   if checkIfIsWireless "$INTERFACE" ; then
  1777.     # Dougal: only need to do this once
  1778.     if [ ! -s "${WLAN_INTERFACES_DIR}/$HWADDRESS.conf" ] ; then
  1779.       #cp -a /tmp/wireless-config "${WLAN_INTERFACES_DIR}/$HWADDRESS.conf"
  1780.       echo -e "INT_WPA_DRV='$PROFILE_WPA_DRV'\nUSE_WLAN_NG='$USE_WLAN_NG'" > ${WLAN_INTERFACES_DIR}/$HWADDRESS.conf
  1781.     fi
  1782.     # create interface config file
  1783.     echo "IS_WIRELESS='$IS_WIRELESS'" > ${NETWORK_INTERFACES_DIR}/$HWADDRESS.conf
  1784.     # Dougal: add info for static ip to profile, in case we use it
  1785.     # (note that -- currently at least -- that's the only use for MODECOMMANDS)
  1786.     #### (I am assuming the profile variable is still set...)
  1787.     # Need to clean up old info before adding new (pointed out by PaulBx1)
  1788.     sed -i '/^STATIC_IP=.*/d ; /^IP_ADDRESS=.*/d ; /^NETMASK=.*/d ; /DNS_SERVER^.*/d ; /^GATEWAY=.*/d ' "${PROFILES_DIR}/${PROFILE_AP_MAC}.${PROFILE_ENCRYPTION}.conf"
  1789.     echo -e "${MODECOMMANDS}" >>"${PROFILES_DIR}/${PROFILE_AP_MAC}.${PROFILE_ENCRYPTION}.conf"
  1790.   else
  1791.     #echo -e "${MODECOMMANDS}" > /etc/${INTERFACE}mode
  1792.     # Dougal: maybe append? in case used both for dhcp and static.
  1793.     echo -e "${MODECOMMANDS}\nIS_WIRELESS=''" > ${NETWORK_INTERFACES_DIR}/$HWADDRESS.conf
  1794.   fi
  1795.  
  1796. } # end saveInterfaceSetup
  1797.  
  1798. #=============================================================================
  1799. # Dougal: a little function to clean up /tmp when we're done...
  1800. cleanUpTmp(){
  1801.     rm -f /tmp/ethmoduleyesload.txt 2>/dev/null
  1802.     rm -f /tmp/loadedeth.txt 2>/dev/null
  1803. #   rm -f /tmp/wag-profiles_iwconfig.sh 2>/dev/null
  1804.     rm -f /tmp/net-setup_* 2>/dev/null
  1805.     rm -f /tmp/wpa_status.txt 2>/dev/null
  1806.     rm -f /tmp/net-setup_scan*.tmp 2>/dev/null
  1807. }
  1808.  
  1809. #=============================================================================
  1810. #=============== START OF SCRIPT BODY ====================
  1811. #=============================================================================
  1812.  
  1813.  
  1814. # Cleanup older temp files (in case didn't exit nicely last time)
  1815. cleanUpTmp
  1816.  
  1817. # Do we have pcmcia hardware?...
  1818. if elspci -l | grep -E -q '60700|60500' ; then
  1819.   MPCMCIA="yes"
  1820. fi
  1821.  
  1822. setDefaultMODULEBUTTONS
  1823.  
  1824. refreshMainWindowInfo
  1825.  
  1826. BGCOLOR="#ffe0e0" #light red.
  1827. TOPMSG="$L_TOPMSG_Initial"
  1828.  
  1829. showMainWindow
  1830.  
  1831. # Dougal: clean up /tmp
  1832. cleanUpTmp
  1833.  
  1834. #v411 BK hack to remove old network wizard configs so rc.sysinit won't use them if old wizard installed...
  1835. [ "`ls -1 /etc/network-wizard/network/interfaces 2>/dev/null`" != "" ] && rm -f /etc/*[0-9]mode
  1836.  
  1837. #=============================================================================
  1838. #================ END OF SCRIPT BODY =====================
  1839. #=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment