-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmake_deb
More file actions
executable file
·251 lines (221 loc) · 7.98 KB
/
make_deb
File metadata and controls
executable file
·251 lines (221 loc) · 7.98 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/env bash
##--------------------------------------------------------------------
## Copyright (c) 2018 OSIsoft, LLC
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##--------------------------------------------------------------------
##
## Author: Ivan Zoratti, Ashish Jabble
##
set -e
usage="$(basename "$0") [-h] [-c] [-a] [-s] [-b branch]
This script is used to create the Debian package of Fledge.
Options:
-h - Display this help text
-c - Clean old versions, removing packages saved in the format .XXXX (but keep the latest version)
-a - Clean all versions, including the latest one (removes everything in the build directory)
-s - Skip the build process (useful if the build is already done or needs to be skipped for testing)
-b - Specify the branch name to use for the build (required argument following -b)"
PKG_ROOT=$(pwd)
architecture=$(arch)
ARCH_NAME=$(dpkg --print-architecture)
repo_name=fledge
skip_build=0
# Function to check if an option is valid
is_valid_option() {
case "$1" in
-h | -c | -a | -s | -b) return 0 ;; # Valid options
*) return 1 ;; # Invalid option
esac
}
# Parse the options
while [[ $# -gt 0 ]]; do
# Check if the current option is valid using the is_valid_option function
if ! is_valid_option "$1"; then
echo "Unrecognized option: $1"
echo "$usage"
exit 1
fi
case "$1" in
-c) # Option for 'clean'
if [ -d "${PKG_ROOT}/packages/Debian/build" ]; then
echo -n "Cleaning the build folder from older versions..."
find "${PKG_ROOT}/packages/Debian/build/${architecture}" -maxdepth 2 | grep '.*\.[0-9][0-9][0-9][0-9]' | xargs rm -rf
echo "Done."
else
echo "No build folder, skipping clean"
fi
exit 0
;;
-a) # Option for 'cleanall'
echo "Cleaning all..."
if [ -d "${PKG_ROOT}/packages/Debian/build" ]; then
echo -n "Cleaning the build folder..."
rm -rf ${PKG_ROOT}/packages/Debian/build
echo "Done."
else
echo "No build folder, skipping cleanall"
fi
exit 0
;;
-s) # Option for 'skip_build'
skip_build=1
shift
;;
-b) # Option for 'branch'
if [[ -z "$2" || "$2" =~ ^- ]]; then
echo "Option -b requires a branch argument."
echo "$usage"
exit 1
fi
branch=$2
shift 2
;;
-h) # Option for 'help'
echo "$usage"
exit 0
;;
--) # End of options
shift
break
;;
*) # Positional arguments (not options)
break
;;
esac
done
#
# Clones/updates Git repository
#
if [[ $skip_build == 0 ]]; then
cd /tmp
if [ -d "${repo_name}" ]; then
echo WARNING: Repository ${repo_name} already exists, using the existing copy
(cd ${repo_name}; git fetch --all; git pull ; git checkout "$branch")
else
git clone -b "$branch" https://github.com/fledge-iot/${repo_name}.git
fi
GIT_ROOT=/tmp/"${repo_name}"
cd ${GIT_ROOT}
git_tag_info=$(cd ${GIT_ROOT} && git describe --tags) && commit_count=$(echo ${git_tag_info} | cut -d- -f2)
fi
#
# Builds Fledge
#
if [[ $skip_build == 0 ]]; then
cd ${GIT_ROOT}
echo "Git log details for Fledge..."
git --no-pager log -1
if [ "${ARCH_NAME}" = "armhf" ]; then
sudo ./requirements.sh
sed -i 's/python_build python_requirements_user/python_build # python_requirements_user/g' Makefile
sed -i '/python_requirements \\/d' Makefile
fi
echo "install fledge"
if [ "${ARCH_NAME}" = "armhf" ]; then
cd ${GIT_ROOT} && sudo make install USE_PIP_CACHE=yes && export FLEDGE_ROOT=/usr/local/fledge
else
sudo ./requirements.sh
cd ${GIT_ROOT} && sudo make install && export FLEDGE_ROOT=/usr/local/fledge
fi
fi
# Check FLEDGE_ROOT
if [ -z ${FLEDGE_ROOT+x} ]; then
# Set FLEDGE_ROOT as the default directory
if [ -d "/usr/local/fledge" ]; then
FLEDGE_ROOT="/usr/local/fledge"
export FLEDGE_ROOT
else
echo "No FLEDGE_ROOT directory found - Program exit."
exit 1
fi
fi
version=`cat ${FLEDGE_ROOT}/VERSION | tr -d ' ' | grep 'fledge_version=' | head -1 | sed -e 's/\(.*\)=\(.*\)/\2/g'`
BUILD_ROOT="${PKG_ROOT}/packages/Debian/build/${architecture}"
# Final package name
if [[ $skip_build == 0 ]] && ([[ ${branch} != "main" ]] && [[ ! ${branch} =~ ^[0-9]+\.[0-9]+\.[0-9]+RC ]] && [[ ! ${branch} =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]); then package_name="fledge_${version}-${commit_count}_${architecture}"; version=${git_tag_info:1}; else package_name="fledge_${version}_${architecture}"; fi
# Print the summary of findings
echo "The package root directory is : ${PKG_ROOT}"
echo "The Fledge directory is : ${FLEDGE_ROOT}"
echo "The Fledge version is : ${version}"
echo "The package will be built in : ${BUILD_ROOT}"
echo "The architecture is set as : ${architecture}"
echo "The package name is : ${package_name}"
echo
# Create the package directory. If a directory with the same name exists,
# it is copied with a version number.
# First, create the BUILD_ROOT folder, if necessary
if [ ! -L "${BUILD_ROOT}" -a ! -d "${BUILD_ROOT}" ]; then
mkdir -p "${BUILD_ROOT}"
fi
cd "${BUILD_ROOT}"
existing_pkgs=`find . -maxdepth 1 -name "${package_name}.????" | wc -l`
existing_pkgs=$((existing_pkgs+1))
new_stored_pkg=$(printf "${package_name}.%04d" "${existing_pkgs}")
if [ -d "${package_name}" ]; then
echo "Saving the old working environment as ${new_stored_pkg}"
mv "${package_name}" "${new_stored_pkg}"
fi
mkdir "${package_name}"
# Populate the package directory with Debian files
# First with files common to all pla
echo -n "Populating the package and updating version in control file..."
cd "${package_name}"
cp -R ${PKG_ROOT}/packages/Debian/common/* .
cp -R ${PKG_ROOT}/packages/Debian/${architecture}/* .
sed -i "s/Version: 1.0.0/Version: ${version}/g" DEBIAN/control
BOOST_VERSION=$(dpkg -l | grep libboost-dev | awk '{print $3}' | grep -oP '^\d+\.\d+\.\d+')
if [ -z "$BOOST_VERSION" ]; then
echo "❌ Boost version not found. Is libboost-dev installed?"
exit 1
fi
echo "✅ Found Boost version: $BOOST_VERSION"
sed -i "s/{{BOOST_VER}}/${BOOST_VERSION}/g" DEBIAN/control
if [[ $skip_build == 0 ]] && ([[ ${branch} = "main" ]] || [[ ${branch} =~ ^[0-9]+\.[0-9]+\.[0-9]+RC ]] || [[ ${branch} =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]); then echo "Build: ${git_tag_info:1}" >> DEBIAN/control; fi
mkdir -p usr/local/fledge
cd usr/local/fledge
cp -R ${FLEDGE_ROOT}/* .
echo "Done."
# Prepare new data directory
echo "Prepare data directory"
mv data data.new
cd data.new
rm -rf backup
rm -rf core.err
rm -rf etc/certs/*
rm -rf fledge.db
rm -rf logs
rm -rf scripts
rm -rf support
rm -rf var
# Add customised files
#echo -n "Adding Fledge customization..."
#cp -R ${PKG_ROOT}/share/* share/postgresql/.
#cd ${BUILD_ROOT}/${package_name}/usr/local/fledge/plugins/storage/postgres
#mkdir bin
#cp ${PKG_ROOT}/scripts/* bin/.
#echo "Done."
# Build the package
cd "${BUILD_ROOT}"
# Save the old versions
existing_pkgs=`find . -maxdepth 1 -name "${package_name}.deb.????" | wc -l`
existing_pkgs=$((existing_pkgs+1))
new_stored_pkg=$(printf "${package_name}.deb.%04d" "${existing_pkgs}")
if [ -e "${package_name}.deb" ]; then
echo "Saving the old package as ${new_stored_pkg}"
mv "${package_name}.deb" "${new_stored_pkg}"
fi
echo "Building the new package..."
dpkg-deb --build ${package_name}
echo "Building Complete."
exit 0