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

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

Fixed wrong updates

  • Property svn:executable set to *
File size: 6.1 KB
Line 
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
12PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
13TMPDIR=${TMPDIR:-/tmp}
14TMPPREFIX=${TMPDIR}/wl-tmp-$$
15WHOST=${WHOST:-rambo.wleiden.net}
16HTTP_PROXY=${HTTP_PROXY:-http://proxy.wleiden.net:3128}
17HTTP_USER_AGENT=${HTTP_USER_AGENT:-curl.faked.fetch/0.0}
18VERSION=1.00
19QUIET=${QUIET:-}
20
21if [ ${QUIET} ]; then
22 echo "Using..."
23 echo "no proxy"
24 echo "no dhclient"
25 echo "config `hostname -s`"
26 sleep 1
27fi
28
29echo "do we need a proxy ?"
30echo
31echo "just hit enter to go on without proxy settings"
32echo "otherwise type y for this proxy ${HTTP_PROXY} or enter your own proxy"
33echo "if don't want a proxy enter n "
34
35if [ -z ${QUIET} ]; then
36 read proxyset
37else
38 proxyset="n"
39fi
40
41case $proxyset in
42
43n)
44echo no proxy is set
45 ;;
46y)
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 ;;
56esac
57
58export HTTP_USER_AGENT
59export TMPDIR
60
61# Genesis master location.
62link=${GENESIS:-http://${WHOST}/cgi-bin/g_list.pl/}
63list=filelist
64
65# Location for private config
66lcd=${LCDIR:-/lcd}
67
68# Make sure we clean up our mess when needed.
69trap "rm -f ${TMPPREFIX}.?; echo Failed; exit 1;" 2 3
70
71# connection test function
72connset()
73{
74
75if [ `ps ax | grep -c dhclient` != "1" ] ; then
76 killall dhclient
77fi
78
79
80echo "enter the ipadress to resolv dns"
81echo 1 for cope as dns on wirelessleiden
82echo 2 for xs4all dns server
83echo 3 if you are at LCPL
84echo or type your on dns
85
86read dns_list
87
88case $dns_list in
891)
90 resolver="172.17.8.1"
91 ;;
922)
93 resolver="194.109.9.99"
94 ;;
953)
96 resolver="10.0.0.1"
97 ;;
98*)
99 resolver=$dns_list
100 ;;
101esac
102
103
104echo "/etc/resolv.conf has been changed from:"
105echo `cat /etc/resolv.conf`
106echo to
107echo $resolver
108echo "nameserver ${resolver}" > /etc/resolv.conf
109
110for nic in `ifconfig -l`
111do
112case ${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
129done
130}
131
132echo "do we need network on a nic by dhcp ?"
133echo "enter n to not use dhclient for configuration ! "
134
135if [ -z ${QUIET} ]; then
136 read nic_dhcp
137else
138 nic_dhcp="n"
139fi
140if [ "x${nic_dhcp}" = "xn" ] ; then
141 echo proceding...
142 else
143 echo running dhclient
144 connset
145fi
146# Logging function
147#
148log()
149{
150 echo $*
151}
152
153cleanse()
154{
155 rm -f ${TMPPREFIX}.?
156}
157
158# Normal exit; but make sure
159# we also clean up any tmp files
160#
161cleanexit()
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
174safefetch()
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
187getvalidnodename()
188{
189log " "
190log " "
191log " "
192log Fetching list of nodes from ${link}
193
194fetch -q -o - ${link} > ${nlist} || cleanexit 1
195
196while ! grep -q "^${nodename}\$" ${nlist}
197do
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
211done
212
213echo Node Selected: ${nodename}
214}
215
216
217do_diff() {
218 diff -uwbB ${symdir}/${i} ${dir}/${i}.new
219}
220
221
222do_move() {
223if [ -e ${dir}/${i}.bak ]; then
224 rm ${dir}/${i}.bak
225fi
226
227if [ -e ${dir}/${i} ]; then
228 mv ${dir}/${i} ${dir}/${i}.bak || cleanexit 1
229 log backup ${dir}/${i} to ${dir}/${i}.bak
230fi
231
232mv ${dir}/${i}.new ${dir}/${i} || cleanexit 1
233 log updated ${dir}/${i}
234}
235
236bink() {
237 $CMD
238}
239
240dir=${lcd}
241
242echo Config Node -- Version: $VERSION
243
244#check config dir
245#
246if [ ! -d ${dir} ]; then
247 mkdir -p ${dir} || cleanexit 1
248fi
249
250if [ -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
260fi
261
262CMD=do_move
263if [ "x$1" = "x-d" ]; then
264 CMD=do_diff
265 dir=${TMPDIR}
266 shift
267fi
268
269# Use the cmd line argument, of any
270#
271if [ $# = 1 ]; then
272 nodename=$1
273else
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
280fi
281
282nlist=${TMPPREFIX}.l
283
284test -z $default && default=$nodename
285
286test -z $nodename && getvalidnodename
287
288log Fetching file list from $link for $nodename
289
290safefetch ${link}${nodename} ${dir}/${list}
291
292for i in `cat ${dir}/${list}`
293do
294 log getting ${i} for ${nodename} from ${link}
295 fetch -q -o - ${link}${nodename}/${i} > ${dir}/${i}.new \
296 || cleanexit 1
297done
298
299
300for i in `cat ${dir}/${list}`
301do
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
310done
311
312
313if [ -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
327fi
328
329# Record our name.
330echo ${nodename} > ${dir}/myname
331
332# Rebuild reverse lookups
333H=`cat /etc/rc.node.local | grep hostname | sed -e s/hostname=// | sed -e s/[\"\']//g`
334hostname $H
335if [ -r /etc/namedb/make-localhost ]; then
336 (
337 cd /etc/namedb || exit 1
338 sh /etc/namedb/make-localhost || exit 1
339 ) || exit 1
340fi
341
342cleanse
343
344if [ -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
349fi
350
351exit 0
Note: See TracBrowser for help on using the repository browser.