blob: 67b5625afaa46a28d5be84a15adbe8ed87205c08 [file] [log] [blame]
Hari Krishna74489792015-07-30 10:07:15 -07001#!/usr/bin/env bash
2
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003# Copyright 2015 Open Networking Foundation (ONF)
4#
5# Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
6# the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
7# or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
8#
9# TestON is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 2 of the License, or
12# (at your option) any later version.
13#
14# TestON is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with TestON. If not, see <http://www.gnu.org/licenses/>.
21
Hari Krishna74489792015-07-30 10:07:15 -070022# TestON install script for Ubuntu (Debian and Fedora)
23
24# Fail on error
25set -e
26
27# Fail on unset var usage
28set -o nounset
29
Jon Hall9e8c7612016-07-18 17:40:06 -070030function init {
31 # Identify Linux release
32 DIST=Unknown
33 RELEASE=Unknown
34 CODENAME=Unknown
Hari Krishna74489792015-07-30 10:07:15 -070035
Jon Hall9e8c7612016-07-18 17:40:06 -070036 ARCH=`uname -m`
37 if [ "$ARCH" = "x86_64" ]; then ARCH="amd64"; fi
38 if [ "$ARCH" = "i686" ]; then ARCH="i386"; fi
Hari Krishna74489792015-07-30 10:07:15 -070039
Jon Hall9e8c7612016-07-18 17:40:06 -070040 if [ -e /etc/debian_version ]; then DIST="Debian"; fi
41 if [ -e /etc/fedora-release ]; then DIST="Debian"; fi
42 grep Ubuntu /etc/lsb-release &> /dev/null && DIST="Ubuntu"
Hari Krishna74489792015-07-30 10:07:15 -070043
Jon Hall9e8c7612016-07-18 17:40:06 -070044 if [ "$DIST" = "Ubuntu" ] || [ "$DIST" = "Debian" ]; then
45 install='sudo apt-get -y install'
46 remove='sudo apt-get -y remove'
47 pipinstall='sudo pip install'
48 # Prereqs for this script
49 if ! which lsb_release &> /dev/null; then
50 $install lsb-release
51 fi
Hari Krishna74489792015-07-30 10:07:15 -070052 fi
Hari Krishna74489792015-07-30 10:07:15 -070053
Jon Hall9e8c7612016-07-18 17:40:06 -070054 if [ "$DIST" = "Fedora" ]; then
55 install='sudo yum -y install'
56 remove='sudo yum -y erase'
57 pipinstall='sudo pip install'
58 # Prereqs for this script
59 if ! which lsb_release &> /dev/null; then
60 $install redhat-lsb-core
61 fi
Hari Krishna74489792015-07-30 10:07:15 -070062 fi
Jon Hall9e8c7612016-07-18 17:40:06 -070063 if which lsb_release &> /dev/null; then
64 DIST=`lsb_release -is`
65 RELEASE=`lsb_release -rs`
66 CODENAME=`lsb_release -cs`
67 fi
68 echo "Detected Linux distribution: $DIST $RELEASE $CODENAME $ARCH"
Hari Krishna74489792015-07-30 10:07:15 -070069
Jon Hall9e8c7612016-07-18 17:40:06 -070070 if ! echo $DIST | egrep 'Ubuntu|Debian|Fedora'; then
71 echo "Install.sh currently only supports Ubuntu, Debian and Fedora."
72 exit 1
73 fi
Hari Krishna74489792015-07-30 10:07:15 -070074
Jon Hall9e8c7612016-07-18 17:40:06 -070075 #Get location of TestON dir
76 SOURCE="${BASH_SOURCE[0]}"
77 while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
78 DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
79 SOURCE="$(readlink "$SOURCE")"
80 [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
81 done
82 DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
83 echo "Found TestON at $DIR"
84}
Hari Krishna74489792015-07-30 10:07:15 -070085
Jon Hall9e8c7612016-07-18 17:40:06 -070086function requirements {
87 system_reqs
88 python_reqs
89}
90
91function system_reqs {
92 # Specify a specific command with $1
93 set +o nounset
94 if [ -z $1 ]
95 then
96 cmd=$install
97 else
98 cmd=$1
99 fi
100 set -o nounset
101 # Install TestON dependencies
102 echo "Installing TestON dependencies"
103 if [ "$DIST" = "Fedora" ]; then
104 # Fedora may have vlan enabled by default. Still need to confirm and update later
Devin Lim1dd79312017-06-13 10:54:58 -0700105 $cmd python-pip build-essential python-dev pep8 python3-requests
Jon Hall9e8c7612016-07-18 17:40:06 -0700106 else
Devin Lim1dd79312017-06-13 10:54:58 -0700107 $cmd python-pip build-essential python-dev pep8 vlan python3-requests
Jon Hall9e8c7612016-07-18 17:40:06 -0700108 fi
109
110 # Some Distos have this already from another package
111 if which arping > /dev/null ; then
112 echo "Arping command detected, skipping package installation."
113 else
114 $cmd arping
115 fi
116}
117
118function python_reqs {
119 # Specify a specific pip command with $1
120 set +o nounset
121 if [ -z $1 ]
122 then
123 cmd=$pipinstall
124 else
125 cmd=$1' install'
126 fi
127 set -o nounset
128 $cmd -r requirements.txt
129}
130
Jon Hall4b202c52018-01-22 13:50:01 -0800131function jenkins_req {
132 set +o nounset
133 if [ -z $1 ]
134 then
135 dir='/var/jenkins'
136 else
137 dir=$1
138 fi
139 set -o nounset
140 # make sure default jenkin's directory exists and is owned by current user?
141 set +e
142 sudo mkdir $dir
143 set -e
144 sudo chown $USER:$USER $dir
145 # Postgresql for storing results in the db
146 echo "Installing dependencies required for Jenkins test-station"
147 $install postgresql postgresql-contrib
148 # R for generating graphs for the wiki summary
149 $install r-base-core libpq-dev
150 echo 'cat(".Rprofile: Setting UK repository"); r = getOption("repos"); r["CRAN"] = "http://cran.uk.r-project.org"; options(repos = r); rm(r)' > ~/.Rprofile
151 sudo R -e 'install.packages( c( "ggplot2", "reshape2", "RPostgreSQL" ) )'
152}
Jon Hall9e8c7612016-07-18 17:40:06 -0700153function symlinks {
154 set +e
155 # Add symbolic link to main TestON folder in Home dir
156 pushd ~
157 sudo ln -s $DIR && echo "Added symbolic link to TestON folder in HOME directory."
158 popd
159
160 # Add symbolic link to TestON cli in /usr/local/bin
161 pushd /usr/local/bin
162 sudo ln -s $DIR/bin/cli.py teston && echo "Added symbolic link to TestON CLI in /usr/local/bin."
163 popd
164
165 # Add symlink to get bash completion
166 pushd /etc/bash_completion.d
167 sudo cp $DIR/bin/.teston_completion teston_completion
168 echo "Bash completion will now be enabled for new shells"
169 popd
170 set -e
171}
172
173function git {
174 # OnosSystemTest git pre-commit hooks
175 pushd $DIR/..
176 cp .git/hooks/pre-commit.sample .git/hooks/pre-commit
177 popd
178}
179
180function get_pypy {
181 echo "Getting pypy"
182 pushd ~
183 if [ ! -e pypy2-v5.3.1-linux64.tar.bz2 ]
184 then
185 wget https://bitbucket.org/pypy/pypy/downloads/pypy2-v5.3.1-linux64.tar.bz2
186 fi
187 tar xf pypy2-v5.3.1-linux64.tar.bz2
188 python_impl=~/pypy2-v5.3.1-linux64/bin/pypy
189 popd
190 venv $python_impl "venv-teston-pypy"
191}
192
193# Optionally install in virtual env
194function venv {
195 # $1 is the path to python implementation, $2 is the venv-name
196 echo "Installing virtual env for TestON..."
197 pushd $DIR
198 set +o nounset
199 if [ -z "$2" ]
200 then
201 venv_name="venv-teston"
202 else
203 venv_name=$2
204 fi
205 pip install virtualenv
206
207 # Setup virtual env
208 if [ -z "$1" ]; then
209 echo "No python implementation specified for virtual env, using default."
210 virtualenv $venv_name
211 else
212 python_impl=$1
213 echo "Using $python_impl for python in virtual env."
214 virtualenv -p $python_impl $venv_name
215 fi
216 python_reqs $venv_name/bin/pip
217 set -o nounset
218 popd
219}
220
221
222function default {
223 requirements
224 symlinks
225 git
226}
227
228function finished {
229 echo ""
230 echo "Completed running install.sh script"
231 echo "Run TestON CLI by typing teston at bash prompt"
232 echo "Example: teston run <TestSuite Name>"
233}
234
235# TODO Add log rotation configuration for TestON logs here (place holder)
236# TODO Add bash tab completion script to this
237
238function usage {
Jon Hall4b202c52018-01-22 13:50:01 -0800239 printf "Usage: $(basename $0) [-dgjprsv] \n"
Jon Hall9e8c7612016-07-18 17:40:06 -0700240 printf "Usage: $(basename $0) -y [PATH] \n\n"
241 printf "This install script attempts to install deoendencies needed to run teston\n"
242 printf "and any tests included in the official repository. If a test still does \n"
243 printf "not run after running this script, you can try looking at the test's README\n"
244 printf "or the driver files used by the tests. There are some software components\n"
245 printf "such as software switches that this script does not attempt to install as\n"
246 printf "they are more complicated.\n\n"
247
248 printf "Options:\n"
249 printf "\t -d (default) requirements, symlinks and git hooks\n"
250 printf "\t -g install git hooks\n"
Jon Hall4b202c52018-01-22 13:50:01 -0800251 printf "\t -j install requirments for running this node as a Jenkin's test-station\n"
Jon Hall9e8c7612016-07-18 17:40:06 -0700252 printf "\t -p install pypy in a virtual env\n"
253 printf "\t -r install requirements for TestON/tests\n"
254 printf "\t -s install symlinks\n"
255 printf "\t -v install a python virtual environment for teston using the default python implementation\n"
Jon Hall4b202c52018-01-22 13:50:01 -0800256 printf "\t -y <PATH> install a python virtual environment for teston using a specific python implementation at PATH.\n"
Jon Hall9e8c7612016-07-18 17:40:06 -0700257
258}
259
260if [ $# -eq 0 ]
261then
Jon Hallfa9973a2016-09-23 10:41:59 -0700262 init
Jon Hall9e8c7612016-07-18 17:40:06 -0700263 default
264elif [ $1 == "--help" ]
265then
266 usage
Hari Krishna74489792015-07-30 10:07:15 -0700267else
Jon Hall9e8c7612016-07-18 17:40:06 -0700268 init
Jon Hall4b202c52018-01-22 13:50:01 -0800269 while getopts 'dgjprsvy:' OPTION
Jon Hall9e8c7612016-07-18 17:40:06 -0700270 do
271 case $OPTION in
272 d) default;;
273 g) git;;
Jon Hall4b202c52018-01-22 13:50:01 -0800274 j) jenkins_req;;
Jon Hall9e8c7612016-07-18 17:40:06 -0700275 p) get_pypy;;
276 r) requirements;;
277 s) symlinks;;
278 v) venv;;
Jon Hall4b202c52018-01-22 13:50:01 -0800279 y) venv $OPTARG;;
Jon Hall9e8c7612016-07-18 17:40:06 -0700280 ?) usage;;
281 esac
282 done
283 shift $(($OPTIND -1))
284 finished
Hari Krishna74489792015-07-30 10:07:15 -0700285fi