AHelsing/Scratch: ctrl-setup.sh

File ctrl-setup.sh, 6.5 KB (added by Aaron Helsinger, 9 years ago)
Line 
1#!/bin/sh
2#----------------------------------------------------------------------
3# Copyright (c) 2015  Raytheon BBN Technologies
4#
5# Permission is hereby granted, free of charge, to any person obtaining
6# a copy of this software and/or hardware specification (the "Work") to
7# deal in the Work without restriction, including without limitation the
8# rights to use, copy, modify, merge, publish, distribute, sublicense,
9# and/or sell copies of the Work, and to permit persons to whom the Work
10# is furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be
13# included in all copies or substantial portions of the Work.
14#
15# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
22# IN THE WORK.
23#----------------------------------------------------------------------
24#
25# UNCLASSIFIED // FOUO
26#
27#----------------------------------------------------------------------
28
29
30# Script to set up a Ryu controller with a mongoDB client on CentOS, avoiding redoing things
31# Note that it only grabs the Ryu source if run directly by a user (not from a GENI install script)
32
33# FIXME: Failing from install script
34
35# Go to a directory where we can download things
36user="`whoami`"
37if [ -e "/users/$user" ]
38then
39    echo " ** Running as regular user $user"
40    cd
41else
42    echo " ** Running as install script user"
43    cd /local
44fi
45
46# Bail if we've already run
47if [ -f "./installed.txt" ]
48then
49    echo " ** Already installed"
50    exit
51fi
52
53/usr/bin/sudo /bin/touch "./installed.txt"
54
55# Update centos
56# FIXME: Updates to CentOS2.6 - do we need to hold at 2.5?
57/bin/echo " ** Update CentOS...."
58/usr/bin/sudo /usr/bin/yum -y update & EPID=$!
59wait $EPID
60
61/usr/bin/yum -q grouplist installed "development tools" > /dev/null 2>&1
62isinstalled=$?
63if [ $isinstalled -eq 1 ]
64then
65    /usr/bin/sudo /usr/bin/yum groupinstall -y 'development tools' & EPID=$!
66    wait $EPID
67fi
68
69/usr/bin/yum -q list installed wget > /dev/null 2>&1
70isinstalled=$?
71if [ $isinstalled -eq 1 ]
72   then
73   /usr/bin/sudo /usr/bin/yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget & EPID=$!
74   wait $EPID
75fi
76
77if [ ! -f "/usr/local/bin/python2.7" ]
78then
79    # Build python
80    /bin/echo "*****************************************"
81    /bin/echo "Build Python...."
82    /usr/bin/wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz & EPID=$!
83    wait $EPID
84    /usr/bin/xz -d Python-2.7.8.tar.xz & EPID=$!
85    wait $EPID
86    /bin/tar -xvf Python-2.7.8.tar & EPID=$!
87    wait $EPID
88    cd Python-2.7.8
89    /usr/bin/sudo ./configure --prefix=/usr/local & EPID=$!
90    wait $EPID
91    /usr/bin/sudo /usr/bin/make && /usr/bin/sudo /usr/bin/make altinstall  & EPID=$!
92    wait $EPID
93else
94    echo " ** Python2.7 already installed"
95fi
96export PATH="/usr/local/bin:$PATH"
97
98if [ ! -f "/usr/local/lib/python2.7/site-packages/setuptools.pth" ]
99then
100    # setuptools
101    /bin/echo "*****************************************"
102    /bin/echo "setuptools...."
103    /usr/bin/wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz & EPID=$!
104    wait $EPID
105    /bin/tar -xvf setuptools-1.4.2.tar.gz & EPID=$!
106    wait $EPID
107    cd setuptools-1.4.2
108    /usr/bin/sudo /usr/local/bin/python2.7 setup.py install & EPID=$!
109    wait $EPID
110else
111    echo " ** setuptools already installed"
112fi
113
114if [ ! -f "/usr/local/bin/pip" ]
115then
116    # pip
117    /bin/echo "*****************************************"
118    /bin/echo "Install pip"
119    /usr/bin/sudo /usr/local/bin/python2.7 ez_setup.py & EPID=$!
120    wait $EPID
121    /usr/bin/sudo /usr/local/bin/python2.7 easy_install.py pip & EPID=$!
122    wait $EPID
123else
124    echo " ** pip already installed"
125fi
126
127/usr/bin/yum -q list installed libxslt > /dev/null 2>&1
128isinstalled=$?
129if [ $isinstalled -eq 1 ]
130then
131    # Ryu dependencies
132    /bin/echo "*****************************************"
133    /bin/echo "Get Ryu dependencies"
134    # First Some extras so we can use pyopenssl since this is python 2.7.8 that misses some SSL fixes
135    /usr/bin/sudo /usr/bin/yum install -y libffi-devel & EPID=$!
136    wait $EPID
137    /usr/bin/sudo /usr/local/bin/pip2.7 install pyopenssl ndg-httpsclient pyasn1 & EPID=$!
138    wait $EPID
139    # Then the things Ryu asked for
140    /usr/bin/sudo /usr/bin/yum -y install libxml2-devel libxslt libxslt-devel & EPID=$!
141    wait $EPID
142    /usr/bin/sudo /usr/bin/yum -y install git & EPID=$!
143    wait $EPID
144    /usr/bin/sudo /usr/local/bin/pip2.7 install msgpack-python oslo.config netaddr lxml ecdsa & EPID=$!
145    wait $EPID
146else
147    echo " ** Ryu dependencies already installed"
148fi
149
150if [ ! -f "/usr/local/bin/ryu" ]
151then
152    # Ryu
153    /bin/echo "*****************************************"
154    /bin/echo "Install Ryu"
155    cd /usr/local/lib/python2.7/site-packages
156    # FIXME: This package doesn't exist it appears
157    if [ -f "/usr/local/lib/python2.7/site-packages/pbr-1.3.0.dist-info" ]
158    then
159        /usr/bin/sudo /bin/mv pbr-1.3.0.dist-info Test_pbr-1.3.0.dist-info
160    fi
161    # FIXME: Install of ryu decides it wants the latest pbr before 2.0 and gets 1.3.0, but something later wants <1.0
162    # So uninstall anything we have so far, install the specific version we want, and then the ryu install works
163    /usr/bin/sudo /usr/local/bin/pip2.7 uninstall -y pbr & EPID=$!
164    wait $EPID
165    /usr/bin/sudo /usr/local/bin/pip2.7 install pbr==0.11.0 & EPID=$!
166    wait $EPID
167    /usr/bin/sudo /usr/local/bin/pip2.7 install ryu & EPID=$!
168    wait $EPID
169else
170    echo " ** Ryu already installed"
171fi
172
173if [ -e "/users/$user" ]
174then
175    if [ ! -e "/users/$user/ryu" ]
176    then
177        # Ryu source
178        /bin/echo "*****************************************"
179        /bin/echo "Get Ryu source"
180        cd
181        /usr/bin/git clone git://github.com/osrg/ryu.git
182    else
183        /bin/echo " ** Ryu source already downloaded"
184    fi
185else
186    echo " ** Running as install script user, so not downloading ryu source."
187fi
188
189/usr/local/bin/python2.7 -c "import pymongo" > /dev/null 2>&1
190isinstalled=$?
191if [ $isinstalled -eq 1 ]
192then
193    # MongoDB client
194    /bin/echo "*****************************************"
195    /bin/echo "Install MongoDB pymongo client"
196    /usr/bin/sudo /usr/local/bin/pip2.7 install pymongo & EPID=$!
197    wait $EPID
198else
199    /bin/echo " ** pymongo already installed"
200fi
201
202/bin/echo " ** Controller node setup with Ryu install done!"