Skip to content

Commit c2a6380

Browse files
committed
centralised debian mechanism added for service packaging
1 parent 22f7c88 commit c2a6380

File tree

4 files changed

+256
-0
lines changed

4 files changed

+256
-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/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

service/packages/DEBIAN/control

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Package: __NAME__
2+
Version: __VERSION__
3+
Section: devel
4+
Priority: optional
5+
Architecture: __ARCH__
6+
Depends: __REQUIRES__
7+
Conflicts:
8+
Maintainer: Dianomic Systems, Inc. <[email protected]>
9+
Homepage: http://www.dianomic.com
10+
Description: __DESCRIPTION__

service/packages/DEBIAN/postinst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
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+
##--------------------------------------------------------------------
20+
##
21+
## @postinst DEBIAN/postinst
22+
## This script is used to execute post installation tasks.
23+
##
24+
## Author: Ashish Jabble
25+
##
26+
##--------------------------------------------------------------------
27+
28+
set -e
29+
30+
set_files_ownership () {
31+
chown -R root:root "/usr/local/foglamp/__INSTALL_DIR__"
32+
}
33+
34+
set_files_ownership

0 commit comments

Comments
 (0)