Chetan Gaonker | cc19ac4 | 2016-05-04 17:21:50 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 2 | |
| 3 | function usage { |
| 4 | echo "usage: ${0#*/} [-h |--help] [--cord] [--venv]" |
| 5 | exit 1 |
| 6 | } |
| 7 | |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 8 | on_cord=0 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 9 | venv=0 |
| 10 | optspec=":h-:" |
| 11 | while getopts "$optspec" optchar; do |
| 12 | case "${optchar}" in |
| 13 | -) |
| 14 | case "${OPTARG}" in |
| 15 | cord) |
| 16 | on_cord=1 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 17 | ;; |
| 18 | venv) |
| 19 | venv=1 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 20 | ;; |
| 21 | help) |
| 22 | usage |
| 23 | ;; |
| 24 | *) |
| 25 | echo "Unknown option --${OPTARG}" |
| 26 | usage |
| 27 | ;; |
| 28 | esac |
| 29 | ;; |
| 30 | h) |
| 31 | usage |
| 32 | ;; |
| 33 | *) |
| 34 | usage |
| 35 | ;; |
| 36 | esac |
| 37 | done |
| 38 | |
| 39 | shift $((OPTIND-1)) |
| 40 | if [ $# -gt 0 ]; then |
| 41 | usage |
Chetan Gaonker | cc19ac4 | 2016-05-04 17:21:50 -0700 | [diff] [blame] | 42 | fi |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 43 | |
| 44 | apt-get update |
| 45 | release=$(lsb_release -cs) |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 46 | if [ $on_cord -eq 0 ]; then |
| 47 | apt-get -y install apt-transport-https ca-certificates |
| 48 | apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D |
| 49 | if [ ! -f /etc/apt/sources.list.d/docker.list ]; then |
A R Karthick | bd82f36 | 2016-11-10 15:08:52 -0800 | [diff] [blame] | 50 | echo deb https://apt.dockerproject.org/repo ubuntu-$release main | tee /etc/apt/sources.list.d/docker.list |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 51 | fi |
| 52 | apt-get update |
| 53 | apt-get purge lxc-docker || true |
| 54 | apt-get -y install linux-image-extra-$(uname -r) |
| 55 | apt-get -y install apparmor |
| 56 | echo "Installing Docker" |
| 57 | apt-get -y install docker-engine |
A R Karthick | c4108fe | 2016-11-17 15:15:28 -0800 | [diff] [blame] | 58 | service docker restart |
A R Karthick | 973010f | 2017-02-06 16:41:51 -0800 | [diff] [blame] | 59 | sleep 5 |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 60 | echo "Verifying Docker installation" |
| 61 | docker run --rm hello-world || exit 127 |
| 62 | docker rmi hello-world |
A R Karthick | b05acab | 2016-11-10 15:12:43 -0800 | [diff] [blame] | 63 | echo "Pulling ONOS latest" |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 64 | docker pull onosproject/onos:latest || exit 127 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 65 | else |
| 66 | echo "Skipping installation of Docker and ONOS" |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 67 | fi |
A R Karthick | 05e85fa | 2016-12-02 09:20:54 -0800 | [diff] [blame] | 68 | |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 69 | apt-get -y install openvswitch-common openvswitch-switch |
| 70 | apt-get -y install wget git python python-dev python-pip python-setuptools python-scapy python-pexpect python-maas-client tcpdump arping libssl-dev libffi-dev realpath python-virtualenv |
| 71 | |
| 72 | setup_path=$(dirname $(realpath $0)) |
| 73 | if [ $venv -eq 1 ]; then |
| 74 | echo "Making a virtual cord-tester pip installation environment" |
| 75 | mkdir -p $setup_path/venv |
A R Karthick | d7f6ade | 2017-02-08 12:23:58 -0800 | [diff] [blame] | 76 | virtualenv $setup_path/venv |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 77 | echo "Installing cord-tester pip packages on the virtual environment" |
| 78 | $setup_path/venv/bin/pip install -r $setup_path/requirements.txt |
| 79 | else |
| 80 | echo "Installing cord-tester pip packages on the host" |
| 81 | pip install -r $setup_path/requirements.txt |
Chetan Gaonker | 66bff93 | 2016-05-09 10:06:37 -0700 | [diff] [blame] | 82 | fi |
A R Karthick | 05e85fa | 2016-12-02 09:20:54 -0800 | [diff] [blame] | 83 | |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 84 | ( cd /tmp && git clone https://github.com/jpetazzo/pipework.git && cp -v pipework/pipework /usr/bin && rm -rf pipework ) |
| 85 | |
A R Karthick | 05e85fa | 2016-12-02 09:20:54 -0800 | [diff] [blame] | 86 | install_ovs() { |
| 87 | mkdir -p /root/ovs |
| 88 | wget http://openvswitch.org/releases/openvswitch-2.5.0.tar.gz -O /root/ovs/openvswitch-2.5.0.tar.gz && \ |
| 89 | ( cd /root/ovs && tar zxpvf openvswitch-2.5.0.tar.gz && \ |
| 90 | cd openvswitch-2.5.0 && \ |
| 91 | ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && make && make install |
| 92 | ) |
| 93 | } |
| 94 | |
| 95 | ovs_install=0 |
| 96 | |
| 97 | if [ -f /usr/bin/ovs-vsctl ] || [ -f /usr/local/bin/ovs-vsctl ]; then |
| 98 | ##find the version. Install if ovs version less than 2.5 |
| 99 | version=`sudo ovs-vsctl --version | head -1 | awk '/[1-9].[0-9].[0-9]/ {print $NF}'` |
| 100 | major=$(echo $version | cut -d "." -f1) |
| 101 | minor=$(echo $version | cut -d "." -f2) |
| 102 | if [ $major -le 2 ]; then |
| 103 | if [ $major -lt 2 ]; then |
| 104 | ovs_install=1 |
| 105 | else |
| 106 | if [ $minor -lt 5 ]; then |
| 107 | ovs_install=1 |
| 108 | fi |
| 109 | fi |
| 110 | fi |
| 111 | else |
| 112 | ovs_install=1 |
| 113 | fi |
| 114 | |
| 115 | if [ $ovs_install -eq 1 ]; then |
| 116 | echo "Installing OVS 2.5.0" |
| 117 | service openvswitch-switch stop |
| 118 | install_ovs |
| 119 | fi |