Hello misc,
I got a bit tired of manually revolving my hostname.if when walking
about with my laptop. To resolve this issue I've written the following
patch.
It hasn't been heavily field tested, but it works for me.
What it does is it looks if the interface can do a scan command. If it
returns successfull it will filter out the nwids and see if there is a
hostname.$nwid.$if available. If it is it will symlink it to
/etc/hostname.$if.
If a non-symlinked /etc/hostname.$if exists it will ignore ifconfig $if
scan command and boot a couple of seconds faster.
Other options that could be thought of would be to first do a bssid
loop, for those who live in an area where everything connects to nwid
"default" and do a second loop based upon nwid.
I'm curious on what your thoughts are and how this patch may be improved.
Sincerely,
Martijn van Duren
Index: netstart
===================================================================
RCS file: /cvs/src/etc/netstart,v
retrieving revision 1.139
diff -u -p -u -r1.139 netstart
--- netstart 22 Aug 2013 07:53:11 -0000 1.139
+++ netstart 4 Feb 2014 21:12:32 -0000
@@ -20,6 +20,44 @@ ifstart() {
[[ $if != +([[:alpha:]])+([[:digit:]]) ]] && return
file=/etc/hostname.$if
+
+ # Check for ifconfig'able interface.
+ (ifconfig $if || ifconfig $if create) >/dev/null 2>&1 || return
+
+ # Test if we already configured the interface
+ test -f /tmp/$if.scan && return
+ touch /tmp/$if.scan
+
+ if [ -h $file ]; then
+ rm -f $file
+ fi
+ if ! [ -f $file ]; then
+ ifconfig $if scan > /tmp/$if.scan
+ IFS='
+'
+ # Test if any of the nwids has a config file
+ while read line; do
+ line="$line nwid "
+ line="${line#*nwid }"
+ test -z "$line" && continue;
+
+ if [[ "$line" = \"* ]]; then
+ IFS='"'
+ set -A scan -- $line
+ nwid="${scan[1]}"
+ else
+ IFS=' '
+ set -A scan -- $line
+ nwid="${scan[0]}"
+ fi
+
+ if [ -f /etc/hostname.$nwid.$if ]; then
+ ln -s /etc/hostname.$nwid.$if $file
+ break
+ fi
+ done < /tmp/$if.scan
+ fi
+
if ! [ -f $file ]; then
echo "netstart: $file: No such file or directory"
return
@@ -31,8 +69,6 @@ ifstart() {
chmod -LR o-rwx $file
chown -LR root.wheel $file
fi
- # Check for ifconfig'able interface.
- (ifconfig $if || ifconfig $if create) >/dev/null 2>&1 || return
# Now parse the hostname.* file
while :; do
@@ -131,6 +167,8 @@ ifmstart() {
for hn in /etc/hostname.*; do
# Strip off /etc/hostname. prefix
if=${hn#/etc/hostname.}
+ # Strip off potential nwid information
+ if=${if##*.}
test "$if" = "*" && continue
# Skip unwanted ifs
@@ -146,6 +184,9 @@ ifmstart() {
&& ifstart $if
done
done
+ for scan in /tmp/*.scan; do
+ test -f $scan && rm $scan
+ done
}
# Re-read /etc/rc.conf
@@ -160,6 +201,9 @@ if [ $# -gt 0 ]; then
while [ $# -gt 0 ]; do
ifstart $1
shift
+ done
+ for scan in /tmp/*.scan; do
+ test -f $scan && rm $scan
done
return
fi