#!/bin/bash

# configuration and startup-script for the 3Com ADSL Modem USB

case $ACTION in

add)
	# start
        idProduct=`echo $PRODUCT | cut -f2 -d'/'`
        if [[ "$idProduct" == "f003" || "$idProduct" == "F003" ]]; then
          exit 0
        fi
        modname=`lsmod | cut -f1 -d' ' | grep 3cp4218`
        if [ "$modname" == "3cp4218" ]; then
          ifconfig atm0 down
          killall atmarpd
          rmmod 3cp4218
        fi
        cd /root/adsl/3cp4218/3com 
        ./3cload 1 ../../firmware/ez-usb.bin || exit 1
        sleep 3s 
        ./3cload 2 ../../firmware/3cinit.bin ../../firmware/3cmain.bin || exit 1
        sleep 3s 
        insmod -f 3cp4218 || exit 1
        sleep 3s
        atmarpd -b -l syslog -m || exit 1
        sleep 3s
        atmarp -c atm0 
        ifconfig atm0 217.126.2.10 netmask 255.255.255.192 up || exit 1
        sleep 3s 
        atmarp -s 217.126.2.2 0.8.32 || exit 1
        route add default gw 217.126.2.2 || exit 1
        ./3cioctl 1 || exit 1
        sleep 3s
	;;

remove)
	# killall
        echo "Pas 1" >> /tmp/pas.txt
        ifconfig atm0 down
        echo "Pas 2" >> /tmp/pas.txt
        killall atmarpd
        echo "Pas 3" >> /tmp/pas.txt
        rmmod 3cp4218
        echo "Pas 4" >> /tmp/pas.txt
	;;

esac
