Public domain
#!/bin/sh
if [ -f /etc/ppp/options ]; then
echo "/etc/ppp/options file exist;"
echo -n "Do you want to rename this file to \"options.bak\" ? [Y/n] "
read REN
if [ "$REN" == "" ]; then REN="y" ;fi
if [ "$REN" == "y" ]; then mv /etc/ppp/options /etc/ppp/options.bak ;fi
fi
echo -n "Enter ISP name : "
read ISP
if [ -f /etc/ppp/peers/$ISP ]; then
echo -n "$ISP connection is exist, Do you want to remove it? [y/N] "
read ANS
if [ "$ANS" == "y" ]; then
rm /etc/ppp/peers/$ISP > /dev/null 2>&1
rm /usr/local/sbin/connect-$ISP > /dev/null 2>&1
rm /usr/local/sbin/disconnect-$ISP > /dev/null 2>&1
cat /etc/ppp/pap-secrets | awk '{ if ( $2 != "\"'$ISP'\"" && $2 != "'$ISP'" ) print $0 }' > /etc/ppp/pap-secrets
echo "$ISP connection removed."
exit 0
fi
echo "Exit without any change !!!"
exit 0
fi
echo -n "Enter Tel.num. : "
read TEL
echo -n "Enter Username : "
read USR
echo -n "Enter Password : "
read -s PAS1
echo
echo -n "Re-Enter Password : "
read -s PAS2
echo
if [ "$PAS1" == "$PAS2" ]; then
PAS=$PAS1
else
echo "Passwords not equal !!! "
exit 0
fi
echo -n "Enter modem dev name [ttyS0] : "
read MDM
if [ "$MDM" == "" ]; then MDM="ttyS0"; fi
echo -n "Do you want to use this connection as your default gateway? [Y/n] "
read GATE
if [ "$GATE" == "" ]; then GATE="y"; fi
echo "kill -INT \`cat /var/lock/LCK..$MDM\` > /dev/null 2>&1 " > /usr/local/sbin/disconnect-$ISP
echo "chmod -x /usr/local/sbin/disconnect-$ISP " >> /usr/local/sbin/disconnect-$ISP
echo "sleep 2" >> /usr/local/sbin/disconnect-$ISP
echo "if [ -f /etc/ppp/gateway.bak ]; then" >> /usr/local/sbin/disconnect-$ISP
echo " GATEWAY=\`cat /etc/ppp/gateway.bak | awk '{ print \$1}'\`" >> /usr/local/sbin/disconnect-$ISP
echo " DEV=\`cat /etc/ppp/gateway.bak | awk '{ print \$2}'\`" >> /usr/local/sbin/disconnect-$ISP
echo " if [ \"\$GATEWAY\" != \"0.0.0.0\" ]; then" >> /usr/local/sbin/disconnect-$ISP
echo " route add default gw \$GATEWAY dev \$DEV" >> /usr/local/sbin/disconnect-$ISP
echo " else" >> /usr/local/sbin/disconnect-$ISP
echo " route add default dev \$DEV" >> /usr/local/sbin/disconnect-$ISP
echo " fi" >> /usr/local/sbin/disconnect-$ISP
echo " rm /etc/ppp/gateway.bak" >> /usr/local/sbin/disconnect-$ISP
echo "fi" >> /usr/local/sbin/disconnect-$ISP
chmod -x /usr/local/sbin/disconnect-$ISP
echo "pppd call $ISP &" > /usr/local/sbin/connect-$ISP
echo "chmod -x /usr/local/sbin/disconnect-*" >> /usr/local/sbin/connect-$ISP
echo "chmod +x /usr/local/sbin/disconnect-$ISP" >> /usr/local/sbin/connect-$ISP
if [ "$GATE" == "y" ]; then
echo "sleep 2" >> /usr/local/sbin/connect-$ISP
echo "GATEWAY=\`route -n | awk '{ if (\$1==\"0.0.0.0\") {print \$2\" \"\$8} }'\`" >> /usr/local/sbin/connect-$ISP
echo "if [ \"\$GATEWAY\" != \"\" ]; then" >> /usr/local/sbin/connect-$ISP
echo " echo \$GATEWAY > /etc/ppp/gateway.bak" >> /usr/local/sbin/connect-$ISP
echo "else" >> /usr/local/sbin/connect-$ISP
echo " rm /etc/ppp/gateway.bak > /dev/null 2>&1" >> /usr/local/sbin/connect-$ISP
echo "fi" >> /usr/local/sbin/connect-$ISP
echo "route del default > /dev/null 2>&1" >> /usr/local/sbin/connect-$ISP
fi
chmod +x /usr/local/sbin/connect-$ISP
echo "if [ \"\$USEPEERDNS\" == \"1\" ]; then" > /etc/ppp/dns-up
echo " mv /etc/resolv.conf /etc/resolv.conf.bak" >> /etc/ppp/dns-up
echo " mv /etc/ppp/resolv.conf /etc/resolv.conf" >> /etc/ppp/dns-up
echo "fi" >> /etc/ppp/dns-up
chmod +x /etc/ppp/dns-up
if [ ! `grep dns-up /etc/ppp/ip-up` ]; then
echo "/etc/ppp/dns-up" >> /etc/ppp/ip-up
fi
chmod +x /etc/ppp/ip-up
echo "if [ -f /etc/resolv.conf.bak ]; then" > /etc/ppp/dns-down
echo " mv /etc/resolv.conf.bak /etc/resolv.conf" >> /etc/ppp/dns-down
echo "fi" >> /etc/ppp/dns-down
chmod +x /etc/ppp/dns-down
if [ ! `grep dns-down /etc/ppp/ip-down` ]; then
echo "/etc/ppp/dns-down" >> /etc/ppp/ip-down
fi
chmod +x /etc/ppp/ip-down
mkdir -p /etc/ppp/peers
touch /etc/ppp/pap-secrets
echo "\"$USR\" \"$ISP\" \"$PAS\"" >> /etc/ppp/pap-secrets
echo "lock" > /etc/ppp/peers/$ISP
echo "defaultroute" >> /etc/ppp/peers/$ISP
echo "noipdefault" >> /etc/ppp/peers/$ISP
echo "usepeerdns" >> /etc/ppp/peers/$ISP
echo "modem" >> /etc/ppp/peers/$ISP
echo "/dev/$MDM" >> /etc/ppp/peers/$ISP
echo "115200" >> /etc/ppp/peers/$ISP
echo "crtscts" >> /etc/ppp/peers/$ISP
echo "passive" >> /etc/ppp/peers/$ISP
echo "asyncmap 0" >> /etc/ppp/peers/$ISP
echo "name \"$USR\"" >> /etc/ppp/peers/$ISP
echo "remotename \"$ISP\"" >> /etc/ppp/peers/$ISP
echo "linkname \"$ISP\"" >> /etc/ppp/peers/$ISP
echo "-detach" >> /etc/ppp/peers/$ISP
echo "connect \"chat -v \\" >> /etc/ppp/peers/$ISP
echo " TIMEOUT 60 \\" >> /etc/ppp/peers/$ISP
echo " ABORT ERROR \\" >> /etc/ppp/peers/$ISP
echo " ABORT BUSY \\" >> /etc/ppp/peers/$ISP
echo " ABORT 'NO ANSWER' \\" >> /etc/ppp/peers/$ISP
echo " ABORT 'NO CARRIER' \\" >> /etc/ppp/peers/$ISP
echo " ABORT 'NO DIALTONE' \\" >> /etc/ppp/peers/$ISP
echo " '' 'AT&FH0' \\" >> /etc/ppp/peers/$ISP
echo " OK ATDT$TEL \\" >> /etc/ppp/peers/$ISP
echo " TIMEOUT 75 \\" >> /etc/ppp/peers/$ISP
echo " CONNECT \\" >> /etc/ppp/peers/$ISP
echo " \"" >> /etc/ppp/peers/$ISP
echo "" >> /etc/ppp/peers/$ISP
echo "### Dial-Ondeman ###" >> /etc/ppp/peers/$ISP
echo "#ipcp-accept-local" >> /etc/ppp/peers/$ISP
echo "#ipcp-accept-remote" >> /etc/ppp/peers/$ISP
echo "#0.0.0.0:10.10.10.10" >> /etc/ppp/peers/$ISP
echo "#demand" >> /etc/ppp/peers/$ISP
echo "" >> /etc/ppp/peers/$ISP
echo "### Re-Dial if error ###" >> /etc/ppp/peers/$ISP
echo "#persist" >> /etc/ppp/peers/$ISP
echo "#maxfail 0" >> /etc/ppp/peers/$ISP
echo "#holdoff 5" >> /etc/ppp/peers/$ISP
echo "" >> /etc/ppp/peers/$ISP
echo "### DEBUG ### " >> /etc/ppp/peers/$ISP
echo "#debug" >> /etc/ppp/peers/$ISP
echo "" >> /etc/ppp/peers/$ISP
echo "-------------------------------"
echo "For advanced settings look at :"
echo "/etc/ppp/dns-up"
echo "/etc/ppp/ip-up"
echo "/etc/ppp/dns-down"
echo "/etc/ppp/ip-down"
echo "/etc/ppp/pap-secrets"
echo "/etc/ppp/peers/$ISP"
echo "/usr/local/sbin/connect-$ISP"
echo "/usr/local/sbin/disconnect-$ISP"
echo "-------------------------------"
echo "To connect to your service provider :"
echo -e "\t #connect-$ISP"
echo
echo "To disconnect from your service provider :"
echo -e "\t #disconnect-$ISP"
echo "-------------------------------"
#!/bin/sh
if [ -f /etc/ppp/options ]; then
echo "/etc/ppp/options file exist;"
echo -n "Do you want to rename this file to \"options.bak\" ? [Y/n] "
read REN
if [ "$REN" == "" ]; then REN="y" ;fi
if [ "$REN" == "y" ]; then mv /etc/ppp/options /etc/ppp/options.bak ;fi
fi
echo -n "Enter ISP name : "
read ISP
if [ -f /etc/ppp/peers/$ISP ]; then
echo -n "$ISP connection is exist, Do you want to remove it? [y/N] "
read ANS
if [ "$ANS" == "y" ]; then
rm /etc/ppp/peers/$ISP > /dev/null 2>&1
rm /usr/local/sbin/connect-$ISP > /dev/null 2>&1
rm /usr/local/sbin/disconnect-$ISP > /dev/null 2>&1
cat /etc/ppp/pap-secrets | awk '{ if ( $2 != "\"'$ISP'\"" && $2 != "'$ISP'" ) print $0 }' > /etc/ppp/pap-secrets
echo "$ISP connection removed."
exit 0
fi
echo "Exit without any change !!!"
exit 0
fi
echo -n "Enter Tel.num. : "
read TEL
echo -n "Enter Username : "
read USR
echo -n "Enter Password : "
read -s PAS1
echo
echo -n "Re-Enter Password : "
read -s PAS2
echo
if [ "$PAS1" == "$PAS2" ]; then
PAS=$PAS1
else
echo "Passwords not equal !!! "
exit 0
fi
echo -n "Enter modem dev name [ttyS0] : "
read MDM
if [ "$MDM" == "" ]; then MDM="ttyS0"; fi
echo -n "Do you want to use this connection as your default gateway? [Y/n] "
read GATE
if [ "$GATE" == "" ]; then GATE="y"; fi
echo "kill -INT \`cat /var/lock/LCK..$MDM\` > /dev/null 2>&1 " > /usr/local/sbin/disconnect-$ISP
echo "chmod 644 /usr/local/sbin/disconnect-$ISP " >> /usr/local/sbin/disconnect-$ISP
echo "sleep 2" >> /usr/local/sbin/disconnect-$ISP
echo "if [ -f /etc/ppp/gateway.bak ]; then" >> /usr/local/sbin/disconnect-$ISP
echo " GATEWAY=\`cat /etc/ppp/gateway.bak | awk '{ print \$1}'\`" >> /usr/local/sbin/disconnect-$ISP
echo " DEV=\`cat /etc/ppp/gateway.bak | awk '{ print \$2}'\`" >> /usr/local/sbin/disconnect-$ISP
echo " if [ \"\$GATEWAY\" != \"0.0.0.0\" ]; then" >> /usr/local/sbin/disconnect-$ISP
echo " route add default gw \$GATEWAY dev \$DEV" >> /usr/local/sbin/disconnect-$ISP
echo " else" >> /usr/local/sbin/disconnect-$ISP
echo " route add default dev \$DEV" >> /usr/local/sbin/disconnect-$ISP
echo " fi" >> /usr/local/sbin/disconnect-$ISP
echo " rm /etc/ppp/gateway.bak" >> /usr/local/sbin/disconnect-$ISP
echo "fi" >> /usr/local/sbin/disconnect-$ISP
chmod 644 /usr/local/sbin/disconnect-$ISP
echo "pppd call $ISP &" > /usr/local/sbin/connect-$ISP
echo "chmod 644 /usr/local/sbin/disconnect-*" >> /usr/local/sbin/connect-$ISP
echo "chmod 755 /usr/local/sbin/disconnect-$ISP" >> /usr/local/sbin/connect-$ISP
if [ "$GATE" == "y" ]; then
echo "sleep 2" >> /usr/local/sbin/connect-$ISP
echo "GATEWAY=\`route -n | awk '{ if (\$1==\"0.0.0.0\") {print \$2\" \"\$8} }'\`" >> /usr/local/sbin/connect-$ISP
echo "if [ \"\$GATEWAY\" != \"\" ]; then" >> /usr/local/sbin/connect-$ISP
echo " echo \$GATEWAY > /etc/ppp/gateway.bak" >> /usr/local/sbin/connect-$ISP
echo "else" >> /usr/local/sbin/connect-$ISP
echo " rm /etc/ppp/gateway.bak > /dev/null 2>&1" >> /usr/local/sbin/connect-$ISP
echo "fi" >> /usr/local/sbin/connect-$ISP
echo "route del default > /dev/null 2>&1" >> /usr/local/sbin/connect-$ISP
fi
chmod 755 /usr/local/sbin/connect-$ISP
echo "if [ \"\$USEPEERDNS\" == \"1\" ]; then" > /etc/ppp/dns-up
echo " mv /etc/resolv.conf /etc/resolv.conf.bak" >> /etc/ppp/dns-up
echo " mv /etc/ppp/resolv.conf /etc/resolv.conf" >> /etc/ppp/dns-up
echo "fi" >> /etc/ppp/dns-up
chmod 755 /etc/ppp/dns-up
touch /etc/ppp/ip-up.local
if [ ! `grep dns-up /etc/ppp/ip-up.local` ]; then
echo "/etc/ppp/dns-up" >> /etc/ppp/ip-up.local
fi
chmod 755 /etc/ppp/ip-up.local
echo "if [ -f /etc/resolv.conf.bak ]; then" > /etc/ppp/dns-down
echo " mv /etc/resolv.conf.bak /etc/resolv.conf" >> /etc/ppp/dns-down
echo "fi" >> /etc/ppp/dns-down
chmod 755 /etc/ppp/dns-down
touch /etc/ppp/ip-down.local
touch /etc/ppp/ip-down.local
if [ ! `grep dns-down /etc/ppp/ip-down.local` ]; then
echo "/etc/ppp/dns-down" >> /etc/ppp/ip-down.local
fi
chmod 755 /etc/ppp/ip-down.local
mkdir -p /etc/ppp/peers
touch /etc/ppp/pap-secrets
echo "\"$USR\" \"$ISP\" \"$PAS\"" >> /etc/ppp/pap-secrets
echo "lock" > /etc/ppp/peers/$ISP
echo "defaultroute" >> /etc/ppp/peers/$ISP
echo "noipdefault" >> /etc/ppp/peers/$ISP
echo "usepeerdns" >> /etc/ppp/peers/$ISP
echo "modem" >> /etc/ppp/peers/$ISP
echo "/dev/$MDM" >> /etc/ppp/peers/$ISP
echo "115200" >> /etc/ppp/peers/$ISP
echo "crtscts" >> /etc/ppp/peers/$ISP
echo "passive" >> /etc/ppp/peers/$ISP
echo "asyncmap 0" >> /etc/ppp/peers/$ISP
echo "name \"$USR\"" >> /etc/ppp/peers/$ISP
echo "remotename \"$ISP\"" >> /etc/ppp/peers/$ISP
echo "linkname \"$ISP\"" >> /etc/ppp/peers/$ISP
echo "-detach" >> /etc/ppp/peers/$ISP
echo "connect \"chat -v \\" >> /etc/ppp/peers/$ISP
echo " TIMEOUT 60 \\" >> /etc/ppp/peers/$ISP
echo " ABORT ERROR \\" >> /etc/ppp/peers/$ISP
echo " ABORT BUSY \\" >> /etc/ppp/peers/$ISP
echo " ABORT 'NO ANSWER' \\" >> /etc/ppp/peers/$ISP
echo " ABORT 'NO CARRIER' \\" >> /etc/ppp/peers/$ISP
echo " ABORT 'NO DIALTONE' \\" >> /etc/ppp/peers/$ISP
echo " '' 'AT&FH0' \\" >> /etc/ppp/peers/$ISP
echo " OK ATDT$TEL \\" >> /etc/ppp/peers/$ISP
echo " TIMEOUT 75 \\" >> /etc/ppp/peers/$ISP
echo " CONNECT \\" >> /etc/ppp/peers/$ISP
echo " \"" >> /etc/ppp/peers/$ISP
echo "" >> /etc/ppp/peers/$ISP
echo "### Dial-Ondeman ###" >> /etc/ppp/peers/$ISP
echo "#ipcp-accept-local" >> /etc/ppp/peers/$ISP
echo "#ipcp-accept-remote" >> /etc/ppp/peers/$ISP
echo "#0.0.0.0:10.10.10.10" >> /etc/ppp/peers/$ISP
echo "#demand" >> /etc/ppp/peers/$ISP
echo "" >> /etc/ppp/peers/$ISP
echo "### Re-Dial if error ###" >> /etc/ppp/peers/$ISP
echo "#persist" >> /etc/ppp/peers/$ISP
echo "#maxfail 0" >> /etc/ppp/peers/$ISP
echo "#holdoff 5" >> /etc/ppp/peers/$ISP
echo "" >> /etc/ppp/peers/$ISP
echo "### DEBUG ### " >> /etc/ppp/peers/$ISP
echo "#debug" >> /etc/ppp/peers/$ISP
echo "" >> /etc/ppp/peers/$ISP
echo "-------------------------------"
echo "For advanced settings look at :"
echo "/etc/ppp/dns-up"
echo "/etc/ppp/ip-up"
echo "/etc/ppp/dns-down"
echo "/etc/ppp/ip-down"
echo "/etc/ppp/pap-secrets"
echo "/etc/ppp/peers/$ISP"
echo "/usr/local/sbin/connect-$ISP"
echo "/usr/local/sbin/disconnect-$ISP"
echo "-------------------------------"
echo "To connect to your service provider :"
echo -e "\t #connect-$ISP"
echo
echo "To disconnect from your service provider :"
echo -e "\t #disconnect-$ISP"
echo "-------------------------------"
BY: Pejman Moghadam
TAG: dialup, slackware, redhat
DATE: 2007-05-28 12:36:55