source: genesis/tools/config-node.sh@ 4050

Last change on this file since 4050 was 4050, checked in by rick, 20 years ago

Forgot to send new version

  • Property svn:executable set to *
File size: 6.5 KB
Line 
1#!/bin/sh
2# (c) Copyright 2002, 2003 Stichting Wireless Leiden, all
3# rights reserved. More information can be found on
4# http://wwww.wirelessleiden.nl and the license is at:
5# http://wleiden.webweaving.org:8080/svn/node-config/LICENSE
6#
7# Marten Vijn 24-03-03
8# new version 14-11-2003
9# If there is a global system configuration file, suck it in.
10#
11
12if [ -z ${QUIET} ]; then
13 echo "Using..."
14 echo "no proxy"
15 echo "no dhclient"
16 echo "config `hostname -s`"
17 sleep 1
18fi
19
20if [ -r /etc/defaults/rc.conf ]; then
21 . /etc/defaults/rc.conf
22 source_rc_confs
23elif [ -r /etc/rc.conf ]; then
24 . /etc/rc.conf
25fi
26
27PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
28TMPDIR=${TMPDIR:-/tmp}
29TMPPREFIX=${TMPDIR}/wl-tmp-$$
30WHOST=${WHOST:-rambo.wleiden.net}
31HTTP_PROXY=${HTTP_PROXY:-http://proxy.wleiden.net:3128}
32HTTP_USER_AGENT=${HTTP_USER_AGENT:-curl.faked.fetch/0.0}
33VERSION=1.00
34echo "do we need a proxy ?"
35echo
36echo "just hit enter to go on without proxy settings"
37echo "otherwise type y for this proxy ${HTTP_PROXY} or enter your own proxy"
38echo "if don't want a proxy enter n "
39
40if [ -z ${QUIET} ]; then
41 read proxyset
42else
43 proxyset="n"
44fi
45
46case $proxyset in
47
48n)
49echo no proxy is set
50 ;;
51y)
52 echo this the proxy ${HTTP_PROXY}
53 export HTTP_PROXY
54 ;;
55
56*)
57 ${HTTP_PROXY}=${proxyset}
58 echo this the proxy $HTTP_PROXY
59 export HTTP_PROXY
60 ;;
61esac
62
63export HTTP_USER_AGENT
64export TMPDIR
65
66# Genesis master location.
67link=${GENESIS:-http://${WHOST}/cgi-bin/g_list.pl/}
68list=filelist
69
70# Location for private config
71lcd=${LCDIR:-/lcd}
72
73# True/false - logging.
74# quiet=true
75
76# Make sure we clean up our mess when needed.
77trap "rm -f ${TMPPREFIX}.?; echo Failed; exit 1;" 2 3
78
79# connection test function
80connset()
81{
82
83if [ `ps ax | grep -c dhclient` != "1" ] ; then
84 killall dhclient
85fi
86
87
88echo "enter the ipadress to resolv dns"
89echo 1 for cope as dns on wirelessleiden
90echo 2 for xs4all dns server
91echo 3 if you are at LCPL
92echo or type your on dns
93
94read dns_list
95
96case $dns_list in
971)
98 resolver="172.17.8.1"
99 ;;
1002)
101 resolver="194.109.9.99"
102 ;;
1033)
104 resolver="10.0.0.1"
105 ;;
106*)
107 resolver=$dns_list
108 ;;
109esac
110
111
112echo "/etc/resolv.conf has been changed from:"
113echo `cat /etc/resolv.conf`
114echo to
115echo $resolver
116echo "nameserver ${resolver}" > /etc/resolv.conf
117
118for nic in `ifconfig -l`
119do
120case ${nic} in
121 lo0)
122 echo
123 ;;
124 wi*)
125 echo
126 ;;
127 *)
128 if ping -qnoc ${WHOST}; then
129 echo Connection on interface ${nic} ok
130 else
131 killall dhclient
132 echo Trying to get a DHCP lease on ${nic}
133 dhclient -1 ${nic}
134 fi
135 ;;
136 esac
137done
138}
139
140echo "do we need network on a nic by dhcp ?"
141echo "enter n to not use dhclient for configuration ! "
142
143if [ -z ${QUIET} ]; then
144 read nic_dhcp
145else
146 nic_dhcp="n"
147fi
148if [ "x${nic_dhcp}" = "xn" ] ; then
149 echo proceding...
150 else
151 echo running dhclient
152 connset
153fi
154# Logging function
155#
156log()
157{
158 ${quiet} || return
159 echo $*
160}
161
162cleanse()
163{
164 rm -f ${TMPPREFIX}.?
165}
166
167# Normal exit; but make sure
168# we also clean up any tmp files
169#
170cleanexit()
171{
172 E=1
173 if [ $# -gt 0 ]; then
174 E=$1
175 fi
176 cleanse
177 log Exit
178 exit $E
179 # Trap any weird exit codes.
180 exit 1
181}
182
183safefetch()
184{
185 url=$1
186 file=$2
187 fetch -q -o - ${link}${nodename} > ${TMPPREFIX}.x \
188 || cleanexit 1
189 cp ${TMPPREFIX}.x ${dir}/${list} \
190 || cleanexit 1
191 rm -f ${TMPPREFIX}.x
192
193 return 0
194}
195
196getvalidnodename()
197{
198log " "
199log " "
200log " "
201log Fetching list of nodes from ${link}
202
203fetch -q -o - ${link} > ${nlist} || cleanexit 1
204
205while ! grep -q "^${nodename}\$" ${nlist}
206do
207 echo Nodes:
208 cat ${nlist}
209 echo
210 echo -n enter nodename \[default: ${default}\]:
211 if [ -z ${QUIET} ]; then
212 read nodename
213 else
214 nodename=${default}
215 fi
216
217 if [ "x${nodename}" = "x" ]; then
218 nodename=${default}
219 fi
220done
221
222echo Node Selected: ${nodename}
223}
224
225# a function to move conf_file to admin_dir
226# and to make symlink on the old location to
227# the new location
228
229do_diff() {
230 diff -uwbB ${symdir}/${i} ${dir}/${i}.new
231}
232
233do_move() {
234rm ${dir}/${i}.bak
235mv ${dir}/${i} ${dir}/${i}.bak \
236 || cleanexit 1
237log backuped ${dir}/${i}
238
239mv ${dir}/${i}.new ${dir}/${i} \
240 || cleanexit 1
241updated ${dir}/${i}
242}
243
244bink() {
245 $CMD
246}
247
248dir=${lcd}
249
250echo Config Node -- Version: $VERSION
251
252#check config dir
253#
254if [ ! -d ${dir} ]; then
255 mkdir -p ${dir} || cleanexit 1
256fi
257
258if [ -z ${HTTP_PROXY} ]; then
259 # checking connection - and only fiddle
260 # with interfaces if we need to.
261 #
262 (
263 echo no proxy defined - checking connection.
264 host ${WHOST} > /dev/null || exit 1
265 ping -qnoc 1 ${WHOST} > /dev/null || exit 1
266 exit 0
267 ) || connset
268fi
269
270CMD=do_move
271if [ "x$1" = "x-d" ]; then
272 CMD=do_diff
273 dir=${TMPDIR}
274 shift
275fi
276
277# Use the cmd line argument, of any
278#
279if [ $# = 1 ]; then
280 nodename=$1
281else
282 if [ -r ${lcd}/myname ]; then
283 default=`cat ${lcd}/myname`
284 else
285 default=`hostname -s`
286 test -z $default && default=none
287 fi
288fi
289
290nlist=${TMPPREFIX}.l
291
292test -z $default && default=$nodename
293
294test -z $nodename && getvalidnodename
295
296log Fetching file list from $link for $nodename
297
298safefetch ${link}${nodename} ${dir}/${list}
299
300for i in `cat ${dir}/${list}`
301do
302 log getting ${i} for ${nodename} from ${link}
303 fetch -q -o - ${link}${nodename}/${i} > ${dir}/${i}.new \
304 || cleanexit 1
305done
306
307
308for i in `cat ${dir}/${list}`
309do
310 case ${i} in
311 linux.sh | config)
312 log obsolete file: ${i} - skipped
313 ;;
314 resolv.conf | rc.node.local | rc.local)
315 symdir='/etc/'
316 bink
317 ;;
318 snmpd.local.conf)
319 symdir='/usr/local/share/snmp/'
320 bink
321 ;;
322 named.conf)
323 symdir='/etc/namedb/'
324 bink
325 ;;
326 dhcpd.conf)
327 symdir='/usr/local/etc/'
328 bink
329 ;;
330 zebra.conf | ospfd.conf)
331 symdir='/usr/local/etc/zebra/'
332 bink
333 ;;
334 authorized_keys)
335 symdir='/root/.ssh'
336 bink
337 ;;
338 daemons.sh)
339 symdir='/wl'
340 bink
341 ;;
342 *)
343 echo Script cannot cope with ${i} - ignoring..
344 ;;
345 esac
346done
347
348
349if [ -e /etc/rc.local ]; then
350 # See if we are in rc.local
351 if grep -q /config-node.sh /etc/rc.local; then
352
353 echo As this node now has real configs - do enter a root password
354 echo
355 passwd \
356 || cleanexit 1
357
358 echo Removing /etc/rc.local
359 rm -f /etc/rc.local
360
361 echo Will drop write perms on the next reboot.
362 fi
363fi
364
365# Record our name.
366echo ${nodename} > ${dir}/myname
367
368# Rebuild reverse lookups
369H=`cat /etc/rc.node.local | grep hostname | sed -e s/hostname=// | sed -e s/[\"\']//g`
370hostname $H
371if [ -r /etc/namedb/make-localhost ]; then
372 (
373 cd /etc/namedb || exit 1
374 sh /etc/namedb/make-localhost || exit 1
375 ) || exit 1
376fi
377
378cleanse
379
380if [ -e /etc/rc.empty.conf ] ; then
381 rm /etc/rc.empty.conf || exit
382 echo removed /etc/rc.empty.conf - and rebooting in 30 seconds \(or press ctrl-C to abort\)
383 read -t 30 DUMMY
384 reboot
385fi
386
387exit 0
Note: See TracBrowser for help on using the repository browser.