# Autodetect network card (script)



## soko1 (Nov 18, 2008)

ifdetect:

```
#!/bin/sh

# (c) 2008 Dmitry Klimov [TrueBSD Project] <lazyklimm@TrueBSD.org>
# (c) 2008 Sokolov Alexey [TrueBSD Project] <sokolov@TrueBSD.org>

if [ `whoami` != "root" ]; then
    echo "This utility should only be run as root"
    echo "Please use 'sudo $0' instead"
    sleep 3
    exit
fi

echo "Please wait..."

LOADERCONF=/boot/loader.conf
if_count=`ifconfig -l |wc -w`

cd /boot/kernel

for if_mod in if_*
do
    echo -n .
    if [ "$if_mod" != "if_ef.ko" ]
    then
	(kldload $if_mod) 2>>/dev/null &&
	(	if_count_new=`ifconfig -l |wc -w`
	    if [ "$if_count_new" != "$if_count" ]
	    then
		IF=`echo $if_mod | cut -d . -f 1`
		echo "${IF}_load=\"YES\"">>${LOADERCONF}
		if_count=$if_count_new
		else
		    kldunload $if_mod 2>>/dev/null
		fi
	)
	
	    fi
done
echo
echo "'$if_mod' detected!"
uniq ${LOADERCONF} /tmp/tmp 
mv /tmp/tmp ${LOADERCONF}
```

Use:

%sudo ./ifdetect

```
Please wait...
......................................................
'if_zyd.ko' detected!
```

%grep if /boot/loader.conf

```
if_zyd_load="YES"
```


----------



## surferwl (Nov 18, 2008)

good!


----------

