-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_deb
executable file
·214 lines (187 loc) · 6.59 KB
/
make_deb
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
#!/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") [help|clean|cleanall]
This script is used to create the Debian package of Fledge
Arguments:
help - Display this help text
clean - Remove all the old versions saved in format .XXXX
cleanall - Remove all the versions, including the last one"
PKG_ROOT=`pwd`
architecture=`arch`
ARCH_NAME=$(dpkg --print-architecture)
repo_name=fledge
skip_build=0
while getopts ":hcasb:" opt; do
case "$opt" in
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
;;
cleanall)
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)
skip_build=1
;;
b)
branch=$OPTARG
;;
help)
echo "${usage}"
exit 1
;;
*)
echo "Unrecognized option: $i"
exit 1
;;
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
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