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