Skip to content

Commit 23440af

Browse files
committed
centralised RPM mechanism added for service packaging
1 parent c2a6380 commit 23440af

File tree

2 files changed

+281
-0
lines changed

2 files changed

+281
-0
lines changed

service/make_rpm

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
#!/bin/bash
2+
3+
##--------------------------------------------------------------------
4+
## Copyright (c) 2019 Dianomic Systems Inc.
5+
##
6+
## Licensed under the Apache License, Version 2.0 (the "License");
7+
## you may not use this file except in compliance with the License.
8+
## You may obtain a copy of the License at
9+
##
10+
## http://www.apache.org/licenses/LICENSE-2.0
11+
##
12+
## Unless required by applicable law or agreed to in writing, software
13+
## distributed under the License is distributed on an "AS IS" BASIS,
14+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
## See the License for the specific language governing permissions and
16+
## limitations under the License.
17+
##--------------------------------------------------------------------
18+
##
19+
## Author: Massimiliano Pinto, Ashish Jabble
20+
##
21+
22+
set -e
23+
24+
# Default branch to package
25+
BRANCH_NAME=master
26+
27+
USAGE="$(basename "$0") [-h] [-a] [-b <branch>] repository ...
28+
This script is used to create the RPM package for a FogLAMP service
29+
30+
Arguments:
31+
-h - Display this help text
32+
-a - Remove all the versions
33+
-b - Branch to base package on"
34+
35+
while getopts ":hab:" opt; do
36+
case "$opt" in
37+
a)
38+
if [ -d "./archive" ]; then
39+
echo -n "Cleaning the package archive folder..."
40+
rm -rf ./archive/*
41+
echo "Done."
42+
else
43+
echo "No archive folder, skipping cleanall"
44+
fi
45+
exit 0
46+
;;
47+
h)
48+
echo "${USAGE}"
49+
exit 0
50+
;;
51+
b)
52+
BRANCH_NAME=$OPTARG
53+
;;
54+
\?)
55+
echo "Invalid option -$OPTARG"
56+
exit 1
57+
;;
58+
:)
59+
echo "-$OPTARG requires an argument"
60+
exit 1
61+
esac
62+
done
63+
shift $((OPTIND -1))
64+
65+
REPO_NAME=$1
66+
67+
if [ "${REPO_NAME}" = "" ]; then
68+
echo You must specify service repository name to package
69+
exit 1
70+
fi
71+
72+
# Check if the default directory exists
73+
echo FOGLAMP_ROOT = ${FOGLAMP_ROOT}
74+
if [ "${FOGLAMP_ROOT}" = "" ]; then
75+
echo "Notification server cannot be compiled: FOGLAMP_ROOT environment variable is not set."
76+
echo "Specify the base directory for FogLAMP and set the variable with:"
77+
echo "export FOGLAMP_ROOT=<basedir>"
78+
exit 1
79+
fi
80+
81+
if [ ! -d "${FOGLAMP_ROOT}" ]; then
82+
echo "Notification server cannot be compiled: ${FOGLAMP_ROOT} is not a valid directory."
83+
echo "Specify the base directory for FogLAMP and set the variable with:"
84+
echo "export FOGLAMP_ROOT=<basedir>"
85+
exit 1
86+
fi
87+
88+
# Check/set LD_LIBRARY_PATH
89+
libPathSet=0
90+
libdir=${FOGLAMP_ROOT}/lib; [ -d ${libdir} ] && LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | sed "s|${libdir}||g") && export LD_LIBRARY_PATH=${libdir}:${LD_LIBRARY_PATH} && libPathSet=1
91+
libdir=${FOGLAMP_ROOT}/cmake_build/C/lib; [ -d ${libdir} ] && LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | sed "s|${libdir}||g") && export LD_LIBRARY_PATH=${libdir}:${LD_LIBRARY_PATH} && libPathSet=1
92+
[ "$libPathSet" -eq "0" ] && echo "Unable to set/update LD_LIBRARY_PATH to include path of Foglamp shared libraries: check whether ${FOGLAMP_ROOT}/lib or ${FOGLAMP_ROOT}/cmake_build/C/lib exists" && exit 1
93+
94+
95+
while [ "${REPO_NAME}" != "" ]
96+
do
97+
98+
package_manager=rpm
99+
arch=`arch`
100+
PKG_ROOT=`pwd`
101+
archive=${PKG_ROOT}/archive/Rpm
102+
install_dir=services
103+
104+
if [ ! -d "${archive}/${arch}" ]; then
105+
mkdir -p "${archive}/$arch"
106+
fi
107+
108+
if [ ! -f packages/RPM/SPECS/service.spec ] ; then
109+
echo You must run this script from the root directory
110+
exit 1
111+
fi
112+
113+
cd /tmp
114+
if [ -d "${REPO_NAME}" ]; then
115+
echo WARNING: Repository ${REPO_NAME} already exists, using the existing copy
116+
(cd ${REPO_NAME}; git pull; git checkout "$branch")
117+
else
118+
git clone -b "$branch" https://github.com/foglamp/${REPO_NAME}.git
119+
fi
120+
121+
GIT_ROOT=/tmp/"${REPO_NAME}"
122+
cd ${GIT_ROOT}
123+
124+
if [ ! -f "${GIT_ROOT}/Package" ]; then
125+
echo "Package file is missing in ${GIT_ROOT}"
126+
rm -rf "${GIT_ROOT}"
127+
exit 1
128+
fi
129+
130+
if [ ! -f "${GIT_ROOT}/Description" ]; then
131+
echo "Description file is missing in ${GIT_ROOT}"
132+
rm -rf "${GIT_ROOT}"
133+
exit 1
134+
fi
135+
136+
. "${GIT_ROOT}"/Package
137+
pkg_name="${REPO_NAME}"
138+
139+
if [ -f "${GIT_ROOT}/VERSION" ]; then
140+
version=`cat "${GIT_ROOT}/VERSION" | tr -d ' ' | grep "notification_version" | head -1 | sed -e 's/\(.*\)version\([>=|>|<|<=|=]*\)\(.*\)/\3/g'`
141+
foglamp_version=`cat ${GIT_ROOT}/VERSION| tr -d ' ' | grep 'foglamp_version' | head -1 | sed -e 's/\(.*\)version\([>=|>|<|<=|=]*\)\(.*\)/\2 \3/g'`
142+
else
143+
echo Unable to determine version of package to create
144+
rm -rf "${GIT_ROOT}"
145+
exit 1
146+
fi
147+
148+
BUILD_ROOT="${GIT_ROOT}/build"
149+
if [ "${package_name}" ]; then
150+
pkg_name=${package_name}
151+
else
152+
pkg_name="foglamp-service-${service_name}"
153+
fi
154+
package_name="${pkg_name}-${version}"
155+
156+
# Print the summary of findings
157+
echo "The package root directory is : ${GIT_ROOT}"
158+
echo "The package build directory is : ${BUILD_ROOT}"
159+
echo "The FogLAMP required version : ${foglamp_version}"
160+
echo "The FogLAMP service ${service_name} version is : ${version}"
161+
echo "The architecture is set as : ${arch}"
162+
echo "The package will be built in : ${archive}/${architecture}"
163+
echo "The package name is : ${package_name}"
164+
echo
165+
166+
# Create the package directory. If a directory with the same name exists,
167+
# it is copied with a version number.
168+
169+
# First, create the BUILD_ROOT folder, if necessary
170+
if [ ! -L "${BUILD_ROOT}" -a ! -d "${BUILD_ROOT}" ]; then
171+
mkdir -p "${BUILD_ROOT}"
172+
fi
173+
174+
cd "${BUILD_ROOT}"
175+
if [ -d "${package_name}" ]; then
176+
rm -rf ${package_name}*
177+
fi
178+
mkdir "${package_name}"
179+
180+
# Populate the package directory with RPM files
181+
echo -n "Populating the package and updating version file..."
182+
cd "${package_name}"
183+
cp -R ${PKG_ROOT}/packages/RPM/* .
184+
sed -i "s/__VERSION__/${version}/g" SPECS/service.spec
185+
sed -i "s/__NAME__/${pkg_name}/g" SPECS/service.spec
186+
sed -i "s/__ARCH__/${arch}/g" SPECS/service.spec
187+
sed -i "s/__PACKAGE_NAME__/${package_name}/g" SPECS/service.spec
188+
sed -i "s|__INSTALL_DIR__|${install_dir}|g" SPECS/service.spec
189+
sed -i "s/__REQUIRES__/${requirements}/g" SPECS/service.spec
190+
sed -i "s/foglamp,/foglamp ${foglamp_version},/" SPECS/service.spec
191+
sed -i "s/foglamp$/foglamp ${foglamp_version}/" SPECS/service.spec
192+
193+
cat > /tmp/sed.script.$$ << EOF
194+
/__DESCRIPTION__/ {
195+
r ${GIT_ROOT}/Description
196+
d
197+
}
198+
EOF
199+
sed -i -f /tmp/sed.script.$$ SPECS/service.spec
200+
rm /tmp/sed.script.$$
201+
202+
mkdir BUILDROOT
203+
cd BUILDROOT
204+
mkdir -p ${package_name}-1.${arch}
205+
cd ${package_name}-1.${arch}
206+
207+
mkdir -p usr/local/foglamp
208+
cd usr/local/foglamp
209+
(cd ${GIT_ROOT};
210+
if [ -f requirements.sh ]; then
211+
./requirements.sh
212+
fi
213+
214+
if [ -f build.sh ]; then
215+
rm -rf build;
216+
./build.sh
217+
else
218+
rm -rf build; mkdir ./build; cd ./build; cmake ..; make
219+
fi)
220+
mkdir -p ${install_dir}
221+
cp -R --preserve=links ${GIT_ROOT}/build/C/${install_dir}/notification/foglamp* "${install_dir}/"
222+
echo "Done."
223+
224+
cd ..
225+
find -L . -type f -exec echo '%{install_path}/'{} \; >> ../../../../SPECS/service.spec
226+
cd "${BUILD_ROOT}"
227+
echo "Building the package..."
228+
rpmbuild --define "_topdir ${BUILD_ROOT}/${package_name}" --noclean -bb ${BUILD_ROOT}/${package_name}/SPECS/service.spec
229+
echo "Building Complete."
230+
231+
# Full Package name
232+
fullname="${package_name}-1.${arch}.rpm"
233+
234+
# Move final package and its spec file to archive/arch directory
235+
cp ${BUILD_ROOT}/${package_name}/RPMS/${arch}/${fullname} ${archive}/${arch}/${fullname}
236+
cp ${BUILD_ROOT}/${package_name}/SPECS/service.spec ${archive}/${arch}
237+
238+
rm -rf /tmp/${REPO_NAME}
239+
exit 0
240+
done
241+
exit 0
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
%define __spec_install_pre /bin/true
2+
3+
Name: __NAME__
4+
Vendor: Dianomic Systems, Inc. <[email protected]>
5+
Version: __VERSION__
6+
Release: 1
7+
BuildArch: __ARCH__
8+
Summary: FogLAMP, the open source platform for the Internet of Things
9+
License: 2019 Dianomic Systems Inc.
10+
Group: IOT
11+
URL: http://www.dianomic.com
12+
13+
%define install_path /usr/local
14+
15+
Prefix: /usr/local
16+
Requires: __REQUIRES__
17+
AutoReqProv: no
18+
19+
20+
%description
21+
__DESCRIPTION__
22+
23+
%pre
24+
25+
%preun
26+
PKG_NAME="__PACKAGE_NAME__"
27+
28+
29+
%post
30+
set -e
31+
set_files_ownership () {
32+
chown -R root:root /usr/local/foglamp/__INSTALL_DIR__
33+
}
34+
35+
# main
36+
echo "Setting ownership of FogLAMP files"
37+
set_files_ownership
38+
39+
40+
%files

0 commit comments

Comments
 (0)