d2d944b586d38f7dde15c9455bcee275928babc5
[ci-management.git] / jjb / cicn / build-package.sh
1 #!/bin/bash
2 # basic build script example
3 set -euo pipefail
4 IFS=$'\n\t'
5
6 update_cmake_repo_trusty() {
7     sudo apt-get install -y --allow-unauthenticated software-properties-common
8     sudo add-apt-repository --yes ppa:george-edison55/cmake-3.x
9 }
10
11 update_cmake_repo_centos() {
12     sudo cat << EOF > cmake.repo
13 [cmake-repo]
14 name=Repo for cmake3
15 baseurl=http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64/
16 enabled=1
17 gpgcheck=0
18 EOF
19     sudo cat << EOF > jsoncpp.repo
20 [jsoncp-repo]
21 name=Repo for jsoncpp
22 baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64/
23 enabled=1
24 gpgcheck=0
25 EOF
26     sudo mv cmake.repo /etc/yum.repos.d/cmake.repo
27     sudo mv jsoncpp.repo /etc/yum.repos.d/jsoncpp.repo
28 }
29
30 setup() {
31
32     DISTRIB_ID=$1
33     DISTRIB_CODENAME=$2
34
35     if ! [ -z ${REPO_NAME} ]; then
36         REPO_URL="${NEXUSPROXY}/content/repositories/fd.io.${REPO_NAME}"
37         echo "REPO_URL: ${REPO_URL}"
38     else
39         exit -1
40     fi
41
42     if [ $DISTRIB_ID == "Ubuntu" ]; then
43         if [ "$DISTRIB_CODENAME" == "trusty" ]; then
44             update_cmake_repo_trusty
45         fi
46
47         echo "deb ${REPO_URL} ./" | sudo tee /etc/apt/sources.list.d/99fd.io.list
48
49         sudo apt-get update
50     elif [ "$DISTRIB_ID" == "CentOS" ]; then
51         update_cmake_repo_centos
52         sudo cat << EOF > fdio-master.repo
53 [fdio-master]
54 name=fd.io master branch latest merge
55 baseurl=${REPO_URL}
56 enabled=1
57 gpgcheck=0
58 EOF
59         sudo mv fdio-master.repo /etc/yum.repos.d/fdio-master.repo
60     fi
61 }
62
63 build_package() {
64
65     ARCHITECTURE=`uname -m`
66
67     # Figure out what system we are running on
68     if [ -f /etc/lsb-release ];then
69         . /etc/lsb-release
70         source ./ubuntu-dependencies
71         DEB=ON
72         RPM=OFF
73
74         if [ "$ARCHITECTURE" == "x86_64" ]; then
75             ARCHITECTURE="amd64"
76         fi
77
78     elif [ -f /etc/redhat-release ];then
79         source ./centos-dependencies
80         sudo yum install -y redhat-lsb
81         DISTRIB_ID=`lsb_release -si`
82         DISTRIB_RELEASE=`lsb_release -sr`
83         DISTRIB_CODENAME=`lsb_release -sc`
84         DISTRIB_DESCRIPTION=`lsb_release -sd`
85
86         DEB=OFF
87         RPM=ON
88     else
89         echo "ERROR: System configuration not recognized. Build failed"
90         exit -1
91     fi
92
93     echo ARCHITECTURE: $ARCHITECTURE
94     echo DISTRIB_ID: $DISTRIB_ID
95     echo DISTRIB_RELEASE: $DISTRIB_RELEASE
96     echo DISTRIB_CODENAME: $DISTRIB_CODENAME
97     echo DISTRIB_DESCRIPTION: $DISTRIB_DESCRIPTION
98
99     setup $DISTRIB_ID $DISTRIB_CODENAME
100
101     if [ $DISTRIB_ID == "Ubuntu" ]; then
102         echo $BUILD_TOOLS ${!PACKAGE_DEPS} | xargs sudo apt-get install -y --allow-unauthenticated
103     elif [ $DISTRIB_ID == "CentOS" ]; then
104         echo $BUILD_TOOLS_GROUP | xargs sudo yum groupinstall -y --nogpgcheck || true
105         echo $BUILD_TOOLS_SINGLE | xargs sudo yum install -y --nogpgcheck || true
106         echo ${!PACKAGE_DEPS} | xargs sudo yum install -y --nogpgcheck || true
107     fi
108
109     # do nothing but print the current slave hostname
110     hostname
111
112     # Install package dependencies
113
114     export CCACHE_DIR=/tmp/ccache
115     if [ -d $CCACHE_DIR ];then
116         echo $CCACHE_DIR exists
117         du -sk $CCACHE_DIR
118     else
119         echo $CCACHE_DIR does not exist.  This must be a new slave.
120     fi
121
122     echo "cat /etc/bootstrap.sha"
123     if [ -f /etc/bootstrap.sha ];then
124         cat /etc/bootstrap.sha
125     else
126         echo "Cannot find cat /etc/bootstrap.sha"
127     fi
128
129     echo "cat /etc/bootstrap-functions.sha"
130     if [ -f /etc/bootstrap-functions.sha ];then
131         cat /etc/bootstrap-functions.sha
132     else
133         echo "Cannot find cat /etc/bootstrap-functions.sha"
134     fi
135
136     echo "sha1sum of this script: ${0}"
137     sha1sum $0
138
139     # Make the package
140     mkdir -p build && pushd build
141
142     rm -rf *
143     cmake -DCMAKE_INSTALL_PREFIX=/usr -DRPM_PACKAGE=$RPM -DDEB_PACKAGE=$DEB -DDISTRIBUTION=$DISTRIB_CODENAME -DARCHITECTURE=$ARCHITECTURE ..
144     make package
145
146     echo "*******************************************************************"
147     echo "* $PACKAGE_NAME BUILD SUCCESSFULLY COMPLETED"
148     echo "*******************************************************************"
149
150     exit 0
151 }