correct fe306 configuration scipt
authorLaurent Mazet <laurent.mazet@thalesgroup.com>
Thu, 7 Jan 2016 14:48:42 +0000 (15:48 +0100)
committerLaurent Mazet <laurent.mazet@thalesgroup.com>
Thu, 7 Jan 2016 14:48:42 +0000 (15:48 +0100)
master/opt/script/configure_fe306

index 0d90204edb434be0366a9c8ccf02b0765f4dbfe1..e6a83634daaafc062b1af4f84d637819fb359508 100755 (executable)
@@ -31,10 +31,13 @@ function usage () {
 
 # formating functions
 
-function title () { echo -e "\033[0;1m$*\033[0;0m"; }
-function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
-function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
-function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
+function title () { echo -e "$conf_header\033[0;1m$*\033[0;0m"; }
+function pass () { echo -e "$conf_header\033[1;32m$*\033[0;0m"; }
+function warn () { echo -e "$conf_header\033[1;33m$*\033[0;0m"; }
+function fail () { echo -e "$conf_header\033[1;31m$*\033[0;0m"; }
+function write () { echo -n "$conf_header$*"; }
+function writeln () { echo "$conf_header$*"; }
+
 
 # configuration values
 
@@ -66,10 +69,10 @@ function sw_configure () {
     esac
 
     if [ "$DRY" = "yes" ]; then
-        echo connect_switch -h swm $CMD
+        writeln connect_switch -h swm $CMD
     else
                LOG=/tmp/$PROGNAME-$$.log
-               echo -n "sw_configure $1: "
+               write "sw_configure $1: "
         eval $TRC6500_SCRIPT_DIR/connect_switch $CMD swm >&$LOG && pass OK || { fail KO; cat $LOG; exit 1; }
                rm -f $LOG
     fi
@@ -89,25 +92,27 @@ all)
         title "switch on port for fe306 $id"
         sw_configure $id
         title "configure fe306 $id"
+        export conf_header=" "
         if [ "$DRY" = "yes" ]; then
-            echo $(basename $0) -i $id
+            writeln $(basename $0) -i $id
         else
-            { $0 -i $id | mawk -W interactive '{print "  " $0}'; } && pass OK || { fail KO; exit 1; }
+            $0 -i $id && pass OK || { fail KO; exit 1; }
         fi
+        export conf_header=""
     done
     title "switch on all fe306 ports"
     sw_configure on
     exit 0
     ;;
-*) echo "unknown fe306 id ($ID)"; exit 1;;
+*) writeln "unknown fe306 id ($ID)"; exit 1;;
 esac
 
 # configure function
 
 function configure () {
-    echo -n "$1 [$2 <= $3]: "
+    write "$1 [$2 <= $3]: "
     if [ "$DRY" = "yes" ]; then
-       echo wget -q -O - http://$IP/$1?$2=$3
+       writeln wget -q -O - http://$IP/$1?$2=$3
     else
         wget -q -O - http://$IP/$1?$2=$3 >/dev/null && pass OK || { fail KO; exit 1; }
     fi
@@ -117,20 +122,20 @@ function configure () {
 
 title "setup local address"
 cmd="ifconfig eth1:1 192.168.0.2 netmask 255.255.255.0"
-[ "$DRY" = "yes" ] && echo $cmd || { echo -n $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
+[ "$DRY" = "yes" ] && writeln $cmd || { write $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
 
 # check if fe306 is connected
 
 #title "check presence of $IP"
 #cmd="ping -c 1 -w 10 -W 10 $IP"
-#[ "$DRY" = "yes" ] && echo $cmd || { echo -n $cmd" "; eval $cmd >&/dev/null && pass OK || { warn KO; ifconfig eth1:1 down; exit 0; }; }
+#[ "$DRY" = "yes" ] && writeln $cmd || { write $cmd" "; eval $cmd >&/dev/null && pass OK || { warn KO; ifconfig eth1:1 down; exit 0; }; }
 
 # get serial number
 
 [ "$DRY" = "yes" ] && SN=00 || \
     SN=$(wget -q -O - http://$IP/versions_en.html | mawk '/MODULE/ { module = 1 } /Serial Number/ { if (module) { printf "%02X", $4; exit 0 } }')
 
-[[ "$SN" =~ ^[0-9A-F][0-9A-F]$ ]] || { echo "unknown serial number ($SN)"; exit 1; }
+[[ "$SN" =~ ^[0-9A-F][0-9A-F]$ ]] || { writeln "unknown serial number ($SN)"; exit 1; }
 
 # configure ip
 
@@ -138,7 +143,7 @@ title "configure ip"
 
 configure ModeServ.cmd serv_mode MANUAL
 configure MacServ.cmd serv_mac 00.80.EE.00.$SN.01
-configure IpServ.cmd serv_ip $(getent hosts | awk '/fe306-'$ID'/ {print $1}')
+configure IpServ.cmd serv_ip $(getent hosts | awk '/fe306-'$ID'/ {writeln $1}')
 configure MaskServ.cmd serv_mask 255.255.255.0
 
 for i in $(seq 1 8); do
@@ -176,6 +181,6 @@ configure PllConfig.cmd pll_cfg pll_cfg_02
 
 title "unset local address"
 cmd="ifconfig eth1:1 down"
-[ "$DRY" = "yes" ] && echo $cmd || { echo -n $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
+[ "$DRY" = "yes" ] && writeln $cmd || { write $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
 
 # vim:set tabstop=4 shiftwidth=4 softtabstop=4: