Hello misc,
I don't know if anyone used my previous patch, if there's even any
interest for it or if there are any plans on for another aproach, but
today I found a minor bug where nwid's with spaces resulted in errors in
the script because of a changed IFS. So here's an updated diff.
Furthermore a quick overview in the concept:
Use ifscandir to make sure netstart without arguements wont rescan an
interface multiple times.
Don't use sed and grep because /usr might not be mounted yet.
To make it work /etc/hostname.$if must not exist or be a symlink and
/etc/hostname.$nwid.$if should exist.
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 17 Mar 2014 09:34:16 -0000
@@ -12,6 +12,8 @@ stripcom() {
done<$1
}
+ifscandir=`mktemp -d`
+
# Start the $1 interface
ifstart() {
if=$1
@@ -20,6 +22,46 @@ 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 $ifscandir/$if.scan && return
+ touch $ifscandir/$if.scan
+
+ if [ -h $file ]; then
+ rm -f $file
+ fi
+ if ! [ -f $file ]; then
+ ifconfig $if scan > $ifscandir/$if.scan
+ IFS_OLD=$IFS
+ 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 < $ifscandir/$if.scan
+ IFS=$IFS_OLD
+ fi
+
if ! [ -f $file ]; then
echo "netstart: $file: No such file or directory"
return
@@ -31,8 +73,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 +171,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 +188,7 @@ ifmstart() {
&& ifstart $if
done
done
+ rm -rf $ifscandir
}
# Re-read /etc/rc.conf
@@ -161,6 +204,7 @@ if [ $# -gt 0 ]; then
ifstart $1
shift
done
+ rm -rf $ifscandir
return
fi