AyumuUeha | 76a01bc | 2017-05-18 13:34:13 +0900 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | #************************************************************/ |
| 3 | #** File: vsg_vcpe_proxy_setup.sh */ |
| 4 | #** Contents: Contains shell script to setup packages & */ |
| 5 | #** applications inside the VCPE. */ |
| 6 | #************************************************************/ |
| 7 | |
| 8 | time_begin=`date` |
| 9 | echo $time_begin |
| 10 | echo "vsg_vcpe_proxy_setup.sh: Begin" |
| 11 | |
| 12 | function extract_stag_ctag() { |
| 13 | echo "Entering extract_stag_ctag function.." |
| 14 | VCPE_NAME=$VCPEPROXY_NAME |
| 15 | echo "Input String $VCPE_NAME" |
| 16 | vcpe_substrings=$( echo $VCPE_NAME | tr "-" "\n" ) |
| 17 | i=0 |
| 18 | for str in $vcpe_substrings |
| 19 | do |
| 20 | echo "i=$i str=$str" |
| 21 | if [ $i -eq 1 ]; then |
| 22 | stag=$str |
| 23 | fi |
| 24 | if [ $i -eq 2 ]; then |
| 25 | ctag=$str |
| 26 | fi |
| 27 | i=$(( i + 1 )) |
| 28 | done |
| 29 | |
| 30 | echo "Parsed String output: stag=$stag ctag=$ctag " |
| 31 | STAG=$stag; export STAG |
| 32 | CTAG=$ctag; export CTAG |
| 33 | } |
| 34 | |
| 35 | function install_restserver() { |
| 36 | echo "install_rest(): Installing REST artifacts in docker instance: $VCPEPROXY_NAME" |
| 37 | time sudo docker exec -t $VCPEPROXY_NAME apt-get update |
| 38 | echo "Installing npm.." |
| 39 | time sudo docker exec -t $VCPEPROXY_NAME apt-get install npm -y |
| 40 | echo "Installing json-server.." |
| 41 | time sudo docker exec -t $VCPEPROXY_NAME npm install -g json-server@0.9.6 |
| 42 | echo "Installing line-reader.." |
| 43 | time sudo docker exec -t $VCPEPROXY_NAME npm install -g line-reader |
| 44 | echo "Installing bluebird.." |
| 45 | time sudo docker exec -t $VCPEPROXY_NAME npm install -g bluebird |
| 46 | #PPPoE http server |
| 47 | echo "Installing express.." |
| 48 | time sudo docker exec -t $VCPEPROXY_NAME npm install -g express |
| 49 | echo "Installing body-parser.." |
| 50 | time sudo docker exec -t $VCPEPROXY_NAME npm install -g body-parser |
| 51 | #PPPoE http server end |
| 52 | } |
| 53 | |
| 54 | function install_pppoe_soft() { |
| 55 | echo "install_pppoe_soft(): Installing PPPoE software in $VCPEPROXY_NAME" |
| 56 | time sudo docker exec -t $VCPEPROXY_NAME apt-get update |
| 57 | echo "Installing ppp.." |
| 58 | time sudo docker exec -t $VCPEPROXY_NAME apt-get install ppp -y |
| 59 | echo "Installing pppoe.." |
| 60 | time sudo docker exec -t $VCPEPROXY_NAME apt-get install pppoe -y |
| 61 | } |
| 62 | |
| 63 | function install_ipv6_soft() { |
| 64 | echo "install_pppoe_soft(): Installing IPv6 software in $VCPEPROXY_NAME" |
| 65 | time sudo docker exec -t $VCPEPROXY_NAME apt-get update |
| 66 | echo "Installing DHCPv6.." |
| 67 | time sudo docker exec -t $VCPEPROXY_NAME apt-get install radvd -y |
| 68 | } |
| 69 | |
| 70 | function install_network_soft() { |
| 71 | echo "install_soft(): Installing required software in $VCPEPROXY_NAME" |
| 72 | time sudo docker exec -t $VCPEPROXY_NAME apt-get update |
| 73 | echo "Installing iptables.." |
| 74 | time sudo docker exec -t $VCPEPROXY_NAME apt-get install iptables -y |
| 75 | echo "Installing tcpdump..." |
| 76 | time sudo docker exec -t $VCPEPROXY_NAME apt-get install tcpdump -y |
| 77 | echo "installing Node Js.." |
| 78 | time sudo docker exec -t $VCPEPROXY_NAME apt-get install nodejs -y |
| 79 | echo "installing...sshpass.." |
| 80 | time sudo docker exec -t $VCPEPROXY_NAME apt-get install sshpass -y |
| 81 | } |
| 82 | |
| 83 | function get_vcpeproxy_wan_ip() { |
| 84 | echo "Entering get_vcpeproxy_wan_ip function.." |
| 85 | addr=`sudo docker exec -t $VCPEPROXY_NAME ifconfig $VCPEPROXY_WAN_IFACE|grep "inet addr"| awk '{ print $2 }'` |
| 86 | |
| 87 | addr=`echo $addr|tr ":" "\n"` |
| 88 | i=1 |
| 89 | for str in $addr |
| 90 | do |
| 91 | echo "i=$i str=$str" |
| 92 | if [ $i -eq 2 ]; then |
| 93 | VCPEPROXY_WAN_IP=$str; export VCPEPROXY_WAN_IP |
| 94 | fi |
| 95 | i=$(( i + 1 )) |
| 96 | done |
| 97 | echo "Returning $VCPEPROXY_WAN_IP" |
| 98 | } |
| 99 | |
| 100 | function install_and_spinup_apmgmt() { |
| 101 | if [ -z $VCPEPROXY_DOCKER_HOME ]; then |
| 102 | echo "cleaning up $VCPEPROXY_DOCKER_HOME directory" |
| 103 | sudo -E docker exec -t $VCPEPROXY_NAME rm -rf $VCPEPROXY_DOCKER_HOME |
| 104 | fi |
| 105 | sudo -E docker exec -t $VCPEPROXY_NAME mkdir -p $VCPEPROXY_DOCKER_HOME |
| 106 | sudo docker cp $vsg_home_dir/$vsg_env_file $VCPEPROXY_NAME:$VCPEPROXY_DOCKER_HOME |
| 107 | echo "VCPEPROXY_WAN_IP=$VCPEPROXY_WAN_IP" |
| 108 | |
| 109 | # VLAN information |
| 110 | echo "{\"s-vlan\":\"$STAG\",\"c-vlan\":\"$CTAG\"}" > $vsg_home_dir/$PPPOE_AP_MGMT_DIR/info.txt |
| 111 | # Information on device for ONOS network configuration |
| 112 | echo "curl -X POST http://$NETCFG_CONSOLIDATOR_IP:$NETCFG_RESTAPI_PORT/rest:$VCPEPROXY_WAN_IP:$AP_RESTAPI_PORT" > $vsg_home_dir/$PPPOE_AP_MGMT_DIR/$AP_REST_NETCFG |
| 113 | chmod +x $vsg_home_dir/$PPPOE_AP_MGMT_DIR/$AP_REST_NETCFG |
| 114 | |
| 115 | echo "Archiving it to $APMGMT_TAR_FILE" |
| 116 | cd $vsg_home_dir/$PPPOE_AP_MGMT_DIR; tar -cvf - . >$APMGMT_TAR_FILE |
| 117 | sudo docker cp $APMGMT_TAR_FILE $VCPEPROXY_NAME:$NODEJS_MODULES_DIR |
| 118 | echo "Archiving it to $IPV6_TAR_FILE" |
| 119 | cd $vsg_home_dir/$IPV6_AP_DIR; tar -cvf - . >$IPV6_TAR_FILE |
| 120 | sudo docker cp $IPV6_TAR_FILE $VCPEPROXY_NAME:$VCPEPROXY_DOCKER_HOME |
| 121 | sudo docker cp $vsg_home_dir/$proxy_ap_mgmt_start_script $VCPEPROXY_NAME:$VCPEPROXY_DOCKER_HOME |
| 122 | sudo docker cp $vsg_home_dir/$proxy_ap_mgmt_stop_script $VCPEPROXY_NAME:$VCPEPROXY_DOCKER_HOME |
| 123 | sudo docker cp $vsg_home_dir/$proxy_ipv6_setup $VCPEPROXY_NAME:$VCPEPROXY_DOCKER_HOME |
| 124 | sudo docker exec $VCPEPROXY_NAME chmod +x $VCPEPROXY_DOCKER_HOME/$proxy_ap_mgmt_start_script |
| 125 | sudo docker exec $VCPEPROXY_NAME chmod +x $VCPEPROXY_DOCKER_HOME/$proxy_ap_mgmt_stop_script |
| 126 | sudo docker exec $VCPEPROXY_NAME chmod +x $VCPEPROXY_DOCKER_HOME/$proxy_ipv6_setup |
| 127 | if [[ "x$VSG_DOCKER_IPV4" != "xipv4" ]]; then |
| 128 | echo "Setup and start IPv6 apps" |
| 129 | sudo docker exec $VCPEPROXY_NAME $VCPEPROXY_DOCKER_HOME/$proxy_ipv6_setup |
| 130 | fi |
| 131 | |
| 132 | echo "mv json-server:/usr/local/lib/node_modules/json-server/lib/server/public" |
| 133 | sudo docker exec $VCPEPROXY_NAME mv /usr/local/lib/node_modules/json-server/lib/server/public/index.html /usr/local/lib/node_modules/json-server/lib/server/public/index.html_sav |
| 134 | |
| 135 | echo "Starting proxy_ap_mgmt_start_script" |
| 136 | sudo docker exec $VCPEPROXY_NAME $VCPEPROXY_DOCKER_HOME/$proxy_ap_mgmt_start_script $VSG_DOCKER_IPV4 |
| 137 | echo "Started proxy_ap_mgmt_start_script" |
| 138 | echo "check whether nodejs is running" |
| 139 | sudo docker exec $VCPEPROXY_NAME ps -fade|grep nodejs |
| 140 | } |
| 141 | |
| 142 | function send_device_info_to_consolidator () { |
| 143 | sudo docker exec $VCPEPROXY_NAME ps -fade|grep nodejs|grep cController > /dev/null 2>&1 |
| 144 | if [ "$?" == 0 ]; then |
| 145 | echo "Posting rest:$VCPEPROXY_WAN_IP:$AP_RESTAPI_PORT to consolidator..." |
| 146 | sudo docker exec $VCPEPROXY_NAME bash $NODEJS_MODULES_DIR$AP_REST_NETCFG |
| 147 | fi |
| 148 | } |
| 149 | |
| 150 | VCPEPROXY_NAME=$1; export VCPEPROXY_NAME |
| 151 | VSG_ID=$2; export VSG_ID |
| 152 | VCPE_PROXY_ID=$3; export VCPE_PROXY_ID |
| 153 | |
| 154 | if [ -z $VCPEPROXY_NAME ]; then |
| 155 | echo " Missing Argument: VCPEPROXY_NAME...." |
| 156 | exit 1 |
| 157 | fi |
| 158 | if [ -z $VSG_ID ]; then |
| 159 | echo " Missing Argument: VSG_ID...." |
| 160 | exit 1 |
| 161 | fi |
| 162 | if [ -z $VCPE_PROXY_ID ]; then |
| 163 | echo " Missing Argument: VCPE_PROXY_ID...." |
| 164 | exit 1 |
| 165 | fi |
| 166 | echo "Reinitializing $VCPEPROXY_NAME docker as vcpe proxy" |
| 167 | extract_stag_ctag |
| 168 | sudo -E $vsg_home_dir/$respin_vcpeproxy_docker_script |
| 169 | |
| 170 | # Check whethere necessary packages are installed in VCPE |
| 171 | sudo docker exec $VCPEPROXY_NAME which nodejs > /dev/null 2>&1 |
| 172 | if [ "$?" == 1 ]; then |
| 173 | # VCPE docker image may be from repository, then install necessary packages |
| 174 | echo "Continuing the installation of vcpe_proxy docker" |
| 175 | install_network_soft |
| 176 | echo "Installing rest servcer" |
| 177 | install_restserver |
| 178 | echo "Installing pppoe soft" |
| 179 | install_pppoe_soft |
| 180 | echo "Installing ipv6 soft" |
| 181 | install_ipv6_soft |
| 182 | fi |
| 183 | echo "Extracting vcpeproxy_wan_ip" |
| 184 | get_vcpeproxy_wan_ip |
| 185 | echo "Before AP mgmt spinup...VCEPROXY_WAN_IP=$VCPEPROXY_WAN_IP" |
| 186 | install_and_spinup_apmgmt |
| 187 | echo "Before sending device info to consolidator..." |
| 188 | send_device_info_to_consolidator |
| 189 | |
| 190 | # To indicate VCPE setup completion |
| 191 | time_end=`date` |
| 192 | echo "Begin $time_begin" > $vsg_home_dir/$VCPEPROXY_NAME |
| 193 | echo $VCPEPROXY_NAME >> $vsg_home_dir/$VCPEPROXY_NAME |
| 194 | echo "End $time_end" >> $vsg_home_dir/$VCPEPROXY_NAME |
| 195 | echo $time_end |
| 196 | echo "vsg_vcpe_proxy_setup.sh: End" |