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