Merge "Fixing branch of libparc and updating centos repositories."
[ci-management.git] / jjb / cicn / build-package.sh
1 #!/bin/bash
2 # basic build script example
3 set -euxo pipefail
4 IFS=$'\n\t'
5
6 APT_PATH=`which apt-get` || true
7 apt_get=${APT_PATH:-"/usr/local/bin/apt-get"}
8
9 # Parameters:
10 # $1 = Distribution [trusty / CentOS]
11 #
12 update_cmake_repo() {
13
14     DISTRIBUTION=$1
15
16     if [ "$DISTRIBUTION" == "trusty" ]; then
17         sudo ${apt_get} install -y --allow-unauthenticated software-properties-common
18         sudo add-apt-repository --yes ppa:george-edison55/cmake-3.x
19     elif [ "$DISTRIBUTION" == "CentOS" ]; then
20         sudo cat << EOF > cmake.repo
21 [cmake-repo]
22 name=Repo for cmake3
23 baseurl=http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64/
24 enabled=1
25 gpgcheck=0
26 EOF
27         sudo cat << EOF > jsoncpp.repo
28 [jsoncp-repo]
29 name=Repo for jsoncpp
30 baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64/
31 enabled=1
32 gpgcheck=0
33 EOF
34         sudo mv cmake.repo /etc/yum.repos.d/cmake.repo
35         sudo mv jsoncpp.repo /etc/yum.repos.d/jsoncpp.repo
36     fi
37 }
38
39 # Parameters:
40 # $1 = Distribution codename
41 #
42 update_qt_repo() {
43     DISTRIBUTION_CODENAME=$1
44
45     if [ "$DISTRIBUTION_CODENAME" != "trusty" ] && [ "$DISTRIBUTION_CODENAME" != "xenial" ]; then
46         echo "No valid distribution specified when calling 'update_qt_repo'. Exiting.."
47         exit -1
48     fi
49
50     sudo ${apt_get} install -y --allow-unauthenticated software-properties-common
51     sudo add-apt-repository --yes ppa:beineri/opt-qt571-$DISTRIBUTION_CODENAME
52
53     wget -q -O - http://archive.getdeb.net/getdeb-archive.key | sudo apt-key add -
54     sudo sh -c "echo 'deb http://archive.getdeb.net/ubuntu $DISTRIBUTION_CODENAME-getdeb apps' >> /etc/apt/sources.list.d/getdeb.list"
55
56     sudo ${apt_get} update
57 }
58
59 # Parameters:
60 # $1 = Distribution id
61 # $2 = Distribution codename
62 #
63 update_fdio_repo() {
64     DISTRIB_ID=$1
65     DISTRIB_CODENAME=$2
66
67     if ! [ -z ${REPO_NAME} ]; then
68         REPO_CICN_URL="${NEXUSPROXY}/content/repositories/fd.io.${REPO_NAME}"
69         REPO_VPP_URL=""
70
71         if [ "$DISTRIB_ID" == "Ubuntu" ]; then
72
73             if [ "$DISTRIB_CODENAME" == "xenial" ]; then
74                 REPO_VPP_URL="${NEXUSPROXY}/content/repositories/fd.io.stable.1701.ubuntu.xenial.main/"
75             elif [ "$DISTRIB_CODENAME" == "trusty" ]; then
76                 REPO_VPP_URL="${NEXUSPROXY}/content/repositories/fd.io.stable.1701.ubuntu.trusty.main/"
77             else
78                 echo "Distribution $DISTRIB_CODENAME is not supported"
79                 exit -1
80             fi
81
82             echo "deb ${REPO_VPP_URL} ./" | sudo tee /etc/apt/sources.list.d/99fd.io.list
83             echo "deb ${REPO_CICN_URL} ./" | sudo tee /etc/apt/sources.list.d/99fd.io.master.list
84
85         elif [ "$DISTRIB_ID" == "CentOS" ]; then
86             REPO_VPP_URL="${NEXUSPROXY}/content/repositories/fd.io.centos7/"
87                     sudo cat << EOF > fdio.repo
88 [fdio-vpp-master]
89 name=fd.io master branch latest merge
90 baseurl=${REPO_VPP_URL}
91 enabled=1
92 gpgcheck=0
93
94 [fdio-cicn-master]
95 name=fd.io master branch latest merge
96 baseurl=${REPO_CICN_URL}
97 enabled=1
98 gpgcheck=0
99 EOF
100             sudo mv fdio.repo /etc/yum.repos.d/fdio.repo
101         else
102             echo "Distribution $DISTRIB_CODENAME is not supported"
103         fi
104     else
105         exit -1
106     fi
107
108 }
109
110 setup() {
111
112     DISTRIB_ID=$1
113     DISTRIB_CODENAME=$2
114
115     if [ "$DISTRIB_ID" == "Ubuntu" ]; then
116         if [ "$DISTRIB_CODENAME" == "trusty" ]; then
117             update_cmake_repo $DISTRIB_CODENAME
118         fi
119
120         update_fdio_repo $DISTRIB_ID $DISTRIB_CODENAME
121
122         sudo ${apt_get} update || true
123
124     elif [ "$DISTRIB_ID" == "CentOS" ]; then
125         update_cmake_repo $DISTRIB_ID
126         update_fdio_repo $DISTRIB_ID $DISTRIB_CODENAME
127     fi
128 }
129
130 build_package() {
131
132     ARCHITECTURE=`uname -m`
133
134     # Figure out what system we are running on
135     if [ -f /etc/lsb-release ];then
136
137         BUILD_TOOLS="build-essential cmake"
138         LIBSSL_LIBEVENT="libevent-dev libssl-dev"
139         LONGBOW_DEPS=""
140         LIBPARC_DEPS="longbow $LIBSSL_LIBEVENT"
141         LIBCCNX_COMMON_DEPS="$LIBPARC_DEPS libparc"
142         LIBCCNX_TRANSPORT_RTA_DEPS="$LIBCCNX_COMMON_DEPS libccnx-common"
143         LIBCCNX_PORTAL_DEPS="$LIBCCNX_TRANSPORT_RTA_DEPS libccnx-transport-rta"
144         LIBICNET_DEPS="$LIBCCNX_PORTAL_DEPS libboost-system-dev"
145         METIS_DEPS="$LIBCCNX_TRANSPORT_RTA_DEPS libccnx-transport-rta"
146         HTTP_SERVER_DEPS="$LIBICNET_DEPS libicnet libboost-regex-dev libboost-filesystem-dev"
147         VPP_PLUGIN_DEPS="vpp-dev vpp-dpdk-dev"
148
149         . /etc/lsb-release
150         DEB=ON
151         RPM=OFF
152
153         if [ "$ARCHITECTURE" == "x86_64" ]; then
154             ARCHITECTURE="amd64"
155         fi
156
157     elif [ -f /etc/redhat-release ];then
158
159         BUILD_TOOLS_GROUP="'Development Tools'"
160         BUILD_TOOLS_SINGLE="cmake"
161         LIBSSL_LIBEVENT="libevent-devel openssl-devel"
162         LONGBOW_DEPS=""
163         LIBPARC_DEPS="longbow $LIBSSL_LIBEVENT"
164         LIBCCNX_COMMON_DEPS="$LIBPARC_DEPS libparc"
165         LIBCCNX_TRANSPORT_RTA_DEPS="$LIBCCNX_COMMON_DEPS libccnx-common"
166         LIBCCNX_PORTAL_DEPS="$LIBCCNX_TRANSPORT_RTA_DEPS libccnx-transport-rta"
167         LIBICNET_DEPS="$LIBCCNX_PORTAL_DEPS boost-devel"
168         METIS_DEPS="$LIBCCNX_TRANSPORT_RTA_DEPS libccnx-transport-rta"
169         HTTP_SERVER_DEPS="$LIBICNET_DEPS libicnet boost-devel"
170
171         sudo yum install -y redhat-lsb
172         DISTRIB_ID=`lsb_release -si`
173         DISTRIB_RELEASE=`lsb_release -sr`
174         DISTRIB_CODENAME=`lsb_release -sc`
175         DISTRIB_DESCRIPTION=`lsb_release -sd`
176
177         DEB=OFF
178         RPM=ON
179     else
180         echo "ERROR: System configuration not recognized. Build failed"
181         exit -1
182     fi
183
184     echo ARCHITECTURE: $ARCHITECTURE
185     echo DISTRIB_ID: $DISTRIB_ID
186     echo DISTRIB_RELEASE: $DISTRIB_RELEASE
187     echo DISTRIB_CODENAME: $DISTRIB_CODENAME
188     echo DISTRIB_DESCRIPTION: $DISTRIB_DESCRIPTION
189
190     setup $DISTRIB_ID $DISTRIB_CODENAME
191
192     if [ $DISTRIB_ID == "Ubuntu" ]; then
193         echo $BUILD_TOOLS ${!PACKAGE_DEPS} | xargs sudo ${apt_get} install -y --allow-unauthenticated
194     elif [ $DISTRIB_ID == "CentOS" ]; then
195         echo $BUILD_TOOLS_GROUP | xargs sudo yum groupinstall -y --nogpgcheck || true
196         echo $BUILD_TOOLS_SINGLE | xargs sudo yum install -y --nogpgcheck || true
197         echo ${!PACKAGE_DEPS} | xargs sudo yum install -y --nogpgcheck || true
198     fi
199
200     # do nothing but print the current slave hostname
201     hostname
202
203     # Install package dependencies
204
205     export CCACHE_DIR=/tmp/ccache
206     if [ -d $CCACHE_DIR ];then
207         echo $CCACHE_DIR exists
208         du -sk $CCACHE_DIR
209     else
210         echo $CCACHE_DIR does not exist.  This must be a new slave.
211     fi
212
213     echo "cat /etc/bootstrap.sha"
214     if [ -f /etc/bootstrap.sha ];then
215         cat /etc/bootstrap.sha
216     else
217         echo "Cannot find cat /etc/bootstrap.sha"
218     fi
219
220     echo "cat /etc/bootstrap-functions.sha"
221     if [ -f /etc/bootstrap-functions.sha ];then
222         cat /etc/bootstrap-functions.sha
223     else
224         echo "Cannot find cat /etc/bootstrap-functions.sha"
225     fi
226
227     # Make the package
228     mkdir -p build && pushd build
229
230     rm -rf *
231     cmake -DCMAKE_INSTALL_PREFIX=/usr -DRPM_PACKAGE=$RPM -DDEB_PACKAGE=$DEB -DDISTRIBUTION=$DISTRIB_CODENAME -DARCHITECTURE=$ARCHITECTURE ..
232     make package
233
234     popd
235
236     echo "*******************************************************************"
237     echo "* $PACKAGE_NAME BUILD SUCCESSFULLY COMPLETED"
238     echo "*******************************************************************"
239
240     exit 0
241 }