forked from fledge-iot/fledge-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_deb
executable file
·157 lines (131 loc) · 5.03 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
#!/usr/bin/env bash
##--------------------------------------------------------------------
## Copyright (c) 2019 Dianomic Systems Inc.
##
## 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: Ashish Jabble
##
set -e
GIT_ROOT=`pwd` # The script must be executed from the root git directory
usage="$(basename "$0") [clean|cleanall]
This script is used to create the Debian package of fledge-gui
Arguments:
clean - Remove all the old versions saved in format .XXXX
cleanall - Remove all the versions, including the last one"
for i in "$@"
do
case "$i" in
clean)
echo -n "Cleaning the build folder from older versions..."
find "${GIT_ROOT}/packages/build" -maxdepth 1 | grep '.*\.[0-9][0-9][0-9][0-9]' | xargs rm -rf
echo "Done."
exit 0
;;
cleanall)
if [ -d "${GIT_ROOT}/packages/build" ]; then
echo -n "Cleaning the build folder..."
rm -rf ${GIT_ROOT}/packages/build/*
echo "Done."
else
echo "No build folder, skipping cleanall"
fi
exit 0
;;
*)
echo "${usage}"
exit 1
;;
esac
done
# OS Type
os=$(uname)
echo "Operating System Type: ${os}"
compat_msg="This script is compatible with Linux (Ubuntu and Raspbian) Only!"
if [[ $os != "Linux" ]]; then
echo -e ${compat_msg}
exit 1;
fi
if [ -f /etc/os-release ]; then
n=$(cat /etc/os-release | grep -w PRETTY_NAME | cut -d= -f2- | tr -d '"')
if [[ $n == *"Raspbian"* ]] || [[ $n == *"Ubuntu"* ]]; then
echo -e "${n}"
else
echo -e "${n}"
echo -e ${compat_msg}
exit 1;
fi
else
echo -e ${compat_msg}
exit 1;
fi
version=`cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[" ,]//g'`
BUILD_ROOT="${GIT_ROOT}/packages/build"
# Get git info
git_tag_info=$(git describe --tags) && commit_count=$(echo ${git_tag_info} | cut -d- -f2)
branch_name=$(git rev-parse --abbrev-ref HEAD)
# If tagged version is checked out then branch name is HEAD; set it to tag version value
if [[ $branch_name == "HEAD" ]]; then branch_name=$(git describe --tags); fi
# Final package name
if [[ ${branch_name} != "main" ]] && [[ ! ${branch_name} =~ ^[0-9]+\.[0-9]+\.[0-9]+RC ]] && [[ ! ${branch_name} =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then package_name="fledge-gui_${version}-${commit_count}"; version=${git_tag_info:1}; else package_name="fledge-gui_${version}"; fi
# Print the summary of findings
echo "The package root directory is : ${GIT_ROOT}"
echo "The Fledge gui version is : ${version}"
echo "The package will be built in : ${BUILD_ROOT}"
echo "The package name is : ${package_name}"
echo
# Prepare build artifacts
rm -rf ${GIT_ROOT}/dist
./build --clean-start
# 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
echo -n "Populating the package and updating version file..."
cd "${package_name}"
cp -R ${GIT_ROOT}/packages/Debian/* .
sed -i "s/Version: 0.0.0/Version: ${version}/g" DEBIAN/control
if [[ ${branch_name} = "main" ]] || [[ ${branch_name} =~ ^[0-9]+\.[0-9]+\.[0-9]+RC ]] || [[ ${branch_name} =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then echo "Build: ${git_tag_info:1}" >> DEBIAN/control; fi
echo "Done."
# sed -i 's/dist/\/var\/www\/html/g' ${GIT_ROOT}/dist/nginx.conf
echo "Copying build artifacts for nginx webroot directory..."
mkdir -p var/www/html
cp -R ${GIT_ROOT}/dist/* var/www/html/
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 debian package..."
dpkg-deb --build ${package_name}
echo "Done."
exit 0