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 |
|
---|
13 | if [ -r /etc/defaults/rc.conf ]; then
|
---|
14 | . /etc/defaults/rc.conf
|
---|
15 | source_rc_confs
|
---|
16 | elif [ -r /etc/rc.conf ]; then
|
---|
17 | . /etc/rc.conf
|
---|
18 | fi
|
---|
19 |
|
---|
20 | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
---|
21 | TMPDIR=${TMPDIR:-/tmp}
|
---|
22 | TMPPREFIX=${TMPDIR}/wl-tmp-$$
|
---|
23 | WHOST=${WHOST:-rambo.wleiden.net}
|
---|
24 | HTTP_PROXY=${HTTP_PROXY:-http://proxy.wleiden.net:3128}
|
---|
25 | HTTP_USER_AGENT=${HTTP_USER_AGENT:-curl.faked.fetch/0.0}
|
---|
26 | VERSION=1.00
|
---|
27 |
|
---|
28 | if [ -z ${QUIET} ]; then
|
---|
29 | echo "Using..."
|
---|
30 | echo "no proxy"
|
---|
31 | echo "no dhclient"
|
---|
32 | echo "config `hostname -s`"
|
---|
33 | sleep 1
|
---|
34 | fi
|
---|
35 |
|
---|
36 | echo "do we need a proxy ?"
|
---|
37 | echo
|
---|
38 | echo "just hit enter to go on without proxy settings"
|
---|
39 | echo "otherwise type y for this proxy ${HTTP_PROXY} or enter your own proxy"
|
---|
40 | echo "if don't want a proxy enter n "
|
---|
41 |
|
---|
42 | if [ -z ${QUIET} ]; then
|
---|
43 | read proxyset
|
---|
44 | else
|
---|
45 | proxyset="n"
|
---|
46 | fi
|
---|
47 |
|
---|
48 | case $proxyset in
|
---|
49 |
|
---|
50 | n)
|
---|
51 | echo no proxy is set
|
---|
52 | ;;
|
---|
53 | y)
|
---|
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 | ;;
|
---|
63 | esac
|
---|
64 |
|
---|
65 | export HTTP_USER_AGENT
|
---|
66 | export TMPDIR
|
---|
67 |
|
---|
68 | # Genesis master location.
|
---|
69 | link=${GENESIS:-http://${WHOST}/cgi-bin/g_list.pl/}
|
---|
70 | list=filelist
|
---|
71 |
|
---|
72 | # Location for private config
|
---|
73 | lcd=${LCDIR:-/lcd}
|
---|
74 |
|
---|
75 | # True/false - logging.
|
---|
76 | # quiet=true
|
---|
77 |
|
---|
78 | # Make sure we clean up our mess when needed.
|
---|
79 | trap "rm -f ${TMPPREFIX}.?; echo Failed; exit 1;" 2 3
|
---|
80 |
|
---|
81 | # connection test function
|
---|
82 | connset()
|
---|
83 | {
|
---|
84 |
|
---|
85 | if [ `ps ax | grep -c dhclient` != "1" ] ; then
|
---|
86 | killall dhclient
|
---|
87 | fi
|
---|
88 |
|
---|
89 |
|
---|
90 | echo "enter the ipadress to resolv dns"
|
---|
91 | echo 1 for cope as dns on wirelessleiden
|
---|
92 | echo 2 for xs4all dns server
|
---|
93 | echo 3 if you are at LCPL
|
---|
94 | echo or type your on dns
|
---|
95 |
|
---|
96 | read dns_list
|
---|
97 |
|
---|
98 | case $dns_list in
|
---|
99 | 1)
|
---|
100 | resolver="172.17.8.1"
|
---|
101 | ;;
|
---|
102 | 2)
|
---|
103 | resolver="194.109.9.99"
|
---|
104 | ;;
|
---|
105 | 3)
|
---|
106 | resolver="10.0.0.1"
|
---|
107 | ;;
|
---|
108 | *)
|
---|
109 | resolver=$dns_list
|
---|
110 | ;;
|
---|
111 | esac
|
---|
112 |
|
---|
113 |
|
---|
114 | echo "/etc/resolv.conf has been changed from:"
|
---|
115 | echo `cat /etc/resolv.conf`
|
---|
116 | echo to
|
---|
117 | echo $resolver
|
---|
118 | echo "nameserver ${resolver}" > /etc/resolv.conf
|
---|
119 |
|
---|
120 | for nic in `ifconfig -l`
|
---|
121 | do
|
---|
122 | case ${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
|
---|
139 | done
|
---|
140 | }
|
---|
141 |
|
---|
142 | echo "do we need network on a nic by dhcp ?"
|
---|
143 | echo "enter n to not use dhclient for configuration ! "
|
---|
144 |
|
---|
145 | if [ -z ${QUIET} ]; then
|
---|
146 | read nic_dhcp
|
---|
147 | else
|
---|
148 | nic_dhcp="n"
|
---|
149 | fi
|
---|
150 | if [ "x${nic_dhcp}" = "xn" ] ; then
|
---|
151 | echo proceding...
|
---|
152 | else
|
---|
153 | echo running dhclient
|
---|
154 | connset
|
---|
155 | fi
|
---|
156 | # Logging function
|
---|
157 | #
|
---|
158 | log()
|
---|
159 | {
|
---|
160 | ${quiet} || return
|
---|
161 | echo $*
|
---|
162 | }
|
---|
163 |
|
---|
164 | cleanse()
|
---|
165 | {
|
---|
166 | rm -f ${TMPPREFIX}.?
|
---|
167 | }
|
---|
168 |
|
---|
169 | # Normal exit; but make sure
|
---|
170 | # we also clean up any tmp files
|
---|
171 | #
|
---|
172 | cleanexit()
|
---|
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 |
|
---|
185 | safefetch()
|
---|
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 |
|
---|
198 | getvalidnodename()
|
---|
199 | {
|
---|
200 | log " "
|
---|
201 | log " "
|
---|
202 | log " "
|
---|
203 | log Fetching list of nodes from ${link}
|
---|
204 |
|
---|
205 | fetch -q -o - ${link} > ${nlist} || cleanexit 1
|
---|
206 |
|
---|
207 | while ! grep -q "^${nodename}\$" ${nlist}
|
---|
208 | do
|
---|
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
|
---|
222 | done
|
---|
223 |
|
---|
224 | echo 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 |
|
---|
231 | do_diff() {
|
---|
232 | diff -uwbB ${symdir}/${i} ${dir}/${i}.new
|
---|
233 | }
|
---|
234 |
|
---|
235 | do_move() {
|
---|
236 | rm ${dir}/${i}.bak
|
---|
237 | mv ${dir}/${i} ${dir}/${i}.bak \
|
---|
238 | || cleanexit 1
|
---|
239 | log backuped ${dir}/${i}
|
---|
240 |
|
---|
241 | mv ${dir}/${i}.new ${dir}/${i} \
|
---|
242 | || cleanexit 1
|
---|
243 | updated ${dir}/${i}
|
---|
244 | }
|
---|
245 |
|
---|
246 | bink() {
|
---|
247 | $CMD
|
---|
248 | }
|
---|
249 |
|
---|
250 | dir=${lcd}
|
---|
251 |
|
---|
252 | echo Config Node -- Version: $VERSION
|
---|
253 |
|
---|
254 | #check config dir
|
---|
255 | #
|
---|
256 | if [ ! -d ${dir} ]; then
|
---|
257 | mkdir -p ${dir} || cleanexit 1
|
---|
258 | fi
|
---|
259 |
|
---|
260 | if [ -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
|
---|
270 | fi
|
---|
271 |
|
---|
272 | CMD=do_move
|
---|
273 | if [ "x$1" = "x-d" ]; then
|
---|
274 | CMD=do_diff
|
---|
275 | dir=${TMPDIR}
|
---|
276 | shift
|
---|
277 | fi
|
---|
278 |
|
---|
279 | # Use the cmd line argument, of any
|
---|
280 | #
|
---|
281 | if [ $# = 1 ]; then
|
---|
282 | nodename=$1
|
---|
283 | else
|
---|
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
|
---|
290 | fi
|
---|
291 |
|
---|
292 | nlist=${TMPPREFIX}.l
|
---|
293 |
|
---|
294 | test -z $default && default=$nodename
|
---|
295 |
|
---|
296 | test -z $nodename && getvalidnodename
|
---|
297 |
|
---|
298 | log Fetching file list from $link for $nodename
|
---|
299 |
|
---|
300 | safefetch ${link}${nodename} ${dir}/${list}
|
---|
301 |
|
---|
302 | for i in `cat ${dir}/${list}`
|
---|
303 | do
|
---|
304 | log getting ${i} for ${nodename} from ${link}
|
---|
305 | fetch -q -o - ${link}${nodename}/${i} > ${dir}/${i}.new \
|
---|
306 | || cleanexit 1
|
---|
307 | done
|
---|
308 |
|
---|
309 |
|
---|
310 | for i in `cat ${dir}/${list}`
|
---|
311 | do
|
---|
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
|
---|
348 | done
|
---|
349 |
|
---|
350 |
|
---|
351 | if [ -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
|
---|
365 | fi
|
---|
366 |
|
---|
367 | # Record our name.
|
---|
368 | echo ${nodename} > ${dir}/myname
|
---|
369 |
|
---|
370 | # Rebuild reverse lookups
|
---|
371 | H=`cat /etc/rc.node.local | grep hostname | sed -e s/hostname=// | sed -e s/[\"\']//g`
|
---|
372 | hostname $H
|
---|
373 | if [ -r /etc/namedb/make-localhost ]; then
|
---|
374 | (
|
---|
375 | cd /etc/namedb || exit 1
|
---|
376 | sh /etc/namedb/make-localhost || exit 1
|
---|
377 | ) || exit 1
|
---|
378 | fi
|
---|
379 |
|
---|
380 | cleanse
|
---|
381 |
|
---|
382 | if [ -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
|
---|
387 | fi
|
---|
388 |
|
---|
389 | exit 0
|
---|