remove extention on some scripts and correct services
[debian6500.git] / master / opt / script / configure_fe306
1 #!/bin/bash
2
3 # parameters
4 #
5 # ============================================================================
6 #
7 # Copyright (C) THALES. All rights reserved
8 # Author: Laurent Mazet
9 #
10 # 2013-11-10 V1.0 : Creation
11 #
12 # 2013-11-20 V1.1 : L.Mazet ajout possibilite de configuration du switch
13 #
14 # ============================================================================
15
16 DRY=
17 ID=
18 IP=192.168.0.1
19 TRC6500_SCRIPT_DIR=$(dirname $0)
20
21 # help function
22
23 function usage () {
24 echo "usage: $PROGNAME [-a] [-d] [-h] [-i <id>]"
25 echo " -a: configure all boards"
26 echo " -d: dry mode"
27 echo " -h: help message"
28 echo " -i: board id (from 1 to 5)"
29 exit $@
30 }
31
32 # formating functions
33
34 function title () { echo -e "\033[0;1m$*\033[0;0m"; }
35 function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
36 function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
37 function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
38
39 # configuration values
40
41 # argument processing
42
43 while [ $# -gt 0 ]; do
44 case "$1" in
45 -a) ID=all;;
46 -d) DRY=yes;;
47 -h) usage 0;;
48 -i) shift; ID=$1;;
49 *) usage 1;;
50 esac
51 shift
52 done
53
54 # switch port configure function ()
55
56 function sw_configure () {
57 case "$1" in
58 off) CMD="-c 'configure terminal' -c 'interface range g1/39-44' -c 'shutdown' -c end -c 'clear mac address-table dynamic' -c 'clear ip arp inspection log' -c exit";;
59 on) CMD="-c 'configure terminal' -c 'interface range g1/39-44' -c 'no shutdown' -c end -c exit";;
60 1) CMD="-c 'configure terminal' -c 'interface g1/39' -c 'no shutdown' -c end -c exit";;
61 2) CMD="-c 'configure terminal' -c 'interface g1/40' -c 'no shutdown' -c end -c exit";;
62 3) CMD="-c 'configure terminal' -c 'interface g1/41' -c 'no shutdown' -c end -c exit";;
63 4) CMD="-c 'configure terminal' -c 'interface g1/42' -c 'no shutdown' -c end -c exit";;
64 5) CMD="-c 'configure terminal' -c 'interface g1/43' -c 'no shutdown' -c end -c exit";;
65 6) CMD="-c 'configure terminal' -c 'interface g1/44' -c 'no shutdown' -c end -c exit";;
66 esac
67
68 if [ "$DRY" = "yes" ]; then
69 echo connect_switch -h swm $CMD
70 else
71 LOG=/tmp/$PROGNAME-$$.log
72 echo -n "sw_configure $1: "
73 eval $TRC6500_SCRIPT_DIR/connect_switch $CMD swm >&$LOG && pass OK || { fail KO; cat $LOG; exit 1; }
74 rm -f $LOG
75 fi
76 }
77
78 case "$ID" in
79 1) CH1=0; CH2=1; CLOCKREF=external;;
80 2) CH1=2; CH2=3; CLOCKREF=internal;;
81 3) CH1=4; CH2=5; CLOCKREF=internal;;
82 4) CH1=6; CH2=7; CLOCKREF=internal;;
83 5) CH1=8; CH2=9; CLOCKREF=internal;;
84 6) CH1=10; CH2=11; CLOCKREF=internal;;
85 all)
86 for id in $(seq 1 5); do
87 title "switch off all fe306 ports"
88 sw_configure off
89 title "switch on port for fe306 $id"
90 sw_configure $id
91 title "configure fe306 $id"
92 if [ "$DRY" = "yes" ]; then
93 echo $(basename $0) -i $id
94 else
95 { $0 -i $id | mawk -W interactive '{print " " $0}'; } && pass OK || { fail KO; exit 1; }
96 fi
97 done
98 title "switch on all fe306 ports"
99 sw_configure on
100 exit 0
101 ;;
102 *) echo "unknown fe306 id ($ID)"; exit 1;;
103 esac
104
105 # configure function
106
107 function configure () {
108 echo -n "$1 [$2 <= $3]: "
109 if [ "$DRY" = "yes" ]; then
110 echo wget -q -O - http://$IP/$1?$2=$3
111 else
112 wget -q -O - http://$IP/$1?$2=$3 >/dev/null && pass OK || { fail KO; exit 1; }
113 fi
114 }
115
116 # setup local address
117
118 title "setup local address"
119 cmd="ifconfig eth1:1 192.168.0.2 netmask 255.255.255.0"
120 [ "$DRY" = "yes" ] && echo $cmd || { echo -n $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
121
122 # check if fe306 is connected
123
124 #title "check presence of $IP"
125 #cmd="ping -c 1 -w 10 -W 10 $IP"
126 #[ "$DRY" = "yes" ] && echo $cmd || { echo -n $cmd" "; eval $cmd >&/dev/null && pass OK || { warn KO; ifconfig eth1:1 down; exit 0; }; }
127
128 # get serial number
129
130 [ "$DRY" = "yes" ] && SN=00 || \
131 SN=$(wget -q -O - http://$IP/versions_en.html | mawk '/MODULE/ { module = 1 } /Serial Number/ { if (module) { printf "%02X", $4; exit 0 } }')
132
133 [[ "$SN" =~ ^[0-9A-F][0-9A-F]$ ]] || { echo "unknown serial number ($SN)"; exit 1; }
134
135 # configure ip
136
137 title "configure ip"
138
139 configure ModeServ.cmd serv_mode MANUAL
140 configure MacServ.cmd serv_mac 00.80.EE.00.$SN.01
141 configure IpServ.cmd serv_ip $(getent hosts | awk '/fe306-'$ID'/ {print $1}')
142 configure MaskServ.cmd serv_mask 255.255.255.0
143
144 for i in $(seq 1 8); do
145 configure MacProd$i.cmd prod_mac$i 00.80.EE.00.$SN.0$((i+1))
146 configure IpProd$i.cmd prod_ip$i 10.133.26.1$ID$i
147 done
148
149 configure IpMulticast.cmd multicast_ip 238.0.0.0
150 configure RxMulticast.cmd multicast_rx 62002
151 configure TxMulticast.cmd multicast_tx 62004
152 configure TTL.cmd ttl 10
153
154 # configure gps
155
156 title "configure gps"
157
158 configure GpsRate.cmd gps_rate 19200
159 configure GpsChar.cmd gps_char 8
160 configure GpsStop.cmd gps_stop 1
161 configure GpsParity.cmd gps_parity no
162
163 # configure miscellaneous
164
165 title "configure miscellaneous"
166 configure BoardNum.cmd board_num $ID
167 configure RackNum.cmd rack_num 1
168 configure Chan1Num.cmd channel1_num $CH1
169 configure Chan2Num.cmd channel2_num $CH2
170
171 configure FpgaLoc.cmd fpga_loc FLASH
172 configure Clk10Mhz.cmd clk_10 $CLOCKREF
173 configure PllConfig.cmd pll_cfg pll_cfg_02
174
175 # unset local address
176
177 title "unset local address"
178 cmd="ifconfig eth1:1 down"
179 [ "$DRY" = "yes" ] && echo $cmd || { echo -n $cmd" "; eval $cmd && pass OK || { fail KO; exit 1; }; }
180
181 # vim:set tabstop=4 shiftwidth=4 softtabstop=4: