Changeset 4985 in genesis
- Timestamp:
- Nov 2, 2005, 5:26:32 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/config-node.sh
r4317 r4985 1 1 #!/bin/sh 2 # 2 3 # (c) Copyright 2002, 2003, 2005 Stichting Wireless Leiden, all 3 4 # rights reserved. More information can be found on … … 5 6 # http://wleiden.webweaving.org:8080/svn/node-config/LICENSE 6 7 # 7 # Marten Vijn 24-03-03 8 # new version 14-11-2003 8 # 1.00 9 # ?? Marten Vijn 24-03-03 10 # ?? new version 14-11-2003 11 # 1.03 proxy cleanup, detect faulty files, generalize 12 # file list, check node name to be valid, '-n' mode. 13 # make moving of final files a bit safer. (dirkx) 14 # 9 15 # If there is a global system configuration file, suck it in. 10 16 # … … 14 20 TMPPREFIX=${TMPDIR}/wl-tmp-$$ 15 21 WHOST=${WHOST:-rambo.wleiden.net} 16 HTTP_PROXY =${HTTP_PROXY:-http://proxy.wleiden.net:3128}22 HTTP_PROXY_DEFAULT=${HTTP_PROXY:-http://proxy.wleiden.net:3128} 17 23 HTTP_USER_AGENT=${HTTP_USER_AGENT:-curl.faked.fetch/0.0} 18 VERSION=1.0 024 VERSION=1.03 19 25 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 26 PRETEND=no 27 28 FETCH=${FETCH:-/usr/bin/fetch} 29 test -e ${FETCH} || FETCH="curl" 30 31 if echo ${FETCH} | grep -q curl; then 32 FETCH="${FETCH} --silent" 37 33 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 34 FETCH="${FETCH} -q" 35 fi 36 37 usage() { 38 echo Usage $0 [-q] [-p proxy] [-d] [-D] [-n] [hostname] 39 echo "-p <proxy> Set a proxy" 40 echo "-P Use ${HTTP_PROXY_DEFAULT} as a proxy" 41 echo "-d Use DHCP to get an address" 42 echo "-n Show what would happen - but do not do it" 43 echo "-q Suppress all output and user interaction" 44 exit 1 45 } 46 47 for i in $* 48 do 49 case "$i" 50 in 51 -d) connset || exit 1 52 ;; 53 -q) 54 QUIET=yes 55 ;; 56 -p) 57 shift; 58 HTTP_PROXY=$1 59 export HTTP_PROXY 60 ;; 61 -p) 62 HTTP_PROXY=HTTP_PROXY_DEFAULT 63 export HTTP_PROXY 64 ;; 65 -n) 66 PRETEND=yes 67 ;; 68 *) 69 test $# -eq 1 || usage 70 nodename=$i 71 break; 72 ;; 73 esac 74 shift 75 done 57 76 58 77 export HTTP_USER_AGENT … … 72 91 connset() 73 92 { 74 75 if [ `ps ax | grep -c dhclient` != "1" ] ; then 76 killall dhclient 77 fi 93 if [ `ps ax | grep -c dhclient` != "1" ] ; then 94 killall dhclient 95 fi 78 96 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 # 97 echo "Enter an IP address of a nearby Nameserver or use:" 98 echo " 1 to use COPE \(on Wleiden\)" 99 echo " 2 to use XS4All \(on the internet\)" 100 echo " 3 to use the LCP server \(on the internal LCP networ\)" 101 102 echo -n "IP address or 1/2/3: " 103 read dns_list 104 105 case $dns_list in 106 1) 107 resolver="172.17.8.1" 108 ;; 109 2) 110 resolver="194.109.9.99" 111 ;; 112 3) 113 resolver="10.0.0.1" 114 ;; 115 *) 116 resolver=$dns_list 117 ;; 118 esac 119 120 cp /etc/resolv.conf /etc/resolv.bak || exit 1 121 echo "nameserver ${resolver}" > /etc/resolv.conf 122 123 for nic in `ifconfig -l` 124 do 125 case ${nic} in 126 lo0 | wi*) 127 ;; 128 *) 129 if ping -qnoc ${WHOST}; then 130 echo Connection on interface ${nic} ok 131 else 132 killall dhclient 133 echo Trying to get a DHCP lease on ${nic} 134 dhclient -1 ${nic} 135 fi 136 ;; 137 esac 138 done 139 } 140 148 141 log() 149 142 { 150 echo $* 143 if [ -z ${QUIET} ]; then 144 echo "$*" 145 fi 146 } 147 lognlr() 148 { 149 if [ -z ${QUIET} ]; then 150 echo -n "$*" 151 fi 151 152 } 152 153 153 154 cleanse() 154 155 { 155 156 rm -f ${TMPPREFIX}.? 156 157 } 157 158 … … 161 162 cleanexit() 162 163 { 163 164 165 166 167 168 169 170 171 164 E=1 165 if [ $# -gt 0 ]; then 166 E=$1 167 fi 168 cleanse 169 log Exit 170 exit $E 171 # Trap any weird exit codes. 172 exit 1 172 173 } 173 174 174 175 safefetch() 175 176 { 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 177 url=$1 178 file=$2 179 ${FETCH} -o - ${link}${nodename} > ${TMPPREFIX}.x \ 180 || cleanexit 1 181 182 # Genesis can provide us with corrupted/empty files 183 # with a 200 OK - so insist that they are at least 184 # a few lines long. 185 # 186 set `wc -l ${TMPPREFIX}.x` 187 if [ $1 -lt 2 ]; then 188 echo File ${link}${nodename} is less than 2 lines long. 189 echo Assuming a problem with Genesis. 190 cleanexit 2 191 fi 192 193 cp ${TMPPREFIX}.x ${dir}/${list} \ 194 || cleanexit 1 195 rm -f ${TMPPREFIX}.x 196 197 return 0 198 } 199 200 getvalidnodenames() 201 { 202 log Fetching list of nodes from ${link} 203 ${FETCH} -o - ${link} > ${nlist} || cleanexit 1 185 204 } 186 205 187 206 getvalidnodename() 188 207 { 189 log " "190 log " "191 log " "192 log Fetching list of nodes from ${link}193 194 fetch -q -o - ${link} > ${nlist} || cleanexit 1195 196 208 while ! grep -q "^${nodename}\$" ${nlist} 197 209 do 198 210 echo Nodes: 199 cat ${nlist} 211 if [ -x /usr/bin/column ]; then 212 column ${nlist} 213 else 214 cat ${nlist} 215 fi 200 216 echo 201 217 echo -n enter nodename \[default: ${default}\]: … … 216 232 217 233 do_diff() { 218 diff -uwbB ${symdir}/${i} ${dir}/${i}.new 219 } 220 234 diff -uwbB $1 $1.new 235 } 221 236 222 237 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 if [ -e $1 ]; then 239 mv $1 $1.bak || cleanexit 1 240 fi 241 cp $1.new $1 || cleanexit 1 242 rm $1.new || cleanexit 1 243 } 244 245 linkin() { 246 symdir=$1 247 file=$2 248 249 if [ ${PRETEND} = 'yes' ]; then 250 echo "** $CMD $*" 251 else 252 $CMD $dir/$file || exit 1 253 fi 254 255 test -e $symdir/$file || echo WARNING: Symlink $symdir/$file not in place. 238 256 } 239 257 … … 249 267 250 268 if [ -z ${HTTP_PROXY} ]; then 251 # checking connection - and only fiddle252 # with interfaces if we need to.253 #254 269 ( 255 echo no proxy defined - checking connection.270 log Checking DNS for ${WHOST} 256 271 host ${WHOST} > /dev/null || exit 1 272 log Checking if ${WHOST} can be reached 257 273 ping -qnoc 1 ${WHOST} > /dev/null || exit 1 274 log Connection OK 258 275 exit 0 259 276 ) || connset … … 267 284 fi 268 285 269 # Use the cmd line argument, of any 270 # 271 if [ $# = 1 ]; then 272 nodename=$1 286 if [ -r ${lcd}/myname ]; then 287 default=`cat ${lcd}/myname` 273 288 else 274 if [ -r ${lcd}/myname ]; then275 default=`cat ${lcd}/myname`276 else277 289 default=`hostname -s` 278 290 test -z $default && default=none 279 fi280 291 fi 281 292 … … 284 295 test -z $default && default=$nodename 285 296 297 getvalidnodenames || exit 1 298 286 299 test -z $nodename && getvalidnodename 287 300 301 while test -z $nodename || ! grep -q ${nodename} ${nlist} 302 do 303 echo 304 echo Error: Node named \"$nodename\" not known. 305 if [ -z ${QUIET} ]; then 306 exit 1 307 fi 308 echo Please select one from the list. 309 echo 310 getvalidnodename 311 done 312 288 313 log Fetching file list from $link for $nodename 289 314 290 315 safefetch ${link}${nodename} ${dir}/${list} 291 316 317 lognlr "Fetching:" 292 318 for i in `cat ${dir}/${list}` 293 319 do 294 log getting ${i} for ${nodename} from ${link}295 fetch -q-o - ${link}${nodename}/${i} > ${dir}/${i}.new \320 lognlr " ${i}" 321 $FETCH -o - ${link}${nodename}/${i} > ${dir}/${i}.new \ 296 322 || cleanexit 1 297 323 done 298 324 log . 299 325 300 326 for i in `cat ${dir}/${list}` 301 327 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 328 case ${i} in 329 linux.sh | config | txtconfig ) 330 # log obsolete file: ${i} - skipped 331 ;; 332 resolv.conf | rc.node.local | rc.local) 333 linkin /etc/ ${i} 334 ;; 335 snmpd.local.conf) 336 linkin /usr/local/share/snmp/ ${i} 337 ;; 338 named.conf) 339 linkin/etc/namedb/ ${i} 340 ;; 341 dhcpd.conf) 342 linkin /usr/local/etc/ ${i} 343 ;; 344 zebra.conf | ospfd.conf) 345 linkin /usr/local/etc/zebra/ ${i} 346 ;; 347 authorized_keys) 348 linkin /root/.ssh ${i} 349 ;; 350 ssh_known_hosts) 351 linkin /etc/ssh ${i} 352 ;; 353 daemons.sh) 354 linkin /wl ${i} 355 ;; 356 *) 357 echo Script cannot cope with ${i} - ignoring.. 358 ;; 359 esac 310 360 done 311 312 361 313 362 if [ -e /etc/rc.local ]; then … … 331 380 332 381 # Rebuild reverse lookups 333 H=`cat /etc/rc.node.local | grep hostname | sed -e s/hostname=// | sed -e s/[\"\']//g` 334 hostname $H 382 if test -e /etc/rc.node.local; then 383 H=`cat /etc/rc.node.local | grep hostname | sed -e s/hostname=// | sed -e s/[\"\']//g` 384 hostname $H 385 else 386 echo Warning: rc.node.local missing. 387 fi 388 335 389 if [ -r /etc/namedb/make-localhost ]; then 336 390 ( … … 340 394 fi 341 395 342 cleanse 396 cleanse || exit 1 343 397 344 398 if [ -e /etc/rc.empty.conf ] ; then 345 rm /etc/rc.empty.conf || exit 346 347 348 399 rm /etc/rc.empty.conf || exit 1 400 echo removed /etc/rc.empty.conf - and rebooting in 30 seconds \(or press ctrl-C to abort\) 401 read -t 30 DUMMY 402 reboot 349 403 fi 350 404
Note:
See TracChangeset
for help on using the changeset viewer.