Changeset 4985 in genesis for tools


Ignore:
Timestamp:
Nov 2, 2005, 5:26:32 PM (19 years ago)
Author:
dirkx
Message:

New version of config-node

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/config-node.sh

    r4317 r4985  
    11#!/bin/sh
     2#
    23# (c) Copyright 2002, 2003, 2005 Stichting Wireless Leiden, all
    34#     rights reserved. More information can be found on
     
    56#     http://wleiden.webweaving.org:8080/svn/node-config/LICENSE
    67#
    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#
    915# If there is a global system configuration file, suck it in.
    1016#
     
    1420TMPPREFIX=${TMPDIR}/wl-tmp-$$
    1521WHOST=${WHOST:-rambo.wleiden.net}
    16 HTTP_PROXY=${HTTP_PROXY:-http://proxy.wleiden.net:3128}
     22HTTP_PROXY_DEFAULT=${HTTP_PROXY:-http://proxy.wleiden.net:3128}
    1723HTTP_USER_AGENT=${HTTP_USER_AGENT:-curl.faked.fetch/0.0}
    18 VERSION=1.00
     24VERSION=1.03
    1925QUIET=${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
     26PRETEND=no
     27
     28FETCH=${FETCH:-/usr/bin/fetch}
     29test -e ${FETCH} || FETCH="curl"
     30
     31if echo ${FETCH} | grep -q curl; then
     32        FETCH="${FETCH} --silent"
    3733else
    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"
     35fi
     36
     37usage() {
     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
     47for i in $*
     48do
     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
     75done
    5776
    5877export HTTP_USER_AGENT
     
    7291connset()
    7392{
    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
    7896 
    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
    148141log()
    149142{
    150   echo $*
     143        if [ -z ${QUIET} ]; then 
     144                echo "$*"
     145        fi
     146}
     147lognlr()
     148{
     149        if [ -z ${QUIET} ]; then 
     150                echo -n "$*"
     151        fi
    151152}
    152153
    153154cleanse()
    154155{
    155   rm -f ${TMPPREFIX}.?
     156        rm -f ${TMPPREFIX}.?
    156157}
    157158
     
    161162cleanexit()
    162163{
    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
     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
    172173}
    173174
    174175safefetch()
    175176{
    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
     200getvalidnodenames()
     201{
     202        log Fetching list of nodes from ${link}
     203        ${FETCH} -o - ${link} > ${nlist} || cleanexit 1
    185204}
    186205
    187206getvalidnodename()
    188207{
    189 log  " "
    190 log  " "
    191 log  " "
    192 log  Fetching list of nodes from ${link}
    193 
    194 fetch -q -o - ${link} > ${nlist} || cleanexit 1
    195 
    196208while ! grep -q "^${nodename}\$" ${nlist}
    197209do
    198210  echo Nodes:
    199   cat ${nlist}
     211  if [ -x /usr/bin/column ]; then
     212        column  ${nlist}
     213  else
     214        cat ${nlist}
     215  fi
    200216  echo
    201217  echo -n enter nodename \[default: ${default}\]:
     
    216232
    217233do_diff() {
    218   diff -uwbB ${symdir}/${i} ${dir}/${i}.new
    219 }
    220 
     234        diff -uwbB $1 $1.new
     235}
    221236
    222237do_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
     238if [ -e $1 ]; then
     239        mv $1 $1.bak  || cleanexit 1
     240fi
     241cp $1.new $1 || cleanexit 1
     242rm $1.new || cleanexit 1
     243}
     244
     245linkin() {
     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.
    238256}
    239257
     
    249267
    250268if [ -z ${HTTP_PROXY} ]; then
    251   # checking connection - and only fiddle
    252   # with interfaces if we need to.
    253   #
    254269  (
    255     echo no proxy defined - checking connection.
     270    log Checking DNS for ${WHOST}
    256271    host ${WHOST} > /dev/null || exit 1
     272    log Checking if ${WHOST} can be reached
    257273    ping -qnoc 1 ${WHOST} > /dev/null || exit 1
     274    log Connection OK
    258275    exit 0
    259276  ) || connset
     
    267284fi
    268285
    269 # Use the cmd line argument, of any
    270 #
    271 if [ $# = 1 ]; then
    272   nodename=$1
     286if [ -r ${lcd}/myname ]; then
     287    default=`cat ${lcd}/myname`
    273288else
    274   if [ -r ${lcd}/myname ]; then
    275     default=`cat ${lcd}/myname`
    276   else
    277289    default=`hostname -s`
    278290    test -z $default && default=none
    279   fi
    280291fi
    281292
     
    284295test -z $default && default=$nodename
    285296
     297getvalidnodenames || exit 1
     298
    286299test -z $nodename && getvalidnodename
    287300
     301while test -z $nodename || ! grep -q ${nodename} ${nlist}
     302do
     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
     311done
     312
    288313log Fetching file list from $link for $nodename
    289314
    290315safefetch ${link}${nodename} ${dir}/${list} 
    291316
     317lognlr "Fetching:"
    292318for i in `cat ${dir}/${list}`
    293319do
    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 \
    296322    || cleanexit 1
    297323done
    298 
     324log .
    299325
    300326for i in  `cat ${dir}/${list}`
    301327do
    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
    310360done
    311 
    312361
    313362if [ -e /etc/rc.local ]; then
     
    331380
    332381# Rebuild reverse lookups
    333 H=`cat /etc/rc.node.local | grep hostname | sed -e s/hostname=// | sed -e s/[\"\']//g`
    334 hostname $H
     382if 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
     385else
     386        echo Warning: rc.node.local missing.
     387fi
     388
    335389if [ -r  /etc/namedb/make-localhost ]; then
    336390  (
     
    340394fi
    341395
    342 cleanse
     396cleanse || exit 1
    343397
    344398if [ -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
     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
    349403fi
    350404
Note: See TracChangeset for help on using the changeset viewer.