On 02/04/14 22:27, Ted Unangst wrote:
On Tue, Feb 04, 2014 at 22:14, Martijn van Duren wrote:
+ # Test if we already configured the interface
+ test -f /tmp/$if.scan && return
+ touch /tmp/$if.scan
this absolutely needs to use mktemp. It may be easier to use
mktemp -d and then put your files inside.
updated diff
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:30:45 -0000
@@ -12,6 +12,8 @@ stripcom() {
done<$1
}
+ifscandir=`mktemp -d`
+
# Start the $1 interface
ifstart() {
if=$1
@@ -20,6 +22,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 $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='
+'
+ # 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
+ fi
+
if ! [ -f $file ]; then
echo "netstart: $file: No such file or directory"
return
@@ -31,8 +71,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 +169,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 +186,7 @@ ifmstart() {
&& ifstart $if
done
done
+ rm -rf $ifscandir
}
# Re-read /etc/rc.conf
@@ -161,6 +202,7 @@ if [ $# -gt 0 ]; then
ifstart $1
shift
done
+ rm -rf $ifscandir
return
fi