#!/bin/ash
#
#
#
 name=4MLinux
 for i in AntivirusLiveCD BakAndImgCD TheSSS; do
   if [ -e /var/$i ]; then
     name=$i
   fi
 done
 clear
 echo ""
 echo " What do you wish to configure?"
 echo " 1) Ethernet,"
 echo " 2) WiFi (via Wireless Tools),"
 echo " 3) WiFi (via WPA Supplicant),"
 echo " 4) Dial-up (PPP),"
 echo " 5) Dial-up (PPPoE)."
 read -p " Your choice (1,2,3,4,5)?: " CHOICE
 WPA=no
 PPPOE=no
 if [ x$CHOICE = x3 ]; then
   WPA=yes
   CHOICE=2
 fi
 if [ x$CHOICE = x5 ]; then
   PPPOE=yes
   CHOICE=4
 fi
 case "$CHOICE" in
 '1')
 restore eth >/dev/null 2>&1
 echo ""
 echo " Network interface is set to eth0."
 read -p " Do you wish to change it (y/n)?: " ANSWER
 ANSWER=y$ANSWER
 if [ $ANSWER = yy ]; then
   echo ""
   read -p " Interface to use?: " INTERFACE
   if [ ! x$INTERFACE = x ]; then
     echo $INTERFACE > /etc/interface
   fi
 fi
 ;;
 '2')
 if [ $WPA = yes ]; then
   restore wpa >/dev/null 2>&1
   else
   restore wlan >/dev/null 2>&1
 fi
 echo ""
 echo " Network interface is set to wlan0."
 read -p " Do you wish to change it (y/n)?: " ANSWER
 ANSWER=y$ANSWER
 if [ $ANSWER = yy ]; then
   echo ""
   read -p " Interface to use?: " INTERFACE
   if [ ! x$INTERFACE = x ]; then
     echo $INTERFACE > /etc/interface
   fi
 fi
 echo ""
 read -p " The name of your network?: " NAME
 if [ x$NAME = x ]; then
   NAME=any
 fi
 sed -i 's/any/'$NAME'/g' /etc/net/wifi/wifi.conf
 if [ $WPA = yes ]; then
   sed -i 's/ssid="any"/ssid="'$NAME'"/g' /etc/net/wifi/wpa_supplicant.conf
   echo ""
   read -p " PSK password?: " PASSWORD
   if [ ! x$PASSWORD = x ]; then
     sed -i 's/password/'$PASSWORD'/g' /etc/net/wifi/wpa_supplicant.conf
   fi
 fi
 ;;
 '4')
 if [ -e /usr/share/gnome-ppp/wvdial.conf ]; then
   FILE=$HOME/.wvdial.conf
   cp -f /usr/share/gnome-ppp/wvdial.conf $FILE
   else
   FILE=/etc/interface
 fi
 if [ $PPPOE = yes ]; then
   restore pppoe >/dev/null 2>&1
   echo enabled > /var/log/pppoe.log
   else
   restore ppp >/dev/null 2>&1
   echo ""
   read -p " The phone number to dial?: " NUMBER
   X=X$NUMBER
   if [ ! $X = X ]; then
     sed -i 's/*99#/'$NUMBER'/g' /etc/net/modem/Phone
     sed -i 's/*99#/'$NUMBER'/g' $FILE
   fi
 fi
 echo ""
 read -p " Your username to login?: " USERNAME
 X=X$USERNAME
 if [ ! $X = X ]; then
   sed -i 's/nousername/'$USERNAME'/g' /etc/net/modem/Username
   sed -i 's/nousername/'$USERNAME'/g' $FILE
 fi
 echo ""
 read -p " Your password to login?: " PASSWORD
 X=X$PASSWORD
 if [ ! $X = X ]; then
   sed -i 's/nopassword/'$PASSWORD'/g' /etc/net/modem/Password
   sed -i 's/nopassword/'$PASSWORD'/g' $FILE
 fi
 if [ $PPPOE = yes ]; then
   if [ ! x$USERNAME = x ]; then
     sed -i 's/someloginname/'$USERNAME'/g' /etc/ppp/peers/pppoe
     if [ ! x$PASSWORD = x ]; then
       echo "$USERNAME	*	$PASSWORD" > /etc/ppp/pap-secrets
       cp /etc/ppp/pap-secrets /etc/ppp/chap-secrets
     fi
   fi
   echo ""
   echo " Your basic PPPoE setup is ready."
   read -p " Do you wish to edit the advanced options (y/n)?: " ANSWER
   ANSWER=y$ANSWER
   if [ $ANSWER = yy ]; then
     mcedit /etc/ppp/peers/pppoe
   fi
 fi
 ;;
 *)
 echo " Bye!"
 exit
 ;;
 esac
 if [ ! $CHOICE = 4 ]; then
   echo ""
   echo " $name uses dynamic IPs by default."
   read -p " Do you wish to set static IPs now (y/n)?: " ANSWER
   ANSWER=y$ANSWER
   if [ $ANSWER = yy ]; then
     sed -i 's/no/yes/g' /etc/net/net.conf
     mcedit /etc/net/net.conf
     else
     sed -i 's/yes/no/g' /etc/net/net.conf
   fi
   if [ $CHOICE = 2 ]; then
     echo ""
     echo " Your basic WiFi setup is ready."
     read -p " Do you wish to edit the advanced options (y/n)?: " ANSWER
     ANSWER=y$ANSWER
     if [ $ANSWER = yy ]; then
       if [ $WPA = yes ]; then
         mcedit /etc/net/wifi/wpa_supplicant.conf
         else
         mcedit /etc/net/wifi/wifi.conf
       fi
     fi
   fi
 fi
 echo ""
 if [ $CHOICE = 4 ]; then
   echo " Done! You can try to execute the 'modem' command now."
   else
   echo " Done! You can try to execute the 'connect' command now."
 fi
 if [ -e /tmp/.X0-lock ]; then
   echo " (This command should be executed in your terminal)."
 fi