diff options
-rw-r--r-- | conf.d.BSD/net.example | 74 | ||||
-rw-r--r-- | conf.d.Linux/net.example | 14 | ||||
-rw-r--r-- | net.BSD/iwconfig.sh | 38 | ||||
-rw-r--r-- | net.Linux/iwconfig.sh | 31 | ||||
-rwxr-xr-x | sh/net.sh | 20 |
5 files changed, 91 insertions, 86 deletions
diff --git a/conf.d.BSD/net.example b/conf.d.BSD/net.example index fe9eec66..9dae1035 100644 --- a/conf.d.BSD/net.example +++ b/conf.d.BSD/net.example @@ -118,16 +118,16 @@ # HINTS # # Most users will just need to set the following options -# key_ESSID1="s:yourkeyhere enc open" # s: means a text key -# key_ESSID2="aaaa-bbbb-cccc-dd" # no s: means a hex key -# preferred_aps="ESSID 1 -#ESSID 2" +# key_SSID1="s:yourkeyhere enc open" # s: means a text key +# key_SSID2="aaaa-bbbb-cccc-dd" # no s: means a hex key +# preferred_aps="SSID 1 +#SSID 2" # # Clear? Good. Now configure your wireless network below #################################### # SETTINGS -# Hard code an ESSID to an interface - leave this unset if you wish the driver +# Hard code an SSID to an interface - leave this unset if you wish the driver # to scan for available Access Points # I would only set this as a last resort really - use the preferred_aps # setting at the bottom of this file @@ -155,70 +155,68 @@ # Setup any other config commands. This is basically the ifconfig argument # without the ifconfig $iface. #ifconfig_eth0="" -# You can do the same per ESSID too. -#ifconfig_ESSID="" +# You can do the same per SSID too. +#ifconfig_SSID="" # Seconds to wait until associated. The default is to wait 10 seconds. # 0 means wait indefinitely. WARNING: this can cause an infinite delay when # booting. #associate_timeout_eth0="5" -# Define a WEP key per ESSID or MAC address (of the AP, not your card) +# Define a WEP key per SSID or MAC address (of the AP, not your card) # The encryption type (open or restricted) must match the # encryption type on the Access Point. # To set a hex key, prefix with 0x -#key_ESSID="0x12341234123412341234123456" +#key_SSID="0x12341234123412341234123456" # or you can use strings. Passphrase IS NOT supported -#key_ESSID="foobar" -#key_ESSID="foobar" +#key_SSID="foobar" +#key_SSID="foobar" # WEP key for the AP with MAC address 001122334455 #mac_key_001122334455="foobar" # You can also override the interface settings found in /etc/conf.d/net -# per ESSID - which is very handy if you use different networks a lot -#config_ESSID="dhcp" -#routes_ESSID= -#fallback_ESSID= +# per SSID - which is very handy if you use different networks a lot +#config_SSID="dhcp" +#routes_SSID= +#fallback_SSID= # Setting name/domain server causes /etc/resolv.conf to be overwritten # Note that if DHCP is used, and you want this to take precedence then # please put -R in your dhcpcd options -#dns_servers_ESSID="192.168.0.1 192.168.0.2" -#dns_domain_ESSID="some.domain" -#dns_search_path_ESSID="search.this.domain search.that.domain" +#dns_servers_SSID="192.168.0.1 192.168.0.2" +#dns_domain_SSID="some.domain" +#dns_search_SSID="search.this.domain search.that.domain" # Please check the man page for resolv.conf for more information # as domain and search (searchdomains) are mutually exclusive and # searchdomains takes precedence # You can also set any of the /etc/conf.d/net variables per MAC address -# incase you use Access Points with the same ESSID but need different +# incase you use Access Points with the same SSID but need different # networking configs. Below is an example - of course you use the same # method with other variables #config_001122334455="dhcp" #dns_servers_001122334455="192.168.0.1 192.168.0.2" -# Map a MAC address to an ESSID -# This is used when the Access Point is not broadcasting it's ESSID -# WARNING: This will override the ESSID being broadcast due to some -# Access Points sending an ESSID even when they have been configured +# Map a MAC address to an SSID +# This is used when the Access Point is not broadcasting it's SSID +# WARNING: This will override the SSID being broadcast due to some +# Access Points sending an SSID even when they have been configured # not to! -# Change 001122334455 to the MAC address and ESSID to the ESSID +# Change 001122334455 to the MAC address and SSID to the SSID # it should map to -#mac_essid_001122334455="ESSID" +#mac_essid_001122334455="SSID" -# This lists the preferred ESSIDs to connect to in order -# ESSID's can contain any characters here as they must match the broadcast -# ESSID exactly. -# Surround each ESSID with the " character and seperate them with a space -# If the first ESSID isn't found then it moves onto the next +# This lists the preferred SSIDs to connect to in order +# SSID's can contain any characters here as they must match the broadcast +# SSID exactly. +# Surround each SSID with the " character and seperate them with a space +# If the first SSID isn't found then it moves onto the next # If this isn't defined then it connects to the first one found -#preferred_aps="ESSID 1 -#ESSID 2" +#preferred_aps="SSID1 SSID2" # You can also define a preferred_aps list per interface -#preferred_aps_eth0="ESSID 3 -#ESSID 4" +#preferred_aps_eth0="SSID3 SSID4" # You can also say whether we only connect to preferred APs or not # Values are "any", "preferredonly", "forcepreferred", "forcepreferredonly" @@ -238,10 +236,8 @@ #associate_order_eth0="any" # You can define blacklisted Access Points in the same way -#blacklist_aps="ESSID 1 -#ESSID 2" -#blacklist_aps_eth0="ESSID 3 -#ESSID 4" +#blacklist_aps="SSID1 SSID2" +#blacklist_aps_eth0="SSID3 SSID4" # If you have more than one wireless card, you can say if you want # to allow each card to associate with the same Access Point or not @@ -254,7 +250,7 @@ # essid_eth0 is not set and your card is capable of scanning # NOTE: preferred_aps list ignores blacklisted_aps - so if you have -# the same ESSID in both, well, you're a bit silly :p +# the same SSID in both, well, you're a bit silly :p ################################################## # wpa_supplicant diff --git a/conf.d.Linux/net.example b/conf.d.Linux/net.example index cda4edb6..be5e020c 100644 --- a/conf.d.Linux/net.example +++ b/conf.d.Linux/net.example @@ -298,7 +298,7 @@ # please put -R in your dhcpcd options #dns_servers_SSID="192.168.0.1 192.168.0.2" #dns_domain_SSID="some.domain" -#dns_search_path_SSID="search.this.domain search.that.domain" +#dns_search_SSID="search.this.domain search.that.domain" # Please check the man page for resolv.conf for more information # as domain and search (searchdomains) are mutually exclusive and # searchdomains takes precedence @@ -326,12 +326,10 @@ # Surround each SSID with the " character and seperate them with a space # If the first SSID isn't found then it moves onto the next # If this isn't defined then it connects to the first one found -#preferred_aps="SSID 1 -#SSID 2" +#preferred_aps="SSID1 SSID2" # You can also define a preferred_aps list per interface -#preferred_aps_eth0="SSID 3 -#SSID 4'" +#preferred_aps_eth0="SSID3 SSID4" # You can also say whether we only connect to preferred APs or not # Values are "any", "preferredonly", "forcepreferred", "forcepreferredonly" and "forceany" @@ -348,10 +346,8 @@ #associate_order_eth0="any" # You can define blacklisted Access Points in the same way -#blacklist_aps="SSID 1 -#SSID 2" -#blacklist_aps_eth0="SSID 3 -#SSID 4" +#blacklist_aps="SSID1 SSID2" +#blacklist_aps_eth0="SSID3 SSID4" # If you have more than one wireless card, you can say if you want # to allow each card to associate with the same Access Point or not diff --git a/net.BSD/iwconfig.sh b/net.BSD/iwconfig.sh index 91d5b006..98254648 100644 --- a/net.BSD/iwconfig.sh +++ b/net.BSD/iwconfig.sh @@ -340,7 +340,7 @@ iwconfig_scan() { i=$((${i} + 1)) done - local i=0 e= m= s= black="$(_get_array "blacklist_aps")" + local i=0 e= m= s= while [ ${i} -le ${APS} ] ; do eval x=\$MAC_${i} @@ -374,14 +374,14 @@ iwconfig_scan() { eoutdent fi - local IFS="$__IFS" - for x in ${black}; do + eval set -- $(_flatten_array "blacklist_aps_${IFVAR}") + [ $# = 0 ] && eval set -- $(_flatten_array "blacklist_aps") + for x in "$@"; do if [ "${x}" = "${s}" ] ; then ewarn "${s} has been blacklisted - not connecting" unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} CAPS_${i} fi done - unset IFS i=$((${i} + 1)) done eoutdent @@ -389,15 +389,13 @@ iwconfig_scan() { } iwconfig_force_preferred() { - [ -z "${preferred_aps}" ] && return 1 + eval set -- $(_flatten_array "preferred_aps_${IFVAR}") + [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") + [ $# = 0 ] && return 1 ewarn "Trying to force preferred in case they are hidden" - local pref="$(_get_array "preferred_aps_${IFVAR}")" - [ -z "${pref}" ] && pref="$(_get_array "preferred_aps")" - - local ssid= IFS="$__IFS" - for ssid in ${pref}; do - unset IFS + local ssid= + for ssid in "$@"; do local found_AP=false i=0 e= while [ ${i} -le ${APS:--1} ] ; do eval e=\$SSID_${i} @@ -418,13 +416,12 @@ iwconfig_force_preferred() { } iwconfig_connect_preferred() { - local ssid= i=0 mode= mac= caps= freq= chan= - local pref="$(_get_array "preferred_aps_${IFVAR}")" - [ -z "${pref}" ] && pref="$(_get_array "preferred_aps")" + eval set -- $(_flatten_array "preferred_aps_${IFVAR}") + [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") + [ $# = 0 ] && return 1 - local IFS="$__IFS" - for ssid in ${pref}; do - unset IFS + local ssid= i=0 mode= mac= caps= freq= chan= + for ssid in "$@"; do while [ ${i} -le ${APS} ] ; do eval e=\$SSID_${i} if [ "${e}" = "${ssid}" ] ; then @@ -453,16 +450,15 @@ iwconfig_connect_not_preferred() { continue fi - local prefa="$(_get_array preferred_aps)" + eval set -- $(_flatten_array "preferred_aps_${IFVAR}") + [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") pref=false - local IFS="$__IFS" - for ssid in ${prefa}; do + for ssid in "$@"; do if [ "${e}" = "${ssid}" ] ; then pref=true break fi done - unset IFS if ! ${pref} ; then SSID=${e} diff --git a/net.Linux/iwconfig.sh b/net.Linux/iwconfig.sh index c70442e1..6aa40029 100644 --- a/net.Linux/iwconfig.sh +++ b/net.Linux/iwconfig.sh @@ -497,29 +497,26 @@ iwconfig_scan() { eoutdent fi - local blacklist="$(_get_array "blacklist_aps")" - local IFS="$__IFS" - for x in ${blacklist}; do - unset IFS + eval set -- $(_flatten_array "blacklist_aps_${IFVAR}") + [ $# = 0 ] && eval set -- $(_flatten_array "blacklist_aps") + for x in "$@"; do if [ "${x}" = "${s}" ] ; then ewarn "${s} has been blacklisted - not connecting" unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} ENC_${i} fi done - unset IFS i=$((${i} + 1)) done eoutdent } iwconfig_force_preferred() { - [ -z "${preferred_aps}" ] && return 1 + eval set -- $(_flatten_array "preferred_aps_${IFVAR}") + [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") + [ $# = 0 ] && return 1 ewarn "Trying to force preferred in case they are hidden" - local pref="$(_get_array "preferred_aps")" ssid= - local IFS="$__IFS" - for ssid in ${pref}; do - unset IFS + for ssid in "$@"; do local found_AP=false i=0 e= while [ ${i} -le ${APS} ] ; do eval e=\$SSID_${i} @@ -541,9 +538,10 @@ iwconfig_force_preferred() { iwconfig_connect_preferred() { local ssid= i= mode= mac= enc= freq= chan= - local pref="$(_get_array preferred_aps)" - local IFS="$__IFS" - for ssid in ${pref}; do + eval set -- $(_flatten_array "preferred_aps_${IFVAR}") + [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") + + for ssid in "$@"; do unset IFS i=0 while [ ${i} -le ${APS} ] ; do @@ -571,15 +569,14 @@ iwconfig_connect_not_preferred() { while [ ${i} -le ${APS} ] ; do eval e=\$SSID_${i} if [ -n "${e}" ] ; then - local prefa="$(_get_array preferred_aps)" - local IFS="$__IFS" - for ssid in ${prefa}; do + eval set -- $(_flatten_array "preferred_aps_${IFVAR}") + [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps") + for ssid in "$@"; do if [ "${e}" = "${ssid}" ] ; then pref=true break fi done - unset IFS if ! ${pref} ; then SSID=${e} @@ -87,6 +87,26 @@ _get_array() { [ -n "${_a}" ] } +# Flatten bash arrays to simple strings +_flatten_array() { + if [ -n "${BASH}" ] ; then + case "$(declare -p "$1" 2>/dev/null)" in + "declare -a "*) + eval "set -- \"\${$1[@]}\"" + for x in "$@"; do + printf "'%s' " "$(printf "$x" | sed "s:':'\\\'':g")" + done + return 0 + ;; + esac + fi + + eval _a=\$$1 + printf "%s" "${_a}" + printf "\n" + [ -n "${_a}" ] +} + _wait_for_carrier() { local timeout= efunc=einfon |