-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·137 lines (123 loc) · 3.95 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# Copyright (c) 2014 Mellanox Technologies. All rights reserved.
#
# This Software is licensed under one of the following licenses:
#
# 1) under the terms of the "Common Public License 1.0" a copy of which is
# available from the Open Source Initiative, see
# http://www.opensource.org/licenses/cpl.php.
#
# 2) under the terms of the "The BSD License" a copy of which is
# available from the Open Source Initiative, see
# http://www.opensource.org/licenses/bsd-license.php.
#
# 3) under the terms of the "GNU General Public License (GPL) Version 2" a
# copy of which is available from the Open Source Initiative, see
# http://www.opensource.org/licenses/gpl-license.php.
#
# Licensee has the right to choose one of the above licenses.
#
# Redistributions of source code must retain the above copyright
# notice and one of the license notices.
#
# Redistributions in binary form must reproduce both the above copyright
# notice, one of the license notices in the documentation
# and/or other materials provided with the distribution.
readonly SUCCESS=0
readonly FAILURE=1
readonly RHEL_DIST="el"
readonly UBUNTU_DIST="ubuntu"
readonly REDHAT_FILE="/etc/redhat-release"
readonly UBUNTU_FIlE="/etc/os-release"
readonly BUILDDIR=/tmp/builddir
readonly PROJECT=eswitchd
readonly BUILD_SRC_DIR=${BUILDDIR}/${PROJECT}
readonly BUILDDIR_REPO=${BUILDDIR}/${REPONAME}
readonly CONFIG_DIR=etc
DIST=""
function deb_cleanup() {
rm -rf etc
rm -rf eswitchd
rm -rf setup.py
}
function check_version_environment() {
if [ -z $ESWITCHD_VERSION ] ; then
echo "missing ESWITCHD_VERSION in environment variable please add it"
exit ${FAILURE}
fi
if [ -z $ESWITCHD_RELEASE ] ; then
echo "missing ESWITCHD_RELEASE in environment variable, please add it"
exit ${FAILURE}
fi
}
function check_dist() {
if [ -f ${REDHAT_FILE} ]; then
DIST=${RHEL_DIST}
elif [ -f ${UBUNTU_FIlE} ]; then
DIST=${UBUNTU_DIST}
else
echo "eswitchd Support only CentOS and Ubuntu"
exit ${FAILURE}
fi
}
function build_rpm(){
rm -rf ${BUILDDIR}
mkdir -p ${BUILDDIR}
mkdir -p /root/rpmbuild/SOURCES
mkdir -p ${BUILD_SRC_DIR}
cp -a ${CONFIG_DIR} ${BUILD_SRC_DIR}
cp -a ${PROJECT} ${BUILD_SRC_DIR}
cp setup.py setup.cfg README.rst ${BUILD_SRC_DIR}
cp -R .git ${BUILD_SRC_DIR}
pushd ./
cd ${BUILDDIR};tar zcvf ${PROJECT}-${ESWITCHD_VERSION}.tar.gz ${PROJECT}
cp ${PROJECT}-${ESWITCHD_VERSION}.tar.gz ~/rpmbuild/SOURCES
popd
rpmbuild -ba --define "_eswitchd_version ${ESWITCHD_VERSION}" --define "_eswitchd_release ${ESWITCHD_RELEASE}" rpm/eswitchd.spec
if [ $? != ${SUCCESS} ] ; then
echo "Failed to build eswitchd rpm"
exit ${FAILURE}
fi
cp /root/rpmbuild/RPMS/noarch/eswitchd-${ESWITCHD_VERSION}-${ESWITCHD_RELEASE}.*.noarch.rpm .
if [ $? != ${SUCCESS} ] ; then
echo "Failed to copy eswitchd rpm"
exit ${FAILURE}
fi
cp /root/rpmbuild/SRPMS/eswitchd-${ESWITCHD_VERSION}-${ESWITCHD_RELEASE}.*.src.rpm .
if [ $? != ${SUCCESS} ] ; then
echo "Failed to copy source eswitchd rpm"
exit ${FAILURE}
fi
}
function update_deb_version(){
sed "s/@@VERSION@@/${ESWITCHD_VERSION}/g;s/@@RELEASE@@/${ESWITCHD_RELEASE}/g" debian/changelog.template > debian/changelog
if [ $? != ${SUCCESS} ] ; then
echo "Failed to update deb version"
deb_cleanup
exit ${FAILURE}
fi
}
function build_deb(){
cd deb
rm -rf etc
rm -rf eswitchd
cp -rf ../etc .
cp -rf ../eswitchd .
cp -rf ../setup.py ../setup.cfg ../README.rst .
update_deb_version
dpkg-buildpackage -tc -uc -us
if [ $? != ${SUCCESS} ] ; then
echo "Failed to build eswitchd deb"
deb_cleanup
exit ${FAILURE}
fi
deb_cleanup
}
check_version_environment
check_dist
if [ $DIST == $RHEL_DIST ]; then
build_rpm
elif [ $DIST == $UBUNTU_DIST ]; then
build_deb
fi
exit ${SUCCESS}