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