vmrun revision bee3dc86
1#!/usr/bin/env bash
2# Copyright (c) 2016 Cisco and/or its affiliates.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at:
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15if [ $USER != "root" ] ; then
16    #echo "Restarting script with sudo..."
17    sudo $0 ${*}
18    exit
19fi
20
21if [ -z "$1" ]; then
22    echo "You must specify a demo name"
23    exit 0;
24fi
25
26if [ -f "$1" ]; then
27    DEMO=$1
28else
29    echo "This is not a valid filename"
30    exit 0;
31fi
32
33source $DEMO
34
35RED='\033[0;31m'
36GREEN='\033[0;32m'
37NC='\033[0m'
38
39function pause {
40    echo ""; echo ""
41    read -n1 -r -p "Press space to continue..." key
42    printf "\033c"
43}
44
45function instruction {
46
47    eval INSTR="$1"
48    eval CMD="$2"
49    echo ""
50    echo -e "${RED}********************************************************************************${NC} \n"
51    echo -e "${RED} ${INSTR} ${NC}"
52    echo -e "${GREEN} ${CMD} ${NC} \n"
53    echo -e "${RED}********************************************************************************${NC} \n"
54}
55
56#Clear and set netns and veths
57/vagrant/netns.sh $C1_IP $C1_GW $C2_IP $C2_GW
58
59#Clear the screen
60printf "\033c"
61
62if [ -e $DEMO.cmd ]; then
63    rm $DEMO.cmd
64fi
65
66#Loop through instructions and commands from filename input as $1
67for ((i=0;i<${#INSTR[@]};++i)); do
68    instruction "\${INSTR[i]}" "\${CMD[i]}"
69    eval "${CMD[i]}"
70    echo -e "${CMD[i]}" >> $DEMO.cmd
71    pause
72done
73
74
75exit 0
76
77
78