ifup-wireless: modify indentation; remove all the temporary files
Signed-off-by: Davide Madrisan <davide.madrisan@gmail.com>
This commit is contained in:
parent
60535caa3b
commit
a8c3002082
@ -1,28 +1,43 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright (c) 2003-2009 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
# Copyright (c) 2003-2009 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
||||||
# Copyright (c) 2003-2009 by Davide Madrisan <davide.madrisan@gmail.com>
|
# Copyright (c) 2003-2009,2013 by Davide Madrisan <davide.madrisan@gmail.com>
|
||||||
|
|
||||||
# Only meant to be called from ifup.
|
# Only meant to be called from ifup.
|
||||||
|
|
||||||
|
# Configure wireless network device options.
|
||||||
|
# Valid variables:
|
||||||
|
# WIRELESS_ESSID
|
||||||
|
# WIRELESS_MODE
|
||||||
|
# WIRELESS_ENCMODE:
|
||||||
|
# WIRELESS_NWID
|
||||||
|
# WIRELESS_CHANNEL
|
||||||
|
# WIRELESS_FREQUENCY
|
||||||
|
# WIRELESS_AP
|
||||||
|
# WIRELESS_FREQ
|
||||||
|
# WIRELESS_RATE
|
||||||
|
# WIRELESS_ENC
|
||||||
|
|
||||||
unset WIRELESS_OPTS WIRELESS_OPTS2
|
unset WIRELESS_OPTS WIRELESS_OPTS2
|
||||||
|
|
||||||
if [ "$WIRELESS_ESSID" ]; then
|
if [ "$WIRELESS_ESSID" ]; then
|
||||||
tmpfile=`tempfile`
|
tmpfile=`tempfile 2>/dev/null`
|
||||||
tmpfile1=`tempfile`
|
tmpfile1=`tempfile 2>/dev/null`
|
||||||
|
|
||||||
if [ "$tmpfile" ]; then
|
if [ "$tmpfile" ]; then
|
||||||
ifconfig ${DEVICE} up
|
ifconfig ${DEVICE} up
|
||||||
# sleep 1
|
|
||||||
unset vname found_essid
|
unset vname found_essid
|
||||||
# Note: iwlist scan essid option does not work with all drivers (see man iwlist)
|
# Note: iwlist scan essid option does not work with all drivers
|
||||||
# so we split cell information below
|
# (see man iwlist) so we split cell information below
|
||||||
iwlist ${DEVICE} scan essid $WIRELESS_ESSID > $tmpfile
|
iwlist ${DEVICE} scan essid $WIRELESS_ESSID > $tmpfile
|
||||||
# Note: sometimes iwlist scan fails with "Device or resource busy", so we try again
|
|
||||||
[ -s $tmpfile ] || {
|
# Note: sometimes iwlist scan fails with "Device or resource busy",
|
||||||
ifconfig ${DEVICE} down
|
# so we try again
|
||||||
|
[ -s $tmpfile ] ||
|
||||||
|
{ ifconfig ${DEVICE} down
|
||||||
ifconfig ${DEVICE} up
|
ifconfig ${DEVICE} up
|
||||||
iwlist ${DEVICE} scan essid $WIRELESS_ESSID > $tmpfile
|
iwlist ${DEVICE} scan essid $WIRELESS_ESSID > $tmpfile; }
|
||||||
}
|
|
||||||
cat $tmpfile | \
|
cat $tmpfile | \
|
||||||
while read line; do
|
while read line; do
|
||||||
if [ "${line:0:5}" = "Cell " ]; then
|
if [ "${line:0:5}" = "Cell " ]; then
|
||||||
@ -31,7 +46,9 @@ if [ "$WIRELESS_ESSID" ]; then
|
|||||||
echo $line >> $tmpfile1
|
echo $line >> $tmpfile1
|
||||||
[ "$line" = "ESSID:\"$WIRELESS_ESSID\"" ] && found_essid=1
|
[ "$line" = "ESSID:\"$WIRELESS_ESSID\"" ] && found_essid=1
|
||||||
done
|
done
|
||||||
|
|
||||||
> $tmpfile
|
> $tmpfile
|
||||||
|
|
||||||
cat $tmpfile1 | \
|
cat $tmpfile1 | \
|
||||||
while read line; do
|
while read line; do
|
||||||
vname=${line/:*}
|
vname=${line/:*}
|
||||||
@ -47,86 +64,91 @@ if [ "$WIRELESS_ESSID" ]; then
|
|||||||
vname=${vname/_(1)}
|
vname=${vname/_(1)}
|
||||||
vval=${line/*:}
|
vval=${line/*:}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vname=WIRELESS_AUTO_${vname/* }
|
vname=WIRELESS_AUTO_${vname/* }
|
||||||
vval=${vval/ }
|
vval=${vval/ }
|
||||||
vval=\"${vval/GHz*}\"
|
vval=\"${vval/GHz*}\"
|
||||||
if [ "$vname" = "WIRELESS_AUTO_Mode" -o "$vname" = "WIRELESS_AUTO_Channel" -o \
|
|
||||||
"$vname" = "WIRELESS_AUTO_Address" -o "$vname" = "WIRELESS_AUTO_Frequency" -o \
|
if [ "$vname" = "WIRELESS_AUTO_Mode" -o \
|
||||||
"$vname" = "WIRELESS_AUTO_IE" -o "$vname" = "WIRELESS_AUTO_Group_Cipher" -o \
|
"$vname" = "WIRELESS_AUTO_Channel" -o \
|
||||||
"$vname" = "WIRELESS_AUTO_Pairwise_Ciphers" -o "$vname" = "WIRELESS_AUTO_Authentication_Suites" ]; then
|
"$vname" = "WIRELESS_AUTO_Address" -o \
|
||||||
|
"$vname" = "WIRELESS_AUTO_Frequency" -o \
|
||||||
|
"$vname" = "WIRELESS_AUTO_IE" -o \
|
||||||
|
"$vname" = "WIRELESS_AUTO_Group_Cipher" -o \
|
||||||
|
"$vname" = "WIRELESS_AUTO_Pairwise_Ciphers" -o \
|
||||||
|
"$vname" = "WIRELESS_AUTO_Authentication_Suites" ]; then
|
||||||
echo $vname=$vval >> $tmpfile
|
echo $vname=$vval >> $tmpfile
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
. $tmpfile
|
. $tmpfile
|
||||||
rm -f $tmpfile $tmpfile1
|
|
||||||
else
|
else
|
||||||
echo "Warning: unable to create temporary file; skipping wireless autodetection"
|
echo "\
|
||||||
|
Warning: unable to create temporary file; skipping wireless autodetection"
|
||||||
fi
|
fi
|
||||||
|
rm -f $tmpfile $tmpfile1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$WIRELESS_MODE" ]; then
|
[ "$WIRELESS_ENCMODE" ] || WIRELESS_ENCMODE="open"
|
||||||
WIRELESS_OPTS="$WIRELESS_OPTS mode $WIRELESS_MODE"
|
|
||||||
#elif [ "$WIRELESS_AUTO_MODE" ]; then
|
[ "$WIRELESS_MODE" ] && WIRELESS_OPTS="$WIRELESS_OPTS mode $WIRELESS_MODE"
|
||||||
# WIRELESS_OPTS="$WIRELESS_OPTS mode $WIRELESS_AUTO_Mode"
|
[ "$WIRELESS_ESSID" ] && WIRELESS_OPTS="$WIRELESS_OPTS essid $WIRELESS_ESSID"
|
||||||
#else
|
[ "$WIRELESS_NWID" ] && WIRELESS_OPTS="$WIRELESS_OPTS nwid $WIRELESS_NWID"
|
||||||
#WIRELESS_OPTS="$WIRELESS_OPTS mode managed"
|
|
||||||
fi
|
|
||||||
if [ ! "$WIRELESS_ENCMODE" ]; then
|
|
||||||
WIRELESS_ENCMODE="open"
|
|
||||||
fi
|
|
||||||
if [ "$WIRELESS_ESSID" ]; then
|
|
||||||
WIRELESS_OPTS="$WIRELESS_OPTS essid $WIRELESS_ESSID"
|
|
||||||
fi
|
|
||||||
if [ "$WIRELESS_NWID" ]; then
|
|
||||||
WIRELESS_OPTS="$WIRELESS_OPTS nwid $WIRELESS_NWID"
|
|
||||||
fi
|
|
||||||
if [ "$WIRELESS_CHANNEL" ]; then
|
if [ "$WIRELESS_CHANNEL" ]; then
|
||||||
WIRELESS_OPTS="$WIRELESS_OPTS channel $WIRELESS_CHANNEL"
|
WIRELESS_OPTS="$WIRELESS_OPTS channel $WIRELESS_CHANNEL"
|
||||||
elif [ "$WIRELESS_AUTO_Channel" ]; then
|
elif [ "$WIRELESS_AUTO_Channel" ]; then
|
||||||
WIRELESS_OPTS="$WIRELESS_OPTS channel $WIRELESS_AUTO_Channel"
|
WIRELESS_OPTS="$WIRELESS_OPTS channel $WIRELESS_AUTO_Channel"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$WIRELESS_FREQUENCY" ]; then
|
if [ "$WIRELESS_FREQUENCY" ]; then
|
||||||
WIRELESS_OPTS="$WIRELESS_OPTS freq $WIRELESS_FREQUENCY"
|
WIRELESS_OPTS="$WIRELESS_OPTS freq $WIRELESS_FREQUENCY"
|
||||||
elif [ "$WIRELESS_AUTO_Frequency" ]; then
|
elif [ "$WIRELESS_AUTO_Frequency" ]; then
|
||||||
WIRELESS_OPTS="$WIRELESS_OPTS freq ${WIRELESS_AUTO_Frequency}G"
|
WIRELESS_OPTS="$WIRELESS_OPTS freq ${WIRELESS_AUTO_Frequency}G"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$WIRELESS_AP" ]; then
|
if [ "$WIRELESS_AP" ]; then
|
||||||
WIRELESS_OPTS2="$WIRELESS_OPTS2 ap $WIRELESS_AP"
|
WIRELESS_OPTS2="$WIRELESS_OPTS2 ap $WIRELESS_AP"
|
||||||
elif [ "$WIRELESS_AUTO_Address" ]; then
|
elif [ "$WIRELESS_AUTO_Address" ]; then
|
||||||
WIRELESS_OPTS2="$WIRELESS_OPTS2 ap $WIRELESS_AUTO_Address"
|
WIRELESS_OPTS2="$WIRELESS_OPTS2 ap $WIRELESS_AUTO_Address"
|
||||||
fi
|
fi
|
||||||
if [ "$WIRELESS_FREQ" ]; then
|
|
||||||
WIRELESS_OPTS2="$WIRELESS_OPTS2 freq $WIRELESS_FREQ"
|
[ "$WIRELESS_FREQ" ] && WIRELESS_OPTS2="$WIRELESS_OPTS2 freq $WIRELESS_FREQ"
|
||||||
fi
|
[ "$WIRELESS_RATE" ] && WIRELESS_OPTS2="$WIRELESS_OPTS2 rate $WIRELESS_RATE"
|
||||||
if [ "$WIRELESS_RATE" ]; then
|
|
||||||
WIRELESS_OPTS2="$WIRELESS_OPTS2 rate $WIRELESS_RATE"
|
|
||||||
fi
|
|
||||||
# Note: WIRELESS_ENC must appear as the last option
|
# Note: WIRELESS_ENC must appear as the last option
|
||||||
if [ "$WIRELESS_ENC" -a "${WIRELESS_AUTO_IE:0:3}" != "WPA" ]; then
|
[ "$WIRELESS_ENC" -a "${WIRELESS_AUTO_IE:0:3}" != "WPA" ] &&
|
||||||
WIRELESS_OPTS="$WIRELESS_OPTS key $WIRELESS_ENCMODE $WIRELESS_ENC"
|
WIRELESS_OPTS="$WIRELESS_OPTS key $WIRELESS_ENCMODE $WIRELESS_ENC"
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$WIRELESS_ESSID" -o "$WIRELESS_ENC" ]; then
|
if [ "$WIRELESS_ESSID" -o "$WIRELESS_ENC" ]; then
|
||||||
echo -n "Setting wireless options for ${DEVICE}: "
|
echo -n "Setting wireless options for ${DEVICE}: "
|
||||||
|
|
||||||
ifconfig ${DEVICE} down
|
ifconfig ${DEVICE} down
|
||||||
iwconfig ${DEVICE} $WIRELESS_OPTS
|
iwconfig ${DEVICE} $WIRELESS_OPTS
|
||||||
if [ "$WIRELESS_OPTS2" ]; then
|
[ "$WIRELESS_OPTS2" ] && iwconfig ${DEVICE} $WIRELESS_OPTS2
|
||||||
iwconfig ${DEVICE} $WIRELESS_OPTS2
|
|
||||||
fi
|
|
||||||
evaluate_retval
|
evaluate_retval
|
||||||
echo
|
echo
|
||||||
|
|
||||||
if [ "${WIRELESS_AUTO_IE:0:3}" == "WPA" -a ! -e /var/run/wpa_supplicant/${DEVICE} ]; then
|
if [ "${WIRELESS_AUTO_IE:0:3}" = "WPA" -a ! -e /var/run/wpa_supplicant/${DEVICE} ]; then
|
||||||
echo -n "Setting WPA options for ${DEVICE}: "
|
echo -n "Setting WPA options for ${DEVICE}: "
|
||||||
[ "$WIRELESS_AUTO_Authentication_Suites" ] || WIRELESS_AUTO_Authentication_Suites=PSK
|
|
||||||
[ "$WIRELESS_AUTO_Pairwise_Ciphers" ] || WIRELESS_AUTO_Pairwise_Ciphers=TKIP
|
[ "$WIRELESS_AUTO_Authentication_Suites" ] ||
|
||||||
[ "$WIRELESS_AUTO_Group_Cipher" ] || WIRELESS_AUTO_Group_Cipher=TKIP
|
WIRELESS_AUTO_Authentication_Suites=PSK
|
||||||
|
|
||||||
|
[ "$WIRELESS_AUTO_Pairwise_Ciphers" ] ||
|
||||||
|
WIRELESS_AUTO_Pairwise_Ciphers=TKIP
|
||||||
|
|
||||||
|
[ "$WIRELESS_AUTO_Group_Cipher" ] ||
|
||||||
|
WIRELESS_AUTO_Group_Cipher=TKIP
|
||||||
|
|
||||||
if [ "${WIRELESS_ENC:0:2}" = "s:" ]; then
|
if [ "${WIRELESS_ENC:0:2}" = "s:" ]; then
|
||||||
WPA_PSK=\"${WIRELESS_ENC/s:}\"
|
WPA_PSK=\"${WIRELESS_ENC/s:}\"
|
||||||
else
|
else
|
||||||
WPA_PSK=${WIRELESS_ENC}
|
WPA_PSK=${WIRELESS_ENC}
|
||||||
fi
|
fi
|
||||||
tmpfile1=`tempfile`
|
|
||||||
|
tmpfile1=`tempfile 2>/dev/null`
|
||||||
cat >> $tmpfile1 << _EOF
|
cat >> $tmpfile1 << _EOF
|
||||||
ctrl_interface=/var/run/wpa_supplicant
|
ctrl_interface=/var/run/wpa_supplicant
|
||||||
network={
|
network={
|
||||||
@ -140,7 +162,10 @@ psk=$WPA_PSK
|
|||||||
}
|
}
|
||||||
_EOF
|
_EOF
|
||||||
wpa_supplicant -Dwext -i${DEVICE} -c $tmpfile1 -B
|
wpa_supplicant -Dwext -i${DEVICE} -c $tmpfile1 -B
|
||||||
|
|
||||||
evaluate_retval
|
evaluate_retval
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
rm -f $tmpfile1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user