[4049] | 1 | #!/bin/sh
|
---|
[4085] | 2 | # (c) Copyright 2002, 2003, 2005 Stichting Wireless Leiden, all
|
---|
[4049] | 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 |
|
---|
[4049] | 12 | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
---|
| 13 | TMPDIR=${TMPDIR:-/tmp}
|
---|
| 14 | TMPPREFIX=${TMPDIR}/wl-tmp-$$
|
---|
[4050] | 15 | WHOST=${WHOST:-rambo.wleiden.net}
|
---|
[4049] | 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
|
---|
[4052] | 19 | QUIET=${QUIET:-}
|
---|
[4051] | 20 |
|
---|
[4052] | 21 | if [ ${QUIET} ]; then
|
---|
[4051] | 22 | echo "Using..."
|
---|
| 23 | echo "no proxy"
|
---|
| 24 | echo "no dhclient"
|
---|
| 25 | echo "config `hostname -s`"
|
---|
| 26 | sleep 1
|
---|
| 27 | fi
|
---|
| 28 |
|
---|
[4049] | 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 |
|
---|
[4050] | 35 | if [ -z ${QUIET} ]; then
|
---|
| 36 | read proxyset
|
---|
| 37 | else
|
---|
| 38 | proxyset="n"
|
---|
| 39 | fi
|
---|
[4049] | 40 |
|
---|
| 41 | case $proxyset in
|
---|
| 42 |
|
---|
[4085] | 43 | n)
|
---|
[4049] | 44 | echo no proxy is set
|
---|
[4085] | 45 | ;;
|
---|
[4049] | 46 | y)
|
---|
[4085] | 47 | echo this the proxy ${HTTP_PROXY}
|
---|
| 48 | export HTTP_PROXY
|
---|
| 49 | ;;
|
---|
[4049] | 50 |
|
---|
| 51 | *)
|
---|
[4085] | 52 | ${HTTP_PROXY}=${proxyset}
|
---|
| 53 | echo this the proxy $HTTP_PROXY
|
---|
| 54 | export HTTP_PROXY
|
---|
| 55 | ;;
|
---|
[4049] | 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
|
---|
[4085] | 78 |
|
---|
[4049] | 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)
|
---|
[4085] | 90 | resolver="172.17.8.1"
|
---|
| 91 | ;;
|
---|
| 92 | 2)
|
---|
| 93 | resolver="194.109.9.99"
|
---|
| 94 | ;;
|
---|
[4049] | 95 | 3)
|
---|
[4085] | 96 | resolver="10.0.0.1"
|
---|
| 97 | ;;
|
---|
[4049] | 98 | *)
|
---|
[4085] | 99 | resolver=$dns_list
|
---|
| 100 | ;;
|
---|
[4049] | 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
|
---|
[4085] | 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
|
---|
[4049] | 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 |
|
---|
[4050] | 135 | if [ -z ${QUIET} ]; then
|
---|
| 136 | read nic_dhcp
|
---|
| 137 | else
|
---|
| 138 | nic_dhcp="n"
|
---|
| 139 | fi
|
---|
[4049] | 140 | if [ "x${nic_dhcp}" = "xn" ] ; then
|
---|
[4085] | 141 | echo proceding...
|
---|
| 142 | else
|
---|
| 143 | echo running dhclient
|
---|
| 144 | connset
|
---|
[4049] | 145 | fi
|
---|
| 146 | # Logging function
|
---|
| 147 | #
|
---|
| 148 | log()
|
---|
| 149 | {
|
---|
[4085] | 150 | echo $*
|
---|
[4049] | 151 | }
|
---|
| 152 |
|
---|
| 153 | cleanse()
|
---|
| 154 | {
|
---|
[4085] | 155 | rm -f ${TMPPREFIX}.?
|
---|
[4049] | 156 | }
|
---|
| 157 |
|
---|
| 158 | # Normal exit; but make sure
|
---|
| 159 | # we also clean up any tmp files
|
---|
| 160 | #
|
---|
| 161 | cleanexit()
|
---|
| 162 | {
|
---|
[4085] | 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
|
---|
[4049] | 172 | }
|
---|
| 173 |
|
---|
| 174 | safefetch()
|
---|
| 175 | {
|
---|
[4085] | 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
|
---|
[4049] | 183 |
|
---|
[4085] | 184 | return 0
|
---|
[4049] | 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
|
---|
[4085] | 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
|
---|
[4049] | 207 |
|
---|
[4085] | 208 | if [ "x${nodename}" = "x" ]; then
|
---|
| 209 | nodename=${default}
|
---|
| 210 | fi
|
---|
[4049] | 211 | done
|
---|
| 212 |
|
---|
| 213 | echo Node Selected: ${nodename}
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 |
|
---|
| 217 | do_diff() {
|
---|
[4085] | 218 | diff -uwbB ${symdir}/${i} ${dir}/${i}.new
|
---|
[4049] | 219 | }
|
---|
| 220 |
|
---|
[4085] | 221 |
|
---|
[4049] | 222 | do_move() {
|
---|
[4085] | 223 | if [ -e ${dir}/${i}.bak ]; then
|
---|
[4054] | 224 | rm ${dir}/${i}.bak
|
---|
| 225 | fi
|
---|
[4049] | 226 |
|
---|
[4085] | 227 | if [ -e ${dir}/${i} ]; then
|
---|
| 228 | mv ${dir}/${i} ${dir}/${i}.bak || cleanexit 1
|
---|
[4054] | 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}
|
---|
[4049] | 234 | }
|
---|
| 235 |
|
---|
| 236 | bink() {
|
---|
[4085] | 237 | $CMD
|
---|
[4049] | 238 | }
|
---|
| 239 |
|
---|
| 240 | dir=${lcd}
|
---|
| 241 |
|
---|
| 242 | echo Config Node -- Version: $VERSION
|
---|
| 243 |
|
---|
| 244 | #check config dir
|
---|
| 245 | #
|
---|
| 246 | if [ ! -d ${dir} ]; then
|
---|
[4085] | 247 | mkdir -p ${dir} || cleanexit 1
|
---|
[4049] | 248 | fi
|
---|
| 249 |
|
---|
| 250 | if [ -z ${HTTP_PROXY} ]; then
|
---|
[4085] | 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
|
---|
[4049] | 260 | fi
|
---|
| 261 |
|
---|
| 262 | CMD=do_move
|
---|
| 263 | if [ "x$1" = "x-d" ]; then
|
---|
[4085] | 264 | CMD=do_diff
|
---|
| 265 | dir=${TMPDIR}
|
---|
| 266 | shift
|
---|
[4049] | 267 | fi
|
---|
| 268 |
|
---|
| 269 | # Use the cmd line argument, of any
|
---|
| 270 | #
|
---|
| 271 | if [ $# = 1 ]; then
|
---|
[4085] | 272 | nodename=$1
|
---|
[4049] | 273 | else
|
---|
[4085] | 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
|
---|
[4049] | 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
|
---|
[4085] | 294 | log getting ${i} for ${nodename} from ${link}
|
---|
| 295 | fetch -q -o - ${link}${nodename}/${i} > ${dir}/${i}.new \
|
---|
| 296 | || cleanexit 1
|
---|
[4049] | 297 | done
|
---|
| 298 |
|
---|
| 299 |
|
---|
| 300 | for i in `cat ${dir}/${list}`
|
---|
| 301 | do
|
---|
[4085] | 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
|
---|
[4049] | 310 | done
|
---|
| 311 |
|
---|
| 312 |
|
---|
| 313 | if [ -e /etc/rc.local ]; then
|
---|
[4085] | 314 | # See if we are in rc.local
|
---|
| 315 | if grep -q /config-node.sh /etc/rc.local; then
|
---|
[4049] | 316 |
|
---|
[4085] | 317 | echo As this node now has real configs - do enter a root password
|
---|
| 318 | echo
|
---|
| 319 | passwd \
|
---|
| 320 | || cleanexit 1
|
---|
[4049] | 321 |
|
---|
[4085] | 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
|
---|
[4049] | 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
|
---|
[4085] | 336 | (
|
---|
| 337 | cd /etc/namedb || exit 1
|
---|
| 338 | sh /etc/namedb/make-localhost || exit 1
|
---|
| 339 | ) || exit 1
|
---|
[4049] | 340 | fi
|
---|
| 341 |
|
---|
| 342 | cleanse
|
---|
| 343 |
|
---|
| 344 | if [ -e /etc/rc.empty.conf ] ; then
|
---|
[4085] | 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
|
---|
[4049] | 349 | fi
|
---|
| 350 |
|
---|
| 351 | exit 0
|
---|