Advertisement
s243a

rc.network() lines 408 to 650 - puppylinux

Oct 10th, 2016
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.07 KB | None | 0 0
  1. # lines 408 to 650 of /etc/rc.d/rc.network -- puppylinux
  2. #  http://www.pearltrees.com/s243a/lines-408-650-rc-network/id16447168
  3. # see if it's wireless
  4.   if [ -f "${WLAN_INTERFACES_DIR}/$HWADDRESS.conf" ] ; then
  5.     OPEN_NETWORKS=""
  6.     USE_WLAN_NG=""
  7.     # we need the driver name, in case it's ath5k
  8.     INTMODULE=$(readlink /sys/class/net/$INTERFACE/device/driver)
  9.     INTMODULE=${INTMODULE##*/}
  10.     . "${WLAN_INTERFACES_DIR}/$HWADDRESS.conf"
  11.     # this should tell us if to use wlan_ng etc.
  12.     if [ "$USE_WLAN_NG" = "yes" ] ; then ####### use wlanctl-ng ########
  13.       if runPrismScan "$INTERFACE" ; then #>/dev/null
  14.         # go over access points (POINTNUM set in function)
  15.         for P in $(seq 0 $POINTNUM) ; do
  16.           grep -Fq 'resultcode=success' /tmp/prism-scan$P || continue
  17.           getPrismCellParameters $P
  18.           # we should have CELL_ESSID, CELL_CHANNEL,
  19.           # CELL_AP_MAC, CELL_MODE, CELL_ENCRYPTION
  20.           # see if access point configured
  21.           #### need to see about the ecryption part: gives "true" or "no_value"
  22.           case $CELL_ENCRYPTION in
  23.             true) CELL_ENCRYPTION=WEP ;;
  24.             *) CELL_ENCRYPTION=Open ;;
  25.           esac
  26.           if [ -f "${PROFILES_DIR}/${CELL_AP_MAC}.${CELL_ENCRYPTION}.conf" ] ; then
  27.             # unset static ip variables
  28.             unset STATIC_IP IP_ADDRESS NETMASK DNS_SERVER1 DNS_SERVER2 GATEWAY
  29.             # source it
  30.             . "${PROFILES_DIR}/${CELL_AP_MAC}.${CELL_ENCRYPTION}.conf"
  31.             assignProfileData
  32.             # try connection
  33.             if useWlanctl && sleep 1 && testInterface ; then
  34.               # sleep a bit, just in case (net-setup.sh has 5 seconds!)
  35.               #sleep 1
  36.               # try and get ip address
  37.               if try_and_connect ; then
  38.                 # done! stop everything.
  39.                 rm /tmp/wlan-up /tmp/prism-* >/dev/null 2>&1
  40.                 success_message
  41.                 #exit
  42.                 # move to next interface (to allow more than one)
  43.                 GOT_ONE="yes"
  44.                 continue 2
  45.               else
  46.                 failure_message
  47.               fi
  48.             elif [ "$CELL_ENCRYPTION" = "Open" ] ; then # add to list of open networks
  49.               OPEN_NETWORKS="$OPEN_NETWORKS $P"
  50.             else # failure of useWlanctl
  51.               failure_message
  52.             fi #if useWlanctl &&
  53.           fi #if [ -f "${PROFILES_DIR}/${CELL_AP_MAC}.${CELL_ENCRYPTION}.conf" ] ; then
  54.         done # for P in
  55.         # if we got here, we are not connected yet, look at open networks
  56.         if [ -n "$OPEN_NETWORKS" ] ; then
  57.           WLAN_SECURE="opensystem"
  58.           PROFILE_KEY=""
  59.           # unset static ip variables
  60.           unset STATIC_IP IP_ADDRESS NETMASK DNS_SERVER1 DNS_SERVER2 GATEWAY
  61.           for P in $OPEN_NETWORKS ; do
  62.             grep -Fq 'resultcode=success' /tmp/prism-scan$P || continue
  63.             getPrismCellParameters $P
  64.             # set the PROFILE_ variables
  65.             PROFILE_ESSID="$CELL_ESSID"
  66.             if useWlanctl && sleep 1 && testInterface ; then
  67.               # sleep a bit, just in case (net-setup.sh has 5 seconds!)
  68.               #sleep 1
  69.               # try and get ip address
  70.               if try_and_connect ; then
  71.                 # done! stop everything.
  72.                 rm /tmp/wlan-up /tmp/prism-* >/dev/null 2>&1
  73.                 success_message
  74.                 #exit
  75.                 # move to next interface (to allow more than one)
  76.                 GOT_ONE="yes"
  77.                 continue 2
  78.               else
  79.                 failure_message
  80.               fi
  81.             else # failure of useWlanctl
  82.               failure_message
  83.             fi
  84.           done
  85.         fi
  86.         rm /tmp/wlan-up /tmp/prism-* >/dev/null 2>&1
  87.       else
  88.         echo "wireless scan with wlanctl-ng failed... skipping interface"
  89.         # clean up (kills dhcpcd etc)
  90.         cleanUpInterface "$INTERFACE"
  91.         ifconfig "$INTERFACE" down
  92.         # go to next interface
  93.         continue
  94.       fi # if runPrismScan
  95.    
  96.     else #################### use the usual iwconfig ####################
  97.       # scan for available networks
  98.       run_iw_scan
  99.       #if [ -n "$SCAN_LIST" ]; then
  100.       if [ -n "$CELL_LIST" ]; then
  101.         #  Dougal: something odd. seems like (at least with some drivers), we
  102.         #+ need to "refresh" after scanning...
  103.         ifconfig "$INTERFACE" down
  104.         ifconfig "$INTERFACE" up
  105.         #CELL_LIST=$(echo "$SCAN_LIST" | grep -Eo "Cell [0-9]+" | cut -f2 -d " ")
  106.         # let the user create a priority list of which networks to use first
  107.         # (will be included in wireless config file, contains mac addresses)
  108.         if [ "$PRIORITY_LIST" ] ; then
  109.           PRIOR_CELLS=""
  110.           for ONE in $PRIORITY_LIST ; do
  111.             # see if it was found, then move cell number to start...
  112.             #ACELL=$(echo "$SCAN_LIST" | grep -F "Address: $ONE" | awk '{print $2}')
  113.             ACELL=$(grep -F "Address: $ONE" $ScanListFile | awk '{print $2}')
  114.             if [ "$ACELL" ] ; then
  115.               PRIOR_CELLS="$PRIOR_CELLS $ACELL"
  116.               # remove from cell list (BASHISM!)
  117.               #CELL_LIST=${CELL_LIST/$ACELL/}
  118.               CELL_LIST=$(echo "$CELL_LIST" | sed "s/$ACELL//")
  119.             fi
  120.           done
  121.           CELL_LIST="$PRIOR_CELLS $CELL_LIST"
  122.         fi
  123.         for CELL in $CELL_LIST ; do
  124.           Get_Cell_Parameters $CELL
  125.           # we should have at least some of:
  126.           # CELL_ESSID, CELL_FREQ, CELL_CHANNEL, CELL_QUALITY,
  127.           # CELL_AP_MAC, CELL_MODE, CELL_ENCRYPTION
  128.           # see if it's open or not
  129.           if [ "$CELL_ENCRYPTION" = "on" ] ; then
  130.             # get only encrypted profiles (might have problems with globbing?)
  131.             for PROF in $(ls ${PROFILES_DIR}/${CELL_AP_MAC}.W[EP][PA]*.conf 2>/dev/null) ; do
  132.               SUCCESS=""
  133.               # unset static ip variables
  134.               unset STATIC_IP IP_ADDRESS NETMASK DNS_SERVER1 DNS_SERVER2 GATEWAY
  135.               # source it
  136.               . "$PROF"
  137.               # assign to PROFILE_ names...
  138.               assignProfileData
  139.               case $PROFILE_ENCRYPTION in
  140.                 WPA|WPA2)
  141.                   WPA_CONF="${WPA_SUPP_DIR}/${PROFILE_AP_MAC}.${PROFILE_ENCRYPTION}.conf"
  142.                   useWpaSupplicant "$WPA_CONF" && SUCCESS="yes"
  143.                   ;;
  144.                 WEP)
  145.                   useIwconfig && SUCCESS="yes"
  146.                   ;;
  147.               esac
  148.               if [ "$SUCCESS" = "yes" ] && sleep 1 && testInterface ; then
  149.                 # sleep a bit, just in case (net-setup.sh has 5 seconds!)
  150.                 #sleep 1
  151.                 # try and get ip address
  152.                 if try_and_connect ; then
  153.                   # done! stop everything.
  154.                   success_message
  155.                   # clean scan files
  156.                   rm /tmp/iwscan*.tmp 2>/dev/null
  157.                   #exit
  158.                   # move to next interface (to allow more than one)
  159.                   GOT_ONE="yes"
  160.                   continue 3
  161.                 else
  162.                   failure_message
  163.                 fi
  164.               else # iwconfig/wpa_supp failed
  165.                 failure_message
  166.               fi
  167.             done # for PROF in
  168.           else # encryption off
  169.             # see if it was configured
  170.             if [ -f "${PROFILES_DIR}/${CELL_AP_MAC}.Open.conf" ] ; then
  171.               # unset static ip variables
  172.               unset STATIC_IP IP_ADDRESS NETMASK DNS_SERVER1 DNS_SERVER2 GATEWAY
  173.               # source it
  174.               . "${PROFILES_DIR}/${CELL_AP_MAC}.Open.conf"
  175.               # assign to PROFILE_ names...
  176.               assignProfileData
  177.               # try connection
  178.               if useIwconfig && sleep 1 && testInterface ; then
  179.                 # sleep a bit, just in case (net-setup.sh has 5 seconds!)
  180.                 #sleep 1
  181.                 # try and get ip address
  182.                 if try_and_connect ; then
  183.                   # done! stop everything.
  184.                   success_message
  185.                   # clean scan files
  186.                   rm /tmp/iwscan*.tmp 2>/dev/null
  187.                   #exit
  188.                   # move to next interface (to allow more than one)
  189.                   GOT_ONE="yes"
  190.                   continue 2
  191.                 else
  192.                   failure_message
  193.                 fi
  194.               else
  195.                 failure_message
  196.               fi
  197.             else # add to list of open networks
  198.               OPEN_NETWORKS="$OPEN_NETWORKS $CELL"
  199.             fi
  200.           fi # if [ "$CELL_ENCRYPTION" = "on" ] ; then  
  201.         done # for CELL in
  202.         # if we got here, we are not connected yet, look at open networks
  203.         if [ "$OPEN_NETWORKS" ] ; then
  204.           # unset static ip variables
  205.           unset STATIC_IP IP_ADDRESS NETMASK DNS_SERVER1 DNS_SERVER2 GATEWAY
  206.           for CELL in $OPEN_NETWORKS ; do
  207.             Get_Cell_Parameters $CELL
  208.             # need to convert to PROFILE_...
  209.             cellToProfile
  210.             if useIwconfig && sleep 1 && testInterface ; then
  211.               # sleep a bit, just in case (net-setup.sh has 5 seconds!)
  212.               #sleep 1
  213.               # try and get ip address
  214.               if try_and_connect ; then
  215.                 success_message
  216.                 # clean scan files
  217.                 rm /tmp/iwscan*.tmp 2>/dev/null
  218.                 #exit
  219.                 # move to next interface (to allow more than one)
  220.                 GOT_ONE="yes"
  221.                 continue 2
  222.               else
  223.                 failure_message
  224.               fi
  225.             else
  226.               failure_message
  227.             fi
  228.           done #for CELL in $OPEN_NETWORKS
  229.         fi
  230.       else # if [ -n "$CELL_LIST" ]; then
  231.         echo "wireless scan with iwlist failed (no networks found)... skipping interface"
  232.         # clean up (kills dhcpcd etc)
  233.         cleanUpInterface "$INTERFACE"
  234.         ifconfig "$INTERFACE" down
  235.         # clean scan files
  236.         rm /tmp/iwscan*.tmp 2>/dev/null
  237.         # go to next interface
  238.         continue
  239.       fi
  240.     fi
  241.     # if we got here, config file exists, but nothing worked
  242.     echo "failed to configure wireless interface $INTERFACE... skipping"
  243.     ifconfig "$INTERFACE" down
  244.     continue
  245. fi # if [ -f "${WLAN_INTERFACES_DIR}/$HWADDRESS.conf" ] ; then
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement