Allow bash arrays to be flattened to make some configs easier.

This commit is contained in:
Roy Marples 2007-11-14 18:23:59 +00:00
parent a215128475
commit 0c25b359de
5 changed files with 91 additions and 86 deletions

View File

@ -118,16 +118,16 @@
# HINTS # HINTS
# #
# Most users will just need to set the following options # Most users will just need to set the following options
# key_ESSID1="s:yourkeyhere enc open" # s: means a text key # key_SSID1="s:yourkeyhere enc open" # s: means a text key
# key_ESSID2="aaaa-bbbb-cccc-dd" # no s: means a hex key # key_SSID2="aaaa-bbbb-cccc-dd" # no s: means a hex key
# preferred_aps="ESSID 1 # preferred_aps="SSID 1
#ESSID 2" #SSID 2"
# #
# Clear? Good. Now configure your wireless network below # Clear? Good. Now configure your wireless network below
#################################### ####################################
# SETTINGS # 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 # to scan for available Access Points
# I would only set this as a last resort really - use the preferred_aps # I would only set this as a last resort really - use the preferred_aps
# setting at the bottom of this file # setting at the bottom of this file
@ -155,70 +155,68 @@
# Setup any other config commands. This is basically the ifconfig argument # Setup any other config commands. This is basically the ifconfig argument
# without the ifconfig $iface. # without the ifconfig $iface.
#ifconfig_eth0="" #ifconfig_eth0=""
# You can do the same per ESSID too. # You can do the same per SSID too.
#ifconfig_ESSID="" #ifconfig_SSID=""
# Seconds to wait until associated. The default is to wait 10 seconds. # Seconds to wait until associated. The default is to wait 10 seconds.
# 0 means wait indefinitely. WARNING: this can cause an infinite delay when # 0 means wait indefinitely. WARNING: this can cause an infinite delay when
# booting. # booting.
#associate_timeout_eth0="5" #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 # The encryption type (open or restricted) must match the
# encryption type on the Access Point. # encryption type on the Access Point.
# To set a hex key, prefix with 0x # To set a hex key, prefix with 0x
#key_ESSID="0x12341234123412341234123456" #key_SSID="0x12341234123412341234123456"
# or you can use strings. Passphrase IS NOT supported # or you can use strings. Passphrase IS NOT supported
#key_ESSID="foobar" #key_SSID="foobar"
#key_ESSID="foobar" #key_SSID="foobar"
# WEP key for the AP with MAC address 001122334455 # WEP key for the AP with MAC address 001122334455
#mac_key_001122334455="foobar" #mac_key_001122334455="foobar"
# You can also override the interface settings found in /etc/conf.d/net # 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 # per SSID - which is very handy if you use different networks a lot
#config_ESSID="dhcp" #config_SSID="dhcp"
#routes_ESSID= #routes_SSID=
#fallback_ESSID= #fallback_SSID=
# Setting name/domain server causes /etc/resolv.conf to be overwritten # 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 # Note that if DHCP is used, and you want this to take precedence then
# please put -R in your dhcpcd options # please put -R in your dhcpcd options
#dns_servers_ESSID="192.168.0.1 192.168.0.2" #dns_servers_SSID="192.168.0.1 192.168.0.2"
#dns_domain_ESSID="some.domain" #dns_domain_SSID="some.domain"
#dns_search_path_ESSID="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 # Please check the man page for resolv.conf for more information
# as domain and search (searchdomains) are mutually exclusive and # as domain and search (searchdomains) are mutually exclusive and
# searchdomains takes precedence # searchdomains takes precedence
# You can also set any of the /etc/conf.d/net variables per MAC address # 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 # networking configs. Below is an example - of course you use the same
# method with other variables # method with other variables
#config_001122334455="dhcp" #config_001122334455="dhcp"
#dns_servers_001122334455="192.168.0.1 192.168.0.2" #dns_servers_001122334455="192.168.0.1 192.168.0.2"
# Map a MAC address to an ESSID # Map a MAC address to an SSID
# This is used when the Access Point is not broadcasting it's ESSID # This is used when the Access Point is not broadcasting it's SSID
# WARNING: This will override the ESSID being broadcast due to some # WARNING: This will override the SSID being broadcast due to some
# Access Points sending an ESSID even when they have been configured # Access Points sending an SSID even when they have been configured
# not to! # 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 # it should map to
#mac_essid_001122334455="ESSID" #mac_essid_001122334455="SSID"
# This lists the preferred ESSIDs to connect to in order # This lists the preferred SSIDs to connect to in order
# ESSID's can contain any characters here as they must match the broadcast # SSID's can contain any characters here as they must match the broadcast
# ESSID exactly. # SSID exactly.
# Surround each ESSID with the " character and seperate them with a space # Surround each SSID with the " character and seperate them with a space
# If the first ESSID isn't found then it moves onto the next # 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 # If this isn't defined then it connects to the first one found
#preferred_aps="ESSID 1 #preferred_aps="SSID1 SSID2"
#ESSID 2"
# You can also define a preferred_aps list per interface # You can also define a preferred_aps list per interface
#preferred_aps_eth0="ESSID 3 #preferred_aps_eth0="SSID3 SSID4"
#ESSID 4"
# You can also say whether we only connect to preferred APs or not # You can also say whether we only connect to preferred APs or not
# Values are "any", "preferredonly", "forcepreferred", "forcepreferredonly" # Values are "any", "preferredonly", "forcepreferred", "forcepreferredonly"
@ -238,10 +236,8 @@
#associate_order_eth0="any" #associate_order_eth0="any"
# You can define blacklisted Access Points in the same way # You can define blacklisted Access Points in the same way
#blacklist_aps="ESSID 1 #blacklist_aps="SSID1 SSID2"
#ESSID 2" #blacklist_aps_eth0="SSID3 SSID4"
#blacklist_aps_eth0="ESSID 3
#ESSID 4"
# If you have more than one wireless card, you can say if you want # 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 # 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 # essid_eth0 is not set and your card is capable of scanning
# NOTE: preferred_aps list ignores blacklisted_aps - so if you have # 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 # wpa_supplicant

View File

@ -298,7 +298,7 @@
# please put -R in your dhcpcd options # please put -R in your dhcpcd options
#dns_servers_SSID="192.168.0.1 192.168.0.2" #dns_servers_SSID="192.168.0.1 192.168.0.2"
#dns_domain_SSID="some.domain" #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 # Please check the man page for resolv.conf for more information
# as domain and search (searchdomains) are mutually exclusive and # as domain and search (searchdomains) are mutually exclusive and
# searchdomains takes precedence # searchdomains takes precedence
@ -326,12 +326,10 @@
# Surround each SSID with the " character and seperate them with a space # 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 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 # If this isn't defined then it connects to the first one found
#preferred_aps="SSID 1 #preferred_aps="SSID1 SSID2"
#SSID 2"
# You can also define a preferred_aps list per interface # You can also define a preferred_aps list per interface
#preferred_aps_eth0="SSID 3 #preferred_aps_eth0="SSID3 SSID4"
#SSID 4'"
# You can also say whether we only connect to preferred APs or not # You can also say whether we only connect to preferred APs or not
# Values are "any", "preferredonly", "forcepreferred", "forcepreferredonly" and "forceany" # Values are "any", "preferredonly", "forcepreferred", "forcepreferredonly" and "forceany"
@ -348,10 +346,8 @@
#associate_order_eth0="any" #associate_order_eth0="any"
# You can define blacklisted Access Points in the same way # You can define blacklisted Access Points in the same way
#blacklist_aps="SSID 1 #blacklist_aps="SSID1 SSID2"
#SSID 2" #blacklist_aps_eth0="SSID3 SSID4"
#blacklist_aps_eth0="SSID 3
#SSID 4"
# If you have more than one wireless card, you can say if you want # 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 # to allow each card to associate with the same Access Point or not

View File

@ -340,7 +340,7 @@ iwconfig_scan() {
i=$((${i} + 1)) i=$((${i} + 1))
done done
local i=0 e= m= s= black="$(_get_array "blacklist_aps")" local i=0 e= m= s=
while [ ${i} -le ${APS} ] ; do while [ ${i} -le ${APS} ] ; do
eval x=\$MAC_${i} eval x=\$MAC_${i}
@ -374,14 +374,14 @@ iwconfig_scan() {
eoutdent eoutdent
fi fi
local IFS="$__IFS" eval set -- $(_flatten_array "blacklist_aps_${IFVAR}")
for x in ${black}; do [ $# = 0 ] && eval set -- $(_flatten_array "blacklist_aps")
for x in "$@"; do
if [ "${x}" = "${s}" ] ; then if [ "${x}" = "${s}" ] ; then
ewarn "${s} has been blacklisted - not connecting" ewarn "${s} has been blacklisted - not connecting"
unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} CAPS_${i} unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} CAPS_${i}
fi fi
done done
unset IFS
i=$((${i} + 1)) i=$((${i} + 1))
done done
eoutdent eoutdent
@ -389,15 +389,13 @@ iwconfig_scan() {
} }
iwconfig_force_preferred() { 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" ewarn "Trying to force preferred in case they are hidden"
local pref="$(_get_array "preferred_aps_${IFVAR}")" local ssid=
[ -z "${pref}" ] && pref="$(_get_array "preferred_aps")" for ssid in "$@"; do
local ssid= IFS="$__IFS"
for ssid in ${pref}; do
unset IFS
local found_AP=false i=0 e= local found_AP=false i=0 e=
while [ ${i} -le ${APS:--1} ] ; do while [ ${i} -le ${APS:--1} ] ; do
eval e=\$SSID_${i} eval e=\$SSID_${i}
@ -418,13 +416,12 @@ iwconfig_force_preferred() {
} }
iwconfig_connect_preferred() { iwconfig_connect_preferred() {
local ssid= i=0 mode= mac= caps= freq= chan= eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
local pref="$(_get_array "preferred_aps_${IFVAR}")" [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
[ -z "${pref}" ] && pref="$(_get_array "preferred_aps")" [ $# = 0 ] && return 1
local IFS="$__IFS" local ssid= i=0 mode= mac= caps= freq= chan=
for ssid in ${pref}; do for ssid in "$@"; do
unset IFS
while [ ${i} -le ${APS} ] ; do while [ ${i} -le ${APS} ] ; do
eval e=\$SSID_${i} eval e=\$SSID_${i}
if [ "${e}" = "${ssid}" ] ; then if [ "${e}" = "${ssid}" ] ; then
@ -453,16 +450,15 @@ iwconfig_connect_not_preferred() {
continue continue
fi fi
local prefa="$(_get_array preferred_aps)" eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
[ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
pref=false pref=false
local IFS="$__IFS" for ssid in "$@"; do
for ssid in ${prefa}; do
if [ "${e}" = "${ssid}" ] ; then if [ "${e}" = "${ssid}" ] ; then
pref=true pref=true
break break
fi fi
done done
unset IFS
if ! ${pref} ; then if ! ${pref} ; then
SSID=${e} SSID=${e}

View File

@ -497,29 +497,26 @@ iwconfig_scan() {
eoutdent eoutdent
fi fi
local blacklist="$(_get_array "blacklist_aps")" eval set -- $(_flatten_array "blacklist_aps_${IFVAR}")
local IFS="$__IFS" [ $# = 0 ] && eval set -- $(_flatten_array "blacklist_aps")
for x in ${blacklist}; do for x in "$@"; do
unset IFS
if [ "${x}" = "${s}" ] ; then if [ "${x}" = "${s}" ] ; then
ewarn "${s} has been blacklisted - not connecting" ewarn "${s} has been blacklisted - not connecting"
unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} ENC_${i} unset SSID_${i} MAC_${i} CHAN_${i} QUALITY_${i} ENC_${i}
fi fi
done done
unset IFS
i=$((${i} + 1)) i=$((${i} + 1))
done done
eoutdent eoutdent
} }
iwconfig_force_preferred() { 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" ewarn "Trying to force preferred in case they are hidden"
local pref="$(_get_array "preferred_aps")" ssid= for ssid in "$@"; do
local IFS="$__IFS"
for ssid in ${pref}; do
unset IFS
local found_AP=false i=0 e= local found_AP=false i=0 e=
while [ ${i} -le ${APS} ] ; do while [ ${i} -le ${APS} ] ; do
eval e=\$SSID_${i} eval e=\$SSID_${i}
@ -541,9 +538,10 @@ iwconfig_force_preferred() {
iwconfig_connect_preferred() { iwconfig_connect_preferred() {
local ssid= i= mode= mac= enc= freq= chan= local ssid= i= mode= mac= enc= freq= chan=
local pref="$(_get_array preferred_aps)" eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
local IFS="$__IFS" [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
for ssid in ${pref}; do
for ssid in "$@"; do
unset IFS unset IFS
i=0 i=0
while [ ${i} -le ${APS} ] ; do while [ ${i} -le ${APS} ] ; do
@ -571,15 +569,14 @@ iwconfig_connect_not_preferred() {
while [ ${i} -le ${APS} ] ; do while [ ${i} -le ${APS} ] ; do
eval e=\$SSID_${i} eval e=\$SSID_${i}
if [ -n "${e}" ] ; then if [ -n "${e}" ] ; then
local prefa="$(_get_array preferred_aps)" eval set -- $(_flatten_array "preferred_aps_${IFVAR}")
local IFS="$__IFS" [ $# = 0 ] && eval set -- $(_flatten_array "preferred_aps")
for ssid in ${prefa}; do for ssid in "$@"; do
if [ "${e}" = "${ssid}" ] ; then if [ "${e}" = "${ssid}" ] ; then
pref=true pref=true
break break
fi fi
done done
unset IFS
if ! ${pref} ; then if ! ${pref} ; then
SSID=${e} SSID=${e}

View File

@ -87,6 +87,26 @@ _get_array() {
[ -n "${_a}" ] [ -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() { _wait_for_carrier() {
local timeout= efunc=einfon local timeout= efunc=einfon