updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / cable-scripts / cable-setup
blob6123c2da06aeccd2249f2d14f050be10a0edbcf4
1 #!/bin/bash
2 #Made by Marcelo A.
4 # Set to "C" locale so we can parse messages from commands
5 LANG=C
6 export LANG
8 CONFIG=/etc/ppp/pptp.conf
9 USER=""
10 ETH=""
11 ME=`basename $0`
12 # Protect created files
13 umask 077
14 copy() {
15 cp $1 $2
16 if [ "$?" != 0 ] ; then
17 echo "*** Error copying $1 to $2"
18 echo "*** Quitting."
19 exit 1
23 # Must be root
24 if [ "`id -u`" != 0 ] ; then
25 echo "$ME: You must be root to run this script" >& 2
26 exit 1
29 # Prototype config file must exist
30 if [ ! -r "$CONFIG" ] ; then
31 echo "Oh, dear, I don't see the file '$CONFIG' anywhere. Please"
32 echo "re-install the client."
33 exit 1
36 . $CONFIG
38 echo "Welcome to the cable connection setup."
39 echo "Please enter some information:"
41 while [ true ] ; do
42 echo ""
43 echo "USER NAME"
44 echo ""
45 echo -n ">>> Enter your user name (default $USER): "
46 read U
48 if [ "$U" = "" ] ; then
49 U="$USER"
52 # Under Linux, "fix" the default interface if eth1 is not available
53 if test `uname -s` = "Linux" ; then
54 ifconfig $ETH > /dev/null 2>&1 || ETH=eth0
56 echo ""
57 echo "INTERFACE"
58 echo ""
59 echo ">>> Enter the Ethernet interface connected to the Cable modem"
60 echo "For Linux, it will be ethn, where 'n' is a number."
61 echo -n "(default $ETH): "
62 read E
64 if [ "$E" = "" ] ; then
65 E="$ETH"
68 echo ""
69 echo "SERVER ADDRESS"
70 echo ""
71 echo ">>> Enter the Server address of your ISP."
72 echo -n "(default $SERVERADDR): "
73 read S
74 if [ "$S" = "" ] ; then
75 S="$SERVERADDR"
78 echo ""
79 echo "DNS"
80 echo ""
81 echo "Please enter the IP address of the primary DNS server."
82 echo "If you want the server to automatically provide you the addresses',"
83 echo "enter 'server' (all lower-case) here."
84 echo "If you just press enter, I will assume you know what you are"
85 echo "doing and not modify your DNS setup."
86 echo -n ">>> Enter the DNS information here: "
88 read DNS1
91 if [ "$DNS1" != "" ] ; then
92 if [ "$DNS1" != "server" ] ; then
93 echo "Please enter the IP address of your ISP's secondary DNS server."
94 echo "If you just press enter, I will assume there is only one DNS server."
95 echo -n ">>> Enter the secondary DNS server address here: "
96 read DNS2
101 while [ true ] ; do
102 echo ""
103 echo "PASSWORD"
104 echo ""
105 stty -echo
106 echo -n ">>> Please enter your password: "
107 read PWD1
108 echo ""
109 echo -n ">>> Please re-enter your password: "
110 read PWD2
111 echo ""
112 stty echo
113 if [ "$PWD1" = "$PWD2" ] ; then
114 break
117 echo -n ">>> Sorry, the passwords do not match. Try again? (y/n)"
118 read ANS
119 case "$ANS" in
120 N|No|NO|Non|n|no|non)
121 echo "OK, quitting. Bye."
122 exit 1
123 esac
124 done
126 echo ""
127 echo "** Summary of what you entered **"
128 echo ""
129 echo "Ethernet Interface: $E"
130 echo "User name: $U"
132 if [ "$DNS1" != "" ] ; then
133 if [ "$DNS1" = "server" ] ; then
134 echo "DNS addresses: Supplied by ISP's server"
135 else
136 echo "Primary DNS: $DNS1"
137 if [ "$DNS2" != "" ] ; then
138 echo "Secondary DNS: $DNS2"
141 else
142 echo "DNS: Do not adjust"
144 echo ""
145 while [ true ] ; do
146 echo -n '>>> Accept these settings and adjust configuration files (y/n)? '
147 read ANS
148 case "ANS" in
149 Y|y|yes|Yes|oui|Oui)
150 ANS=y
152 N|n|no|No|non|Non)
153 ANS=n
155 esac
156 if [ "$ANS" = "y" -o "$ANS" = "n" ] ; then
157 break
159 done
160 if [ "$ANS" = "y" ] ; then
161 break
163 done
165 # Adjust configuration files. First to $CONFIG
166 copy $CONFIG $CONFIG-bak
167 if [ "$DNS1" = "server" ] ; then
168 DNSTYPE=SERVER
169 DNS1=""
170 DNS2=""
171 PEERDNS=yes
172 else
173 PEERDNS=no
174 if [ "$DNS1" = "" ] ; then
175 DNSTYPE=NOCHANGE
176 else
177 DNSTYPE=SPECIFY
180 # Where is pppd likely to put its pid?
181 if [ -d /var/run ] ; then
182 VARRUN=/var/run
183 else
184 VARRUN=/etc/ppp
188 sed -e "s&^USER=.*&USER='$U'&" \
189 -e "s&^ETH=.*&ETH='$E'&" \
190 -e "s&^SERVERADDR=.*&SERVERADDR='$S'&" \
191 -e "s/^DNSTYPE=.*/DNSTYPE=$DNSTYPE/" \
192 -e "s/^DNS1=.*/DNS1=$DNS1/" \
193 -e "s/^DNS2=.*/DNS2=$DNS2/" \
194 -e "s/^PEERDNS=.*/PEERDNS=$PEERDNS/" \
195 < $CONFIG-bak > $CONFIG
197 if [ $? != 0 ] ; then
198 echo "** Error modifying $CONFIG"
199 echo "** Quitting"
200 exit 1
203 echo "Adjusting /etc/ppp/pap-secrets and /etc/ppp/chap-secrets"
204 if [ -r /etc/ppp/pap-secrets ] ; then
205 echo " (But first backing it up to /etc/ppp/pap-secrets-bak)"
206 copy /etc/ppp/pap-secrets /etc/ppp/pap-secrets-bak
207 else
208 cp /dev/null /etc/ppp/pap-secrets-bak
210 if [ -r /etc/ppp/chap-secrets ] ; then
211 echo " (But first backing it up to /etc/ppp/chap-secrets-bak)"
212 copy /etc/ppp/chap-secrets /etc/ppp/chap-secrets-bak
213 else
214 cp /dev/null /etc/ppp/chap-secrets-bak
217 egrep -v "^$U|^\"$U\"" /etc/ppp/pap-secrets-bak > /etc/ppp/pap-secrets
218 echo "\"$U\" * \"$PWD1\" *" >> /etc/ppp/pap-secrets
219 egrep -v "^$U|^\"$U\"" /etc/ppp/chap-secrets-bak > /etc/ppp/chap-secrets
220 echo "\"$U\" * \"$PWD1\" *" >> /etc/ppp/chap-secrets
222 echo ""
223 echo ""
224 echo ""
225 echo "Congratulations, it should be all set up!"
226 echo ""
227 echo "Type: '/etc/rc.d/cable start' - to bring up your CABLE link"
228 echo " '/etc/rc.d/cable stop' - to bring it down"
229 echo " '/etc/rc.d/cable status' - to see the link status."
230 exit 0