#!bin/sh
#
if [ "$1" = "m" ]
then

echo
echo ---------------------------------------------------------
echo fli4l Modem Plus Menue
echo ---------------------------------------------------------
echo
echo AUSWAHL_AKTION_______________________________ SHELLBEFEHL
echo
echo - 1 --- Verbindung herstellen---------------- mp w
echo - 2 --- Verbindung trennen------------------- mp a oder hp
echo - 3 --- Provider auswaehlen------------------ mp p
echo - 4 --- Modem stumm schalten----------------- mp s
echo - 5 --- Modem laut schalten------------------ mp l
echo - 6 --- Modem speeren------------------------ mp sp
echo - 7 --- Modem freigeben---------------------- mp fr
echo - 8 --- Rckstellung auf OPT modem----------- mp z
echo - 9 --- Programm verlassen-------------------
echo
echo Bitte Auswahl-Nr. eingeben:
echo
read ein
if test $ein = 1;then
mp w
fi
if test $ein = 2; then
mp a
fi
if test $ein = 3;then
mp p
fi
if test $ein = 4;then
mp s
fi
if test $ein = 5;then
mp l
fi
if test $ein = 6;then
mp sp
fi
if test $ein = 7;then
mp fr
fi
if test $ein = 8;then
mp z
fi

fi

# Waehlen

if [ "$1" = "w" ]
then

killall pppd
pppd call modem
echo ---------------------------------------------------------
echo fli4l Modem Plus Waehlen via ping
echo ---------------------------------------------------------
p=$(cat /etc/mplus/00/provn)
s=$(cat /etc/mplus/00/ipdial)
echo
echo Verbindung zum Provider $p
echo
echo via ping zu $s wird hergestellt ....
echo
echo --- der ping-Befehl endet mit der -- ping statistics --
echo ___ und kehrt normalerweise zur fli4l-shell zurueck
echo
echo --- wenn die Meldung -- Network is unreachable -- auftaucht
echo ___ dann bitte Modem einmal auflegen mit [hp] oder [mpa]
echo
echo --- taucht die fli4l-shell nicht mehr auf
echo ___ dann 2 x  [ strg + c ] druecken und
echo ___ Modem mit [hp] oder [mpa] auflegen
echo
ping -c 2 $s
echo

fi

# Auflegen

if [ "$1" = "a" ]
then

killall pppd
pppd call modem
echo
echo fli4l-mplus
echo Modem aufgelegt
echo

fi

# Provider

if [ "$1" = "p" ]
then

s=$(cat /etc/mplus/00/provn)
echo
echo ---------------------------------------------------------
echo fli4l Modem Plus Providerauswahl
echo ---------------------------------------------------------
echo
echo Sie haben im Moment den Provider $s eingestellt
echo
echo Folgende Provider stehen zur Auswahl
echo
cat /etc/mplus/00/prov
echo - 7 --- Programm verlassen -------------
echo
echo Auswahl-Nr. ?
read aus
if test $aus = 1;then
cp /etc/mplus/00/chat00 /etc/mplus/00/chatscript
cp /etc/mplus/01/chat02 /etc/mplus/00/chat02
cp /etc/mplus/01/provn /etc/mplus/00/provn
cat /etc/mplus/00/chatm0 >> /etc/mplus/00/chatscript
cat /etc/mplus/00/chat02 >> /etc/mplus/00/chatscript
cp /etc/mplus/00/chatscript /etc/chatscript
cp /etc/mplus/save/pap-secrets /etc/ppp/pap-secrets
cp /etc/mplus/save/chap-secrets /etc/ppp/chap-secrets
cp /etc/mplus/00/peer00 /etc/mplus/00/modem
cat /etc/mplus/01/peer02 >> /etc/mplus/00/modem
cp  /etc/mplus/00/modem /etc/ppp/peers/modem
fi
if test $aus = 2;then
cp /etc/mplus/00/chat00 /etc/mplus/00/chatscript
cp /etc/mplus/02/chat02 /etc/mplus/00/chat02
cp /etc/mplus/02/provn /etc/mplus/00/provn
cat /etc/mplus/00/chatm0 >> /etc/mplus/00/chatscript
cat /etc/mplus/00/chat02 >> /etc/mplus/00/chatscript
cp /etc/mplus/00/chatscript /etc/chatscript
cp /etc/mplus/02/pap-secrets /etc/ppp/pap-secrets
cp /etc/mplus/02/chap-secrets /etc/ppp/chap-secrets
cp /etc/mplus/00/peer00 /etc/mplus/00/modem
cat /etc/mplus/02/peer02 >> /etc/mplus/00/modem
cp  /etc/mplus/00/modem /etc/ppp/peers/modem
fi
if test $aus = 3;then
cp /etc/mplus/00/chat00 /etc/mplus/00/chatscript
cp /etc/mplus/03/chat02 /etc/mplus/00/chat02
cp /etc/mplus/03/provn /etc/mplus/00/provn
cat /etc/mplus/00/chatm0 >> /etc/mplus/00/chatscript
cat /etc/mplus/00/chat02 >> /etc/mplus/00/chatscript
cp /etc/mplus/00/chatscript /etc/chatscript
cp /etc/mplus/03/pap-secrets /etc/ppp/pap-secrets
cp /etc/mplus/03/chap-secrets /etc/ppp/chap-secrets
cp /etc/mplus/00/peer00 /etc/mplus/00/modem
cat /etc/mplus/03/peer02 >> /etc/mplus/00/modem
cp  /etc/mplus/00/modem /etc/ppp/peers/modem
fi
if test $aus = 4;then
cp /etc/mplus/00/chat00 /etc/mplus/00/chatscript
cp /etc/mplus/04/chat02 /etc/mplus/00/chat02
cp /etc/mplus/04/provn /etc/mplus/00/provn
cat /etc/mplus/00/chatm0 >> /etc/mplus/00/chatscript
cat /etc/mplus/00/chat02 >> /etc/mplus/00/chatscript
cp /etc/mplus/00/chatscript /etc/chatscript
cp /etc/mplus/04/pap-secrets /etc/ppp/pap-secrets
cp /etc/mplus/04/chap-secrets /etc/ppp/chap-secrets
cp /etc/mplus/00/peer00 /etc/mplus/00/modem
cat /etc/mplus/04/peer02 >> /etc/mplus/00/modem
cp  /etc/mplus/00/modem /etc/ppp/peers/modem
fi
if test $aus = 5;then
echo Geben Sie den Providernamen ein
read NAME
rm /etc/mplus/ma/provn
echo $NAME >> /etc/mplus/ma/provn
echo Geben Sie die Rufnummer ein
read DIAL
echo Geben Sie den Benutzernamen ein
read USER
echo Geben Sie das Passwort ein
read PASSWD
rm /etc/mplus/ma/pap-secrets
rm /etc/mplus/ma/chap-secrets
echo "\"$USER\" * \"$PASSWD\"" >> /etc/mplus/ma/pap-secrets
echo "\"$USER\" * \"$PASSWD\"" >> /etc/mplus/ma/chap-secrets
{
    echo "OK ATDT$DIAL"
    echo "CONNECT \\d\\c"
} > /etc/mplus/ma/chat02
{   echo "name \"$USER\""
    echo "user \"$USER\""
} > /etc/mplus/ma/peer02
cp /etc/mplus/00/chat00 /etc/mplus/00/chatscript
cp /etc/mplus/ma/chat02 /etc/mplus/00/chat02
cp /etc/mplus/ma/provn /etc/mplus/00/provn
cat /etc/mplus/00/chatm0 >> /etc/mplus/00/chatscript
cat /etc/mplus/00/chat02 >> /etc/mplus/00/chatscript
cp /etc/mplus/00/chatscript /etc/chatscript
cp /etc/mplus/ma/pap-secrets /etc/ppp/pap-secrets
cp /etc/mplus/ma/chap-secrets /etc/ppp/chap-secrets
cp /etc/mplus/00/peer00 /etc/mplus/00/modem
cat /etc/mplus/ma/peer02 >> /etc/mplus/00/modem
cp  /etc/mplus/00/modem /etc/ppp/peers/modem
fi
if test $aus = 6;then
cp /etc/mplus/00/chat00 /etc/mplus/00/chatscript
cp /etc/mplus/ma/chat02 /etc/mplus/00/chat02
cp /etc/mplus/ma/provn /etc/mplus/00/provn
cat /etc/mplus/00/chatm0 >> /etc/mplus/00/chatscript
cat /etc/mplus/00/chat02 >> /etc/mplus/00/chatscript
cp /etc/mplus/00/chatscript /etc/chatscript
cp /etc/mplus/ma/pap-secrets /etc/ppp/pap-secrets
cp /etc/mplus/ma/chap-secrets /etc/ppp/chap-secrets
cp /etc/mplus/00/peer00 /etc/mplus/00/modem
cat /etc/mplus/ma/peer02 >> /etc/mplus/00/modem
cp  /etc/mplus/00/modem /etc/ppp/peers/modem
fi
t=$(cat /etc/mplus/00/provn)
echo
echo Provider $t eingestellt
echo

fi

# Modem stumm

if [ "$1" = "s" ]
then

cp -f /etc/mplus/00/chat00 /etc/mplus/00/chatscript
cat /etc/mplus/00/chatm0 >> /etc/mplus/00/chatscript
cat /etc/mplus/00/chat02 >> /etc/mplus/00/chatscript
cp /etc/mplus/00/chatscript /etc/chatscript
echo
echo fli4l-mplus
echo Modem stumm geschaltet
echo

fi

# Modem laut

if [ "$1" = "l" ]
then

cp -f /etc/mplus/00/chat00 /etc/mplus/00/chatscript
cat /etc/mplus/00/chatm1 >> /etc/mplus/00/chatscript
cat /etc/mplus/00/chat02 >> /etc/mplus/00/chatscript
cp /etc/mplus/00/chatscript /etc/chatscript
echo
echo fli4l-mplus
echo Modem laut geschaltet
echo

fi

# Modem speeren

if [ "$1" = "sp" ]
then

killall pppd
echo
echo fli4l-mplus
echo Modem gespeert
echo

fi

if [ "$1" = "fr" ]
then

# Modem freigeben

pppd call modem
echo
echo fli4l-mplus
echo Modem freigegeben
echo

fi

# Modem zurckgestellt

if [ "$1" = "z" ]
then

echo
cp /etc/mplus/01/provn /etc/mplus/00/provn
cp /etc/mplus/save/chatscript /etc/chatscript
cp /etc/mplus/save/pap-secrets /etc/ppp/pap-secrets
cp /etc/mplus/save/chap-secrets /etc/ppp/chap-secrets
cp /etc/mplus/save/modem /etc/ppp/peers/modem
echo fli4l-mplus
echo auf OPT Modem zurueckgestellt
echo

fi
