Advertisement
Guest User

LucidPuppy-net-setup.sh

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