Contributed by sean on from the airborne packets dept.
So, I got tired of doing my little time saving workarounds every time I connected to a wireless network and decided to look for a solution. Several people have posted little wireless scripts here, to misc@ and minor modifications to help simplify and automate the configuration of wireless, but the scripts never seemed to go far enough. That said, I took the shut up and hack motto and crafted my own solution that is more complete and well, "sucks less" than everyone else's solution (in my humble opinion). I've tried to keep it simple and as minimally intrusive as possible.
The following is an excerpt from the script's comments:
# EXAMPLE # Manually configure a wireless interface # # # sh /etc/wiconfig iwi0 # # Automatically scan for wireless networks and, using previous manual # configurations, configure the wireless interface based on the strongest # wireless signal (for use with hostname.if(5) files) # # $ cat /etc/hostname.iwi0 # !/bin/sh /etc/wiconfig -q \$if # # With the above /etc/hostname.iwi0 in place, iwi0 will be configured # upon startup or whenever /etc/netstart iwi0 is invoked. # # wiconfig can also be used in conjunction with apmd. In the following # example, upon resume, it'll check the status of the wireless connection # and, if there is no network connection, it'll automatically scan for # wireless networks and, using previous manual configurations, configure # the wireless interface based on the strongest wireless signal. # # $ cat /etc/apmd/resume # #!/bin/sh # /bin/sh /etc/wiconfig -qs iwi0I think this script will be quite useful for anyone who uses wireless on OpenBSD and enjoys taking his or her notebook places. That said, while this has been working well for me over the past couple of days, consider this a beta.
I would like others to give it a test-drive and provide feedback. Also, know that I am not a programmer by profession. While I've done minor scripts here and there, this is the largest script I've ever written and I learned a fair amount about pdksh in the process. I took some queues from other related scripts and reviewed some of the scripts used by OpenBSD in writing this so I'd appreciate feedback here as well and welcome patches.
It is my hope that the time I spent writing this will save time for many people when it comes to wireless on OpenBSD. The "wiconfig" script can currently be downloaded from http://bink.mooo.com/~daniel/pub/, but please know I've only used it on OpenBSD 5.0.
(Comments are closed)
By Matthias Kilian (kili) kili@outback.escape.de on
Comments
By Daniel M (danielm) on
Comments
By Matthias Kilian (kili) on
Actually, I didn't even test wether that `rm /etc/wiconfig` works or not. IMHO it's wrong to parse ifconfig output, and it's dangerous parsing ifconfig output with a shell script.
I don't think that something like your wiconfig can be done correctly as a sole shell script.
Comments
By Daniel M (danielm) on
By wim wauters (unisoftdesign) undeadly@unisoftdesign.co.uk on www.unisoftdesign.co.uk
By Peter Ljung (peter_ljung) ljung.peter@gmail.com on http://www.lounge.se
This is certainly work in progress, but works for me in common situations.
auto-wifi.sh
By Aaron Bieber (qbit) deftly@gmail.com on http://qbit.io
1. athn seems to take longer than 3 seconds to set state to "active".
2. adsuck wants /var/adsuck/files/resolve.conf to be 644, but the umask is causing it to be 640.
Here is a patch that fixes both my issues:
<pre>
diff --git a/wiconfig b/wiconfig
index 3f271f6..d714ae1 100644
--- a/wiconfig
+++ b/wiconfig
@@ -79,9 +79,6 @@ myname=$0
max=20
wiconfigdb="/etc/wiconfig.db"
-# Don't allow others to read the files we create
-umask 027
-
function usage {
echo "usage: $myname [-dqs] interface"
exit 1
@@ -400,15 +397,15 @@ function determine {
# Must bring interface up for status to become active
ifconfig $if nwid ${nwid[$choice]} wpakey $pass1 up > /dev/null 2>&1
typeset _status=$?
- sleep 3
+ sleep 10
# Network is active
if [ $_status -eq 0 ] && active $(ifconfig $if | fgrep status); then
update wpa
else
ifconfig $if -nwid -wpakey down > /dev/null 2>&1
- ifconfig $if nwid ${nwid[$choice]} nwkey $pass1 up > /dev/null 2>&1
+ ifconfig $if nwid ${nwid[$choice]} wpakey $pass1 up > /dev/null 2>&1
_status=$?
- sleep 3
+ sleep 10
if [ $_status -eq 0 ] && \
active $(ifconfig $if | fgrep status); then
update wep
@@ -452,12 +449,16 @@ function secure {
}
function createdb {
+ # Don't allow others to read the files we create
+ oldumask=$( umask )
+ umask 027
echo -n > $wiconfigdb
typeset _i=1
while [ $_i -le ${#r[@]} ]; do
echo ${r[$_i]} >> $wiconfigdb
_i=$(($_i+1))
done
+ umask $oldumask
}
function end {
</pre>
Comments
By Daniel M (danielm) on
Comments
By Aaron Bieber (qbit) on http://qbit.io
it seems that the athn takes anywhere form 5 to 10 seconds.. so i just went with 10 :D
The nwkey to wpakey bit was leftover from debugging the 10 second issue.
Is the project hosted anywhere that is conducive to communal hacking? Github maybe?
Comments
By Daniel M (danielm) on
Comments
By Aaron Bieber (qbit) on http://qbit.io
Added it up to github : https://github.com/devious/wiconfig
By Anonymous Coward (erlang) on