remove unwated proxy in the script
[samplevnf.git] / tools / ubuntu-server-cloudimg-dpdk-samplevnf-modify.sh
1 #!/bin/bash
2 # Copyright (c) 2016-2017 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # installs required packages
17 # must be run from inside the image (either chrooted or running)
18
19 set -ex
20
21 if [ $# -eq 1 ]; then
22     nameserver_ip=$1
23
24     # /etc/resolv.conf is a symbolic link to /run, restore at end
25     rm /etc/resolv.conf
26     echo "nameserver $nameserver_ip" > /etc/resolv.conf
27     echo "nameserver 8.8.8.8" >> /etc/resolv.conf
28     echo "nameserver 8.8.4.4" >> /etc/resolv.conf
29 fi
30
31 INSTALL_BIN_PATH="/opt/nsb_bin"
32 BIN_PATH="/usr/sbin/"
33 TREX_VERSION="v2.20"
34 TREX_DOWNLOAD="https://trex-tgn.cisco.com/trex/release/$TREX_VERSION.tar.gz"
35 TREX_DIR=$INSTALL_BIN_PATH/trex/scripts
36
37 enable_proxy()
38 {
39        echo $https_proxy
40        echo $http_proxy
41        if [[ "$http_proxy" != "" ]]; then
42            echo 'Acquire::http::Proxy "$http_proxy";' > /etc/apt/apt.conf
43        fi
44 }
45
46 install_trex()
47 {
48
49         INSTALL_BIN_PATH="/opt/nsb_bin"
50         DPDK_DOWNLOAD="http://dpdk.org/browse/dpdk/snapshot/dpdk-16.07.zip"
51         TREX_VERSION="v2.20"
52         TREX_DOWNLOAD="https://trex-tgn.cisco.com/trex/release/$TREX_VERSION.tar.gz"
53         TREX_DIR=$INSTALL_BIN_PATH/trex/scripts
54         pushd .
55         cd $INSTALL_BIN_PATH
56         echo "Build TRex and installing Trex TG in $INSTALL_BIN_PATH/trex"
57         rm -rf ${TREX_DOWNLOAD##*/}
58         if [ ! -e ${TREX_DOWNLOAD##*/} ] ; then
59             wget $TREX_DOWNLOAD
60         fi
61         tar zxvf ${TREX_DOWNLOAD##*/}
62         #pushd .
63         rm -rf $INSTALL_BIN_PATH/trex
64         mkdir -p $INSTALL_BIN_PATH/trex
65         mv $TREX_VERSION trex/scripts
66         rm -rf $TREX_VERSION.tar.gz
67         cd $INSTALL_BIN_PATH/trex/scripts/ko/src/
68         make
69         make install
70         touch "$INSTALL_BIN_PATH/trex/scripts/automation/trex_control_plane/stl/__init__.py"
71         cp "$INSTALL_BIN_PATH/trex/scripts/dpdk_nic_bind.py" "$INSTALL_BIN_PATH"
72         popd
73 }
74 install_sample_vnf()
75 {
76               mkdir -p $INSTALL_BIN_PATH
77         echo "Install Sample VNFs"
78         pushd .
79         cd $INSTALL_BIN_PATH
80         git clone https://git.opnfv.org/samplevnf
81         cd samplevnf
82         VNF_CORE=$INSTALL_BIN_PATH/samplevnf
83         ./tools/vnf_build.sh -s -d='17.02'
84         cp $VNF_CORE/VNFs/vACL/build/vACL $INSTALL_BIN_PATH
85         cp $VNF_CORE/VNFs/vCGNAPT/build/vCGNAPT $INSTALL_BIN_PATH
86         cp $VNF_CORE/VNFs/vFW/build/vFW $INSTALL_BIN_PATH
87         cp $VNF_CORE/VNFs/DPPD-PROX/build/prox $INSTALL_BIN_PATH
88         cp $VNF_CORE/VNFs/UDP_Replay/build/UDP_Replay $INSTALL_BIN_PATH
89         cp $VNF_CORE/VNFs/vFW/vnf_template.txt $INSTALL_BIN_PATH
90
91                                 # copy to standard path
92         cp $VNF_CORE/VNFs/vACL/build/vACL $BIN_PATH
93         cp $VNF_CORE/VNFs/vCGNAPT/build/vCGNAPT $BIN_PATH
94         cp $VNF_CORE/VNFs/vFW/build/vFW $BIN_PATH
95         cp $VNF_CORE/VNFs/DPPD-PROX/build/prox $BIN_PATH
96         cp $VNF_CORE/VNFs/UDP_Replay/build/UDP_Replay $BIN_PATH
97
98         # build vpe
99         cd $VNF_CORE/dpdk/examples/ip_pipeline
100         export RTE_SDK= $VNF_CORE/dpdk
101         make
102         cp $VNF_CORE/build/ip_pipeline $INSTALL_BIN_PATH/vPE_vnf
103
104               echo "Done"
105         popd
106 }
107 # iperf3 only available for trusty in backports
108 if grep -q trusty /etc/apt/sources.list ; then
109     if [ "${YARD_IMG_ARCH}" = "arm64" ]; then
110         echo "deb [arch=${YARD_IMG_ARCH}] http://ports.ubuntu.com/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list
111     else
112         echo "deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list
113     fi
114 fi
115
116 # Workaround for building on CentOS (apt-get is not working with http sources)
117 # sed -i 's/http/ftp/' /etc/apt/sources.list
118
119 # Force apt to use ipv4 due to build problems on LF POD.
120 echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99force-ipv4
121
122 echo 'GRUB_CMDLINE_LINUX="resume=/dev/sda1 default_hugepagesz=1G hugepagesz=1G hugepages=4 iommu=on iommu=pt intel_iommu=on"' >> /etc/default/grub
123 echo 'huge /mnt/huge hugetlbfs defaults 0 0' >> vi /etc/fstab
124
125 mkdir /mnt/huge
126 chmod 777 /mnt/huge
127
128 for i in {1..2}
129 do
130     touch /etc/network/interfaces.d/eth$i.cfg
131     chmod 777 /etc/network/interfaces.d/eth$i.cfg
132     echo "auto eth$i" >> /etc/network/interfaces.d/eth$i.cfg
133     echo "iface eth$i inet dhcp" >> /etc/network/interfaces.d/eth$i.cfg
134 done
135
136 # this needs for checking dpdk status, adding interfaces to dpdk, bind, unbind etc..
137
138 # Add hostname to /etc/hosts.
139 # Allow console access via pwd
140 cat <<EOF >/etc/cloud/cloud.cfg.d/10_etc_hosts.cfg
141 manage_etc_hosts: True
142 #password: RANDOM
143 password: password
144 chpasswd: { expire: False }
145 ssh_pwauth: True
146 EOF
147
148 linuxheadersversion=$(echo ls boot/vmlinuz* | cut -d- -f2-)
149
150 apt-get update
151 apt-get install -y \
152     bc \
153     fio \
154     gcc \
155     git \
156     iperf3 \
157     iproute2 \
158     ethtool \
159     linux-tools-common \
160     linux-tools-generic \
161     lmbench \
162     make \
163     netperf \
164     patch \
165     perl \
166     rt-tests \
167     stress \
168     sysstat \
169     linux-headers-"${linuxheadersversion}" \
170     libpcap-dev \
171     chpasswd \
172     lua5.2
173
174 # Build dpdk vPE VNF
175 pushd .
176 echo "root:root" | chpasswd
177 enable_proxy
178 install_sample_vnf
179 install_trex
180 popd .
181 cd /root
182
183 sed -i -e 's/PermitRootLogin without-password/PermitRootLogin yes/g'  /etc/ssh/sshd_config
184 sed -i -e 's/prohibit-password/yes/g' /etc/ssh/sshd_config
185 passwd
186
187 CLONE_DEST=/opt/tempT
188 # remove before cloning
189 rm -rf -- "${CLONE_DEST}"
190 git clone https://github.com/kdlucas/byte-unixbench.git "${CLONE_DEST}"
191 make --directory "${CLONE_DEST}/UnixBench/"
192
193 git clone https://github.com/beefyamoeba5/ramspeed.git "${CLONE_DEST}/RAMspeed"
194 cd "${CLONE_DEST}/RAMspeed/ramspeed-2.6.0"
195 mkdir temp
196 bash build.sh
197
198 git clone https://github.com/beefyamoeba5/cachestat.git "${CLONE_DEST}"/Cachestat
199
200 # restore symlink
201 ln -sfrT /run/resolvconf/resolv.conf /etc/resolv.conf