#!/bin/sh

usage() {
	echo "Usage: $0 sagem|speedtouch user pass vci vpi [firmware path]"
	exit -1
}

if [ $# -lt 5 ]; then
	usage
fi

enc="pppoa" # only PPPoA support for now
model=$1
username=$2
password=$3
shift

# authentication
for file in /etc/ppp/pap-secrets /etc/ppp/chap-secrets; do
	grep -q $username $file || # avoid duplication
	  echo "\"$username\" \"*\" \"$password\" \"*\"" >> $file
done
#nameserver fix
ln -sf /var/run/ppp/resolv.conf /etc/resolv.conf
#echo "nameserver 193.110.121.20" >> /etc/resolv.conf

# PPP link setup
#install -m640 /usr/share/system-config-adsl/$model/$model-$enc.in /etc/ppp/peers/adsl
#sed -e "s/@@USERNAME@@/$username/" -i /etc/ppp/peers/adsl
# model-specific config
case $model in
  sagem)
	/usr/share/system-config-adsl/sagem_install "$@"
	exit $?
	;;
  speedtouch)
	/usr/share/system-config-adsl/speedtouch_install "$@"
	exit $?
	;;
  *)
	usage
	;;
esac
