Skip to content

Commit 91a18a1

Browse files
Merge pull request #45 from foglamp/FOGL-2943
Fogl 2943 centralised service packaging for Deb and RPM
2 parents 22f7c88 + 5f976b8 commit 91a18a1

File tree

7 files changed

+664
-0
lines changed

7 files changed

+664
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ packages/Debian/build/
1313

1414
# Archived packages
1515
plugins/archive
16+
service/archive

service/README.rst

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
*****************************
2+
Packaging for FogLAMP Service
3+
*****************************
4+
5+
This directory contains the deb and rpm scripts used to create a FogLAMP service package.
6+
7+
Internal Structure
8+
==================
9+
10+
The directory contains the following set of files:
11+
12+
- Files named with **make_** prefix, such as ``make_deb``, ``make_rpm``, are the shell scripts used to build the package.
13+
- The **packages** folder contains the list package types to build. It contains *DEBIAN* and *RPM*
14+
15+
- Inside the *packages/DEBIAN* folder, which contains all the Debian-based files, i.e. control, postinst, needed for the creation of the package.
16+
17+
- In the *archive/DEBIAN/architecture_name* folder which contains the build package.
18+
19+
- Inside the *packages/RPM/SPECS* folder, which contains RPM spec-based file, i.e. service.spec needed for the creation of the package.
20+
21+
- In the *archive/Rpm/architecture_name* folder which contains the build package.
22+
23+
24+
The make_deb Script
25+
===================
26+
27+
.. code-block:: console
28+
29+
$ ./make_deb -h
30+
make_deb [-h] [-a] [-b <branch>] repository ...
31+
This script is used to create the Debian package for a FogLAMP service
32+
33+
Arguments:
34+
-h - Display this help text
35+
-a - Remove all the versions
36+
-b - Branch to base package on
37+
$
38+
39+
40+
Building a Debian Package
41+
=========================
42+
43+
First, make sure that FogLAMP_ROOT is set.
44+
Finally, run the ``make_deb`` command:
45+
46+
.. code-block:: console
47+
48+
$ ./make_deb -b develop foglamp-service-notification
49+
Cloning into 'foglamp-service-notification'...
50+
Checking connectivity... done.
51+
The package root directory is : /tmp/foglamp-service-notification
52+
The package build directory is : /tmp/foglamp-service-notification/build
53+
The FogLAMP required version : >=1.6
54+
The architecture is set as : x86_64
55+
The package will be built in : /home/foglamp/Development/foglamp-pkg/service/archive/DEBIAN/x86_64
56+
The package name is : foglamp-service-notification-1.6.0-x86_64
57+
58+
Populating the package and updating version file...Done.
59+
Building the package...
60+
dpkg-deb: building package 'foglamp-service-notification' in 'foglamp-service-notification-1.6.0-x86_64.deb'.
61+
Building Complete.
62+
$
63+
64+
The result will be:
65+
66+
.. code-block:: console
67+
68+
$ ls -l archive/DEBIAN/x86_64/
69+
total 8
70+
drwxrwxr-x 4 foglamp foglamp 4096 foglamp-service-notification-1.6.0-x86_64
71+
-rw-r--r-- 1 foglamp foglamp 3338 foglamp-service-notification-1.6.0-x86_64-1.6.0.deb
72+
$
73+
74+
The make_rpm Script
75+
===================
76+
.. code-block:: console
77+
78+
$ ./make_rpm --help
79+
make_rpm [-a] [-c] [-h] [-b <branch>] repository ...
80+
This script is used to create the RPM package for a FogLAMP service
81+
Arguments:
82+
-h - Display this help text
83+
-c - Remove all the old versions saved in format .XXXX
84+
-a - Remove all the versions, including the last one
85+
-b - Branch to base package on
86+
$
87+
88+
Building a RPM Package
89+
======================
90+
91+
First, make sure that FogLAMP_ROOT is set.
92+
Finally, run the ``make_rpm`` command:
93+
94+
.. code-block:: console
95+
96+
$ ./make_rpm -b develop foglamp-service-notification
97+
Cloning into 'foglamp-service-notification'...
98+
Checking connectivity... done.
99+
The package root directory is : /tmp/foglamp-service-notification
100+
The package build directory is : /tmp/foglamp-service-notification/build
101+
The FogLAMP required version : >= 1.6
102+
The FogLAMP service notification version is : 1.6.0
103+
The architecture is set as : x86_64
104+
The package will be built in : /home/foglamp/Development/foglamp-pkg/service/archive/Rpm/
105+
The package name is : foglamp-service-notification-1.6.0
106+
107+
108+
Building the package...
109+
Processing files: foglamp-service-notification-1.6.0-1.x86_64
110+
Checking for unpackaged file(s): /usr/lib/rpm/check-files /tmp/foglamp-service-notification/build/foglamp-service-notification-1.6.0/BUILDROOT/foglamp-service-notification-1.6.0-1.x86_64
111+
Wrote: /tmp/foglamp-service-notification/build/foglamp-service-notification-1.6.0/RPMS/x86_64/foglamp-service-notification-1.6.0-1.x86_64.rpm
112+
Building Complete.
113+
$
114+
115+
The result will be:
116+
117+
.. code-block:: console
118+
119+
$ ls -l archive/Rpm/x86_64
120+
total 12 -rw-rw-r-- 1 foglamp foglamp 11805 foglamp-service-notification-1.6.0-1.x86_64.rpm
121+
$
122+
123+
Cleaning the Package Folder
124+
===========================
125+
126+
Use the ``-a`` option to remove all the packages and the files used to make the package.

service/make_deb

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
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: 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 Debian 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+
73+
while [ "${REPO_NAME}" != "" ]
74+
do
75+
package_manager=deb
76+
architecture=`arch`
77+
PKG_ROOT=`pwd`
78+
archive=${PKG_ROOT}/archive/DEBIAN
79+
install_dir=services
80+
81+
if [ ! -d "${archive}/${architecture}" ]; then
82+
mkdir -p "${archive}/${architecture}"
83+
fi
84+
85+
cd /tmp
86+
if [ -d "${REPO_NAME}" ]; then
87+
echo WARNING: Repository ${REPO_NAME} already exists, using the existing copy
88+
(cd ${REPO_NAME}; git pull; git checkout "${BRANCH_NAME}")
89+
else
90+
git clone -b ${BRANCH_NAME} --single-branch https://github.com/foglamp/${REPO_NAME}.git
91+
fi
92+
93+
GIT_ROOT=/tmp/"${REPO_NAME}"
94+
cd ${GIT_ROOT}
95+
96+
if [ ! -f "${GIT_ROOT}/Package" ]; then
97+
echo Repository ${REPO_NAME} is missing package directive file
98+
rm -rf "${GIT_ROOT}"
99+
exit 1
100+
fi
101+
102+
if [ ! -f "${GIT_ROOT}/Description" ]; then
103+
echo Repository ${REPO_NAME} is missing package description file
104+
rm -rf "${GIT_ROOT}"
105+
exit 1
106+
fi
107+
108+
. "${GIT_ROOT}"/Package
109+
pkg_name="${REPO_NAME}"
110+
111+
if [ -f "${GIT_ROOT}/VERSION" ]; then
112+
version=`cat ${GIT_ROOT}/VERSION | tr -d ' ' | grep 'notification_version' | head -1 | sed -e 's/\(.*\)version=\(.*\)/\2/g'`
113+
foglamp_version=`cat ${GIT_ROOT}/VERSION | tr -d ' ' | grep 'foglamp_version' | head -1 | sed -e 's/\(.*\)version\(.*\)/\2/g'`
114+
else
115+
echo Unable to determine version of package to create
116+
rm -rf "${GIT_ROOT}"
117+
exit 1
118+
fi
119+
120+
BUILD_ROOT="${GIT_ROOT}/build"
121+
if [ "${package_name}" ]; then
122+
pkg_name=${package_name}
123+
else
124+
pkg_name="foglamp-service-${service_name}"
125+
fi
126+
# Final package name
127+
archname=$(dpkg --print-architecture)
128+
package_name="${pkg_name}-${version}-${architecture}"
129+
130+
# Print the summary of findings
131+
echo "The package root directory is : ${GIT_ROOT}"
132+
echo "The package build directory is : ${BUILD_ROOT}"
133+
echo "The FogLAMP required version : ${foglamp_version}"
134+
echo "The architecture is set as : ${architecture}"
135+
echo "The package will be built in : ${archive}/${architecture}"
136+
echo "The package name is : ${package_name}"
137+
echo
138+
139+
# Create the package directory. If a directory with the same name exists,
140+
# it is copied with a version number.
141+
142+
# First, create the BUILD_ROOT folder, if necessary
143+
if [ ! -L "${BUILD_ROOT}" -a ! -d "${BUILD_ROOT}" ]; then
144+
mkdir -p "${BUILD_ROOT}"
145+
fi
146+
147+
148+
# Check if the default directory exists
149+
if [[ ! -d "${FOGLAMP_ROOT}" ]]; then
150+
logger -p local0.err -t "foglamp.script.foglamp" "FogLAMP cannot be executed: ${FOGLAMP_ROOT} is not a valid directory."
151+
echo "FogLAMP cannot be executed: ${FOGLAMP_ROOT} is not a valid directory."
152+
echo "Create the enviroment variable FOGLAMP_ROOT before using FogLAMP."
153+
echo "Specify the base directory for FogLAMP and set the variable with:"
154+
echo "export FOGLAMP_ROOT=<basedir>"
155+
exit 1
156+
fi
157+
158+
# Check/set LD_LIBRARY_PATH
159+
libPathSet=0
160+
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
161+
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
162+
[ "$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
163+
164+
# Make service
165+
rm -rf build; mkdir ./build; cd ./build; cmake ..; make; cd ..
166+
167+
if [ -d "${BUILD_ROOT}/${package_name}" ]; then
168+
rm -rf ${BUILD_ROOT}/${pkg_name}*
169+
fi
170+
cd "${BUILD_ROOT}"
171+
mkdir "${package_name}"
172+
173+
# Populate the package directory with Debian files
174+
# First with files common to all pla
175+
echo -n "Populating the package and updating version file..."
176+
cd "${package_name}"
177+
mkdir DEBIAN
178+
deb_path=${BUILD_ROOT}/${package_name}/DEBIAN
179+
cp -R ${PKG_ROOT}/packages/DEBIAN/* ${deb_path}
180+
sed -i "s/__VERSION__/${version}/g" ${deb_path}/control
181+
sed -i "s/__NAME__/${pkg_name}/g" ${deb_path}/control
182+
sed -i "s/__ARCH__/${archname}/g" ${deb_path}/control
183+
sed -i "s/__REQUIRES__/${requirements}/g" ${deb_path}/control
184+
sed -i "s/foglamp,/foglamp (${foglamp_version}),/" ${deb_path}/control
185+
sed -i "s/foglamp$/foglamp (${foglamp_version})/" ${deb_path}/control
186+
desc=`cat "${GIT_ROOT}/Description"`
187+
sed -i "s/__DESCRIPTION__/${desc}/g" ${deb_path}/control
188+
sed -i "s|__INSTALL_DIR__|${install_dir}|g" ${deb_path}/postinst
189+
190+
# Debian file structure
191+
mkdir -p usr/local/foglamp
192+
cd usr/local/foglamp
193+
mkdir -p ${install_dir}
194+
cp "${GIT_ROOT}/build/C/${install_dir}/${service_name}/${exec_name}" "${install_dir}/${exec_name}"
195+
echo "Done."
196+
197+
# Build the package
198+
cd "${BUILD_ROOT}"
199+
echo "Building the package..."
200+
dpkg-deb --build ${package_name}
201+
echo "Building Complete."
202+
203+
# Move final package to archive directory
204+
cp ${BUILD_ROOT}/${package_name}.deb ${archive}/${architecture}
205+
cp -R ${BUILD_ROOT}/${package_name} ${archive}/${architecture}
206+
207+
rm -rf /tmp/${REPO_NAME}
208+
209+
exit 0
210+
done
211+
exit 0

0 commit comments

Comments
 (0)