File: netconfig

package info (click to toggle)
libcdk5 5.0.20050424-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,504 kB
  • ctags: 2,620
  • sloc: ansic: 29,645; sh: 4,283; makefile: 634; cpp: 42; sed: 40
file content (415 lines) | stat: -rw-r--r-- 11,525 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!/bin/sh
# $Id: netconfig,v 1.3 2002/07/16 22:25:56 tom Exp $

#
# Written by: Mike Glover, March 1997
# E-mail    : vexus@home.com, glover@credit.erin.utoronto.ca
#
# Purpose:
#    This is a graphical network configuration program.
#    It was inspired by the cdialog interface that Linux
#    uses. The widgets are the CDK command line widgets
#    provided by the CDK distribution. If you have any
#    questions about CDK, or the command line widgets
#    please feel free to mail me at one of the two above
#    addresses.
#

#
# Copyright 2000, Mike Glover
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgment:
#	This product includes software developed by Mike Glover
#	and contributors.
# 4. Neither the name of Mike Glover nor the names of contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY MIKE GLOVER AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL MIKE GLOVER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

#
# Set up the root directory for the system files.
#
if [ "$1" = "" ]; then
   ROOTDIR=""
else
   ROOTDIR=$1;
fi

#
# This copies a file to it's destination and
# sets the file mode.
#
copyFile()
{
   source=$1;
   dest=$2;
   mode=$3;

   #
   # If the original exists, make a copy.
   #
   if [ -f "${dest}" ]; then
      cp ${dest} ${dest}.old
   fi
   mv ${source} ${dest}
   chmod ${mode} ${dest}
}

#
# Set up some variables.
#
CDK_DIALOG="../cdkdialog"
CDK_ENTRY="../cdkentry"
CDK_TEMPLATE="../cdktemplate"
NETWORKS="${ROOTDIR}/etc/networks"
HOSTS="${ROOTDIR}/etc/hosts"
HOSTNAME_FILE="${ROOTDIR}/etc/HOSTNAME"
RESOLV="${ROOTDIR}/etc/resolv.conf"
INET="${ROOTDIR}/etc/rc.d/rc.inet1"
IFCONFIG="${ROOTDIR}/sbin/ifconfig"
ROUTE="${ROOTDIR}/sbin/route"
tmpFile="/tmp/tmp.$$"

#
# Define some global variables.
#
IP=""
HOST=""
DOMAIN=""
GATEWAY=""
NETMASK=""
NETWORK=""
BROADCAST=""
NAMESERVER=""

#
# Set the screen and widget colors.
#
CDK_WIDGET_COLOR="</5>"; export CDK_WIDGET_COLOR
CDK_SCREEN_COLOR="</7>"; export CDK_SCREEN_COLOR

#
#
#
exitMessage()
{
   exit;
}

#
# Create the opening window.
#
intro()
{
   program=`basename $0`
   buttons="</R>< OK >"
   message="<C></B>Network Configuration

We will now attempt to configure your mail and TCP/IP. This
process probably won't work on all possible network
configurations; but should give you a good start. You will
be able to reconfigure your network at any time by typing
in the command:
<C>${program}"

   ${CDK_DIALOG} -m "${message}" -B "${buttons}" -S 2> /dev/null
}

#
# Get the hostname of the machine.
#
getHostname()
{
   label="</24/B>Enter Hostname: "
   title="<C></B>Enter Hostname

We need to give the machine a name. We only need the base
hostname of the machine; the domain will be queried for
next.
"

   ${CDK_ENTRY} -i "${HOST}" -f 20 -F "</56/B>_" -T "${title}" -L "${label}" -S 2> ${tmpFile}
   HOST=`cat ${tmpFile}`
}

#
# Get the domain name of the machine.
#
getDomainName()
{
   label="</24/B>Enter Domain Name: "
   title="<C></B>Enter Domain Name

Now enter in the domain in which this machine will
reside. Do </K>NOT<!K> supply a leading '.'

"

   ${CDK_ENTRY} -i "${DOMAIN}" -f 20 -F "</56/B>_" -T "${title}" -L "${label}" -S 2> ${tmpFile}
   DOMAIN=`cat ${tmpFile}`
}

#
# Ask them if they plan to use loopback only.
#
loopback()
{
   buttons="< Yes >
< No >"
   message="<C></B>Loopback

Do you plan to only use loopback?  If so then your address will
be 127.0.0.1 and most of the following questions can be skipped.

<C>Do you plan to ONLY use loopback?
"

   ${CDK_DIALOG} -m "${message}" -B "${buttons}" -S 2> /dev/null
   answer=$?
   if [ $answer -eq 0 ]; then
      exitMessage;
   fi
}

#
# Get the IP Address.
#
getIPAddress()
{
   title="<C>         </B>Enter Machine IP Address

<C>Enter the IP address you plan to assign to this machine.
"
   plate="###.###.###.###"
   overlay="</56/B>___.___.___.___"
   ${CDK_TEMPLATE} -i "${IP}" -p "${plate}" -o "${overlay}" -T "${title}" -m 10 -P -S 2> ${tmpFile}
   IP=`cat ${tmpFile}`
}

#
#
#
getGatewayAddress()
{
   NETWORK=`echo ${IP} | awk 'BEGIN {FS="."} {printf ("%s.%s.%s.0",$1,$2,$3)}'`
   BROADCAST=`echo ${IP} | awk 'BEGIN {FS="."} {printf ("%s.%s.%s.255",$1,$2,$3)}'`

   #
   # Get the machine's gateway address.
   #
   title="<C>         </B>Enter Gateway Address

Enter the address of the gateway for this machine. If you do not
know, or have one, use the IP address of this machine. The IP
address you assigned to this machine should already be filled
in. If you want to erase it press control-x to erase the field
or hit the backspace or delete key to erase portions of the field.
"
   tmp=`echo ${IP} | sed 's/\.//g'`
   plate="###.###.###.###"
   overlay="</B/56>___.___.___.___"
   ${CDK_TEMPLATE} -d "${tmp}" -p "${plate}" -o "${overlay}" -T "${title}" -m 10 -P -S 2> ${tmpFile}
   GATEWAY=`cat ${tmpFile}`

   #
   # Get the machine's netmask.
   #
   title="<C>         </B>Enter Netmask

Enter your netmask.  More often than not this value will be
255.255.255.0  A defaulted value of 255.255.255.0 is already
filled in.  If you want to erase it press control-x to erase
the field or hit the backspace or delete key to erase
portions of the field.
"
   plate="###.###.###.###"
   overlay="</B/56>___.___.___.___"
   ${CDK_TEMPLATE} -d "2552552550" -p "${plate}" -o "${overlay}" -T "${title}" -m 10 -P -S 2> ${tmpFile}
   NETMASK=`cat ${tmpFile}`

   #
   # Find out if the user will be accessing a domain name server.
   #
   message="<C>         </B>Named Services

Will you be accessing a name server.
"
   buttons="< Yes >
< No >"
   ${CDK_DIALOG} -m "${message}" -B "${buttons}" -S 2> /dev/null
   answer=$?

   #
   # If they answered yes, get the IP address.
   #
   if [ "$answer" -eq 0 ]; then
      #
      # Get the machine's domain name server address.
      #
      title="<C>         </B>Enter DNS Address

Enter the address of the domain name server (DNS) which you want to
use.  The value of the DNS server has been filled in with the
gateway address you provided.  If you want to erase it press
control-x to erase the field or hit the backspace or delete key
to erase portions of the field.
"
      tmp=`echo ${GATEWAY} | sed 's/\.//g'`
      plate="###.###.###.###"
      overlay="</B/56>___.___.___.___"
      ${CDK_TEMPLATE} -d "${tmp}" -p "${plate}" -o "${overlay}" -T "${title}" -m 10 -P -S 2> ${tmpFile}
      NAMESERVER=`cat ${tmpFile}`
   fi
}

#
# Call the functions needed.
#


#########################################
# Create the hosts file.
#
cat << EOF > ${tmpFile}
#
# hosts		This file describes a number of hostname-to-address
#		mappings for the TCP/IP subsystem.  It is mostly
#		used at boot time, when no name servers are running.
#		On small systems, this file can be used instead of a
#		"named" name server.  Just add the names, addresses
#		and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1	localhost
$IP	${HOST}.${DOMAIN} ${HOST}
# End of hosts
EOF
copyFile ${tmpFile} "${HOSTS}" 644
echo "${HOST}.${DOMAIN}" > ${tmpFile}
copyFile ${tmpFile} ${HOSTNAME_FILE} 644

#########################################
# Create the resolv.conf file.
#
cat << EOF > ${tmpFile}
domain ${DOMAIN}
nameserver ${NAMESERVER}
EOF
copyFile ${tmpFile} "${RESOLV}" 644

#########################################
# Create the /etc/networks file.
#
cat << EOF > ${tmpFile}
#
# networks	This file describes a number of netname-to-address
#		mappings for the TCP/IP subsystem.  It is mostly
#		used at boot time, when no name servers are running.
#

loopback	127.0.0.0
localnet	${IP}

# End of networks.
EOF
copyFile ${tmpFile} "${NETWORKS}" 644

#########################################
# Create the /etc/rc.d/inet1 file.
#
cat << EOF > ${tmpFile}
#! /bin/sh
#
# rc.inet1	This shell script boots up the base INET system.
#
# Version:	@(#)/etc/rc.d/rc.inet1	1.01	05/27/93
#

HOSTNAME=\`cat /etc/HOSTNAME\`

# Attach the loopback device.
${IFCONFIG} lo 127.0.0.1
${ROUTE} add -net 127.0.0.0

# IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the
# eth0 interface. If you're only using loopback or SLIP, don't include the
# rest of the lines in this file.

# Edit for your setup.
IPADDR="$IP"	# REPLACE with YOUR IP address!
NETMASK="$NETMASK"	# REPLACE with YOUR netmask!
NETWORK="$NETWORK"	# REPLACE with YOUR network address!
BROADCAST="$BROADCAST"	# REPLACE with YOUR broadcast address, if you
			# have one. If not, leave blank and edit below.
GATEWAY="$GATEWAY"	# REPLACE with YOUR gateway address!

# Uncomment the line below to configure your ethernet card.
${IFCONFIG} eth0 \${IP} broadcast \${BROADCAST} netmask \${NETMASK}

# If the line above is uncommented, the code below can also be uncommented.
# It sees if the ethernet was properly initialized, and gives the admin some
# hints about what to do if it wasn't.
if [ ! \$? = 0 ]; then
  cat << END
Your ethernet card was not initialized properly.  Here are some reasons why this
may have happened, and the solutions:
1. Your kernel does not contain support for your card.  Including all the
   network drivers in a Linux kernel can make it too large to even boot, and
   sometimes including extra drivers can cause system hangs.  To support your
   ethernet, either edit /etc/rc.d/rc.modules to load the support at boottime,
   or compile and install a kernel that contains support.
2. You don't have an ethernet card, in which case you should comment out this
   section of /etc/rc.d/rc.inet1.  (Unless you don't mind seeing this error...)
END
fi

# Uncomment these to set up your IP routing table.
${ROUTE} add -net \${NETWORK} netmask \${NETMASK}
${ROUTE} add default gw \${GATEWAY} metric 1

# End of rc.inet1
EOF
copyFile ${tmpFile} "${INET}" 755

#
# Spit out the 'we are done' message.
#
message="<C></B>Network Setup Complete

Your network software has now been configured. You may
rerun this program to reconfigure or you may edit the
respective system files."
buttons="< OK >"
${CDK_DIALOG} -m "${message}" -B "${buttons}" -S 2> /dev/null

#
# Clean up
#
rm -f ${tmpFile}