updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / cable-scripts / cable-start
blobf1c1561d1c98c947361e63325e78ccad91e40154
1 #!/bin/bash
2 #Made by Marcelo A.
4 ME=`basename $0`
5 # Set to "C" locale so we can parse messages from commands
6 LANG=C
7 export LANG
8 # Must be root
9 if test "`id -u`" != 0 ; then
10 echo "$0: You must be root to run this script" >& 2
11 exit 1
14 CONFIG=/etc/ppp/pptp.conf
15 USER=""
16 ETH=""
17 if test ! -f "$CONFIG" -o ! -r "$CONFIG" ; then
18 echo "$0: Cannot read configuration file '$CONFIG'" >& 2
19 exit 1
22 . $CONFIG
24 for i in /etc/ppp/ppp-cable.pid /var/run/ppp-cable.pid ; do
25 if [ -r $i ] ; then
26 PID="`head -n1 $i`"
27 #Check if still running
28 kill -0 $PID > /dev/null 2>&1
29 if [ $? = 0 ] ; then
30 echo "$ME: There already seems to be a connection up (PID $PID)" >& 2
31 exit 1
33 rm -f $i
34 fi
35 done
37 # pptp invocation
38 for i in /usr/sbin/pptp-linux ./pptp-linux "`which pptp`" ; do
39 if test -x "$i" ; then
40 PPTP_CMD="$i"
41 break
43 done
44 if [ ! -x "$i" ] ; then
45 echo "Couldn't find any pptp executable , please reinstall."
46 exit 1
49 # Check for command-line overriding of USER and ETH
50 case "$#" in
52 USER="$1"
55 USER="$1"
56 ETH="$2"
58 esac
60 ##Check if ethx NIC is up and running.
61 netstat -rn |grep " ${ETH}\$" > /dev/null
62 /sbin/ifconfig $ETH | grep "UP.*RUNNING" > /dev/null
63 if [ "$?" != "0" ] ; then
64 echo "Your $ETH interface isn't UP and/or RUNNING"
65 exit 1
66 fi
68 DGW=$(route -n |grep "^0.*eth"| awk '{ print $2 }')
69 if [ "$DGW" = "" ] ; then
70 DGW1=$(route -n|grep "UGH.*eth"|awk '{ print $2 }' )
71 if [ "$DGW1" = "" ] ; then
72 echo ""
73 echo "Something is Fishy with your routing table, no Default Gateway"
74 echo "Aborting..."
75 echo ""
76 exit 1
77 else
78 DGW="$DGW1"
79 route add default gw $DGW 2> /dev/null
81 fi
83 # Check that config file is sane
84 if test "$USER" = "" ; then
85 echo "$0: Check '$CONFIG' -- no setting for USER" >& 2
86 exit 1
88 if test "$ETH" = "" ; then
89 echo "$0: Check '$CONFIG' -- no setting for ETH" >& 2
90 exit 1
92 if test "$SERVERADDR" = "" ; then
93 echo "$0: Check '$CONFIG' -- no setting for SERVERADDR" >& 2
94 exit 1
96 #PPPD_PID=0
99 # MTU of Ethernet card attached to modem MUST be 1500.
100 ifconfig $ETH up mtu 1500
101 modprobe ppp_generic > /dev/null 2>&1
102 modprobe ppp_async > /dev/null 2>&1
104 # If DNSTYPE is SERVER, we must use "usepeerdns" option to pppd.
105 if test "$DNSTYPE" = "SERVER" ; then
106 PEERDNS=yes
109 if test "$PEERDNS" = "yes" ; then
110 PEERDNS="usepeerdns"
111 else
112 PEERDNS=""
115 if test "$PERSIST" != "no" ; then
116 PERSIST="persist"
117 else
118 PERSIST=""
121 if test "$DEFAULTROUTE" != "no" ; then
122 DEFAULTROUTE="defaultroute"
123 else
124 DEFAULTROUTE="nodefaultroute"
127 # Standard PPP options we always use
128 PPP_STD_OPTIONS="noipdefault noauth default-asyncmap noipx $DEFAULTROUTE hide-password nodetach maxfail 1 lcp-max-configure 6 linkname cable ipparam cable-pptp $PEERDNS $PERSIST mtu 1460 mru 1460 noproxyarp noaccomp nobsdcomp nodeflate nopcomp user $USER lcp-echo-interval $LCP_INTERVAL lcp-echo-failure $LCP_FAILURE $PPPD_EXTRA"
131 if test "$OVERRIDE_PPPD_COMMAND" != "" ; then
132 setsid $OVERRIDE_PPPD_COMMAND &
133 else
134 setsid pppd $PPP_STD_OPTIONS \
135 pty "$PPTP_CMD $SERVERADDR $PPTP_EXTRA --nolaunchpppd" &
137 sleep 4