Wireless Bootup Script
From ArchWiki
[edit] Please note there is now full wireless support in the standard initscripts - this information is obsolete
Work is currently underway to have this placed into the existing initscripts package
In order to use this, you must have a wireless-profile defined (see the Sample Wireless Profile). You must also add a WIRELESS_PROFILES=() array to your rc.conf file.
# !/bin/sh
# Arch Linux Wireless Networking Script
# phrakture <aaronmgriffin@gmail.com>
#
# Contributors:
# dibblethewrecker <http://dtw.jiwe.org/>
# Pierre Schmitz <http://archlinux.laber-land.de or http://www.laber-land.de/contact.php>
# MasonM <mason_mullins (at) hotmail (dot) com>
. /etc/rc.conf
. /etc/rc.d/functions
. /etc/conf.d/dhcpcd
# wireless''up <profile''name>
wireless_up()
{
if [[ ! -f /etc/conf.d/wireless-profiles/${1}/config ]]; then
echo \"Profile [[$1]] NOT found!\"
return 1
fi
. /etc/conf.d/wireless-profiles/${1}/config
if [[ ! -n \"$INTERFACE\" ]]; then
echo \"Profile [[$1]] has no interface defined!\"
return 1
elif [[ -f /etc/dhcpc/dhcpcd-${INTERFACE}.pid ]]; then
echo \"Interface $INTERFACE already active\"
return 1
fi
if [[ -n \"$INFO\" ]]; then
stat_busy \"Loading Wireless Profile [[$INFO]] on $INTERFACE\"
else
stat_busy \"Loading Wireless Profile [[$1]] on $INTERFACE\"
fi
if [[ -n \"$MODE\" ]]; then
/usr/sbin/iwconfig $INTERFACE mode $MODE
fi
if [[ -n \"$NWID\" ]]; then
/usr/sbin/iwconfig $INTERFACE nwid $NWID
fi
if [[ -n \"$FREQ\" ]]; then
/usr/sbin/iwconfig $INTERFACE freq $FREQ
elif [[ -n \"$CHANNEL\" ]]; then
/usr/sbin/iwconfig $INTERFACE channel $CHANNEL
fi
if [[ -n \"$KEY\" ]]; then
/usr/sbin/iwconfig $INTERFACE key $KEY
fi
if [[ -n \"$SENS\" ]]; then
/usr/sbin/iwconfig $INTERFACE sens $SENS
fi
if [[ -n \"$RATE\" ]] ; then
/usr/sbin/iwconfig $INTERFACE rate $RATE
fi
if [[ -n \"$RTS\" ]]; then
/usr/sbin/iwconfig $INTERFACE rts $RTS
fi
if [[ -n \"$FRAG\" ]]; then
/usr/sbin/iwconfig $INTERFACE frag $FRAG
fi
if [[ -n \"$PARAMS\" ]]; then
/usr/sbin/iwconfig $INTERFACE $PARAMS
fi
if [[ -n \"$ESSID\" ]]; then
/usr/sbin/iwconfig $INTERFACE essid $ESSID
fi
/sbin/ifconfig $INTERFACE up
# TBD : iwscan for each essid to verify it exists...
# if [[ -n \"$ESSID\" ]]; then
# sleep 2
# if ! /usr/sbin/iwlist $INTERFACE scan || grep \"ESSID:\\"$ESSID\\"\" >/dev/null 2>&1; then
# /sbin/ifconfig $INTERFACE down
# echo \"ESSID [[$ESSID]] was not found\"
# return 1
# fi
# fi
if [[ -f /etc/conf.d/wireless-profiles/${1}/wpa ]]; then
/usr/bin/wpa_supplicant -wB -i$INTERFACE -c/etc/conf.d/wireless-profiles/${1}/wpa
#I don“t know how we could determine if wpa_supplicant is ready...
sleep 2
let i=0
while ! /usr/bin/wpa''cli status || grep \"wpa''state=COMPLETED\" >/dev/null 2>&1; do
if [[ $i -gt 10 ]]; then
echo \"WPA failed\"
/usr/bin/wpa_cli terminate >/dev/null 2>&1
/sbin/ifconfig $INTERFACE down
return 1
fi
sleep 2
let i++
done
fi
if [[ \"$IFOPTS\" = \"dhcp\" ]]; then
. /etc/conf.d/dhcpcd
rm -f /etc/dhcpc/dhcpcd-${INTERFACE}.{pid,cache} >/dev/null 2>&1
/usr/sbin/dhcpcd $DHCPCD_ARGS $INTERFACE
else
/sbin/ifconfig $IFOPTS
fi
if [[ -x /etc/conf.d/wireless-profiles/${1}/connected ]]; then
/etc/conf.d/wireless-profiles/${1}/connected
fi
return $?
}
# wireless''down <profile''name>
wireless_down()
{
if [[ ! -f /etc/conf.d/wireless-profiles/${1}/config ]]; then
echo \"Profile [[$1]] NOT found!\"
return 1
fi
. /etc/conf.d/wireless-profiles/${1}/config
if [[ -n \"$INFO\" ]]; then
stat_busy \"Stopping Wireless Profile [[$INFO]] on $INTERFACE\"
else
stat_busy \"Stopping Wireless Profile [[$1]] on $INTERFACE\"
fi
if [[ -f /etc/conf.d/wireless-profiles/${1}/wpa ]]; then
/usr/bin/wpa_cli terminate >/dev/null 2>&1
fi
if [[ \"$IFOPTS\" = \"dhcp\" ]]; then
if [[ -f /etc/dhcpc/dhcpcd-${INTERFACE}.pid ]]; then
#thanks to MasonM for pointing this out!
/sbin/dhcpcd -k
# /bin/kill `cat /etc/dhcpc/dhcpcd-${INTERFACE}.pid`
fi
fi
/sbin/ifconfig $INTERFACE down
if [[ -x /etc/conf.d/wireless-profiles/${1}/disconnected ]]; then
/etc/conf.d/wireless-profiles/${1}/disconnected
fi
return $?
}
case \"$1\" in
start)
for profile in ${WIRELESS_PROFILES[[@]]}; do
if ! ck''daemon wireless''${profile}; then
echo \"Profile [[$profile]] is already up\"
else
wireless_up $profile
if [[ $? -eq 0 ]]; then
add''daemon wireless''${profile}
stat_done
else
stat_fail
fi
fi
done
;;
stop)
for profile in ${WIRELESS_PROFILES[[@]]}; do
if ck''daemon wireless''${profile}; then
echo \"Profile [[$profile]] is not up\"
else
rm''daemon wireless''${profile}
wireless_down $profile
if [[ $? -eq 0 ]]; then
stat_done
else
stat_fail
fi
fi
done
;;
restart)
$0 stop
sleep 2
$0 start
;;
profile)
if [[ \"$3\" = \"up\" ]]; then
if ! ck''daemon wireless''${2}; then
echo \"Profile [[$2]] is already up\"
else
wireless_up $2
if [[ $? -eq 0 ]]; then
add''daemon wireless''${2}
stat_done
else
stat_fail
fi
fi
elif [[ \"$3\" = \"down\" ]]; then
if ck''daemon wireless''${2}; then
echo \"Profile [[$2]] is not running\"
else
wireless_down $2
if [[ $? -eq 0 ]]; then
rm''daemon wireless''${2}
stat_done
else
stat_fail
fi
fi
fi
;;
*)
echo \"usage: $0 {start||stop||restart}\"
echo \"usage: $0 profile <profile_name> {up||down}\"
;;
esac
WikiMigration--dlanor 13:09, 23 Jul 2005 (EDT)