The Code
Here is the resulting script:
#!/bin/sh
# /usr/local/etc/rc.d/wi0
# Configure wireless interface
# See the ifconfig(8), dhclient(8) and route(8) man pages for further
# assistance.
NIC=wi0
case $1 in
dhome)
ifconfig ${NIC} ssid "myhome" authmode "shared" nwkey 0x123456789a
dhclient ${NIC}
echo ${NIC}
;;
shome)
ifconfig ${NIC} inet 192.168.1.21 ssid "myhome" authmode "shared"
nwkey 0x123456789a netmask 255.255.255.0
route add default 192.168.1.1
echo nameserver 24.204.0.4 > /etc/resolv.conf
echo nameserver 24.204.0.5 >> /etc/resolv.conf
echo ${NIC}
;;
dsister)
ifconfig ${NIC} ssid "sisterhome" authmode "shared" nwkey \
0x987654321a
dhclient ${NIC}
echo ${NIC}
;;
stop)
[ -s /var/run/dhclient.pid ] && kill `cat /var/run/dhclient.pid` \
&& rm /var/run/dhclient.pid
ifconfig ${NIC} remove
echo " ${NIC} removed"
;;
status)
ifconfig ${NIC}
;;
*)
echo "usage: /usr/local/etc/${NIC} [dhome|shome|dsister|stop|status]"
;;
esac
Note that the stop option kills
dhclient. If you will be using multiple network
interfaces, you may wish to delete the line that reads:
[ -s /var/run/dhclient.pid ] && kill `cat /var/run/dhclient.pid` && rm \
/var/run/dhclient.pid
The script should be owned by root and be readable
by root only. If you create your script as a
normal user, you need to change its owner. Become the superuser, and:
# chown root:wheel /usr/local/etc/rc.d/wi0
# chmod 700 /usr/local/etc/wi0