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

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

Schoonheidsfoutje

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