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

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

Fixed paar foutjes als files niet bekend waren

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