#!/bin/sh
#
# --------------------------------------------------------------------------
# Copyright notice
# --------------------------------------------------------------------------
# Copyright: Rene Mayrhofer, Mar. 2000
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# On Debian GNU/Linux systems, the complete text of the GNU General
# Public License can be found in `/usr/share/common-licenses/GPL'.
# --------------------------------------------------------------------------
#

. /etc/default/common-definitions.sh

echo "searching for installed network adapters..."
old_printk=`cat /proc/sys/kernel/printk`
echo 0 0 0 0 > /proc/sys/kernel/printk

listpci |
while read class mod desc; do
  if [ "$class" = "NETWORK" ]; then
    set $desc
    shift `expr $# - 1`
    dev=$1
    desc=`expr "$desc" : "\(.*\) $dev"`

    echo -n -e "  found $desc ... "
    if modprobe -q $mod ; then
      echo -e "loaded ${COLOR_GREEN}${mod}${COLOR_NORMAL}"

      # remember the module so that it gets loaded on the next reboots
      echo $mod >> /etc/modules

      # bring the device(s) up immediately
      (cat /proc/net/dev | grep $dev | cut -d: -f1) |
      while read realdev; do
        ip link set dev $realdev up
      done
    else
      echo -e "${COLOR_RED}load failed${COLOR_NORMAL}"
    fi
  fi
done

echo $old_printk > /proc/sys/kernel/printk
echo "search completed"

exit 0
