forked from fledge-iot/fledge-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_rpm
executable file
·169 lines (143 loc) · 5.36 KB
/
make_rpm
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
#!/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: Mohd. Shariq
##
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 RPM package of fledge-gui
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"
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
;;
help)
echo "${usage}"
exit 0
;;
*)
echo "Unrecognized option: $i"
exit 1
;;
esac
done
os=$(uname)
echo "Operating System Type: ${os}"
compat_msg="This script is compatible with Red Hat Linux 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 == *"Red Hat"* ]] || [[ $n == *"CentOS"* ]]; 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"
git_tag_info=$(git describe --tags | sed 's/-/_/g') && commit_count=$(echo ${git_tag_info} | cut -d_ -f2) || { commit_count=$(git rev-list --count HEAD); git_tag_info="v$version_$commit_count_$(git rev-parse --short HEAD)"; }
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
if [[ ${branch_name} = "main" ]] || [[ ${branch_name} =~ ^[0-9]+\.[0-9]+\.[0-9]+RC ]] || [[ ${branch_name} =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then commit_count=1; fi
# Final package name
package_name="fledge-gui-${version}-${commit_count}"
arch=`arch`
# 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 RPM files
echo -n "Populating the package and updating version file..."
cd "${package_name}"
cp -R ${GIT_ROOT}/packages/RPM/* .
sed -i "s/__VERSION__/${version}/g" SPECS/fledge-gui.spec
sed -i "s/__ARCH__/${arch}/g" SPECS/fledge-gui.spec
sed -i "s/__RELEASE__/${commit_count}/g" SPECS/fledge-gui.spec
sed -i "s/__VCS__/${git_tag_info:1}/g" SPECS/fledge-gui.spec
echo "Done."
mkdir BUILDROOT
cd BUILDROOT
mkdir -p ${package_name}.${arch}
cd ${package_name}.${arch}
# sed -i 's/dist/\/usr\/share\/nginx\/html/g' ${GIT_ROOT}/dist/nginx.conf
echo "Copying build artifacts for nginx webroot directory..."
mkdir -p usr/share/nginx/html
cp -R ${GIT_ROOT}/dist/* usr/share/nginx/html/
echo "Done."
cd ..
# Build the package
cd "${BUILD_ROOT}"
# Save the old versions
existing_pkgs=`find . -maxdepth 1 -name "${package_name}.rpm.????" | wc -l`
existing_pkgs=$((existing_pkgs+1))
new_stored_pkg=$(printf "${package_name}.rpm.%04d" "${existing_pkgs}")
if [ -e "${package_name}.rpm" ]; then
echo "Saving the old package as ${new_stored_pkg}"
mv "${package_name}.rpm" "${new_stored_pkg}"
fi
echo "Building the new rpm package..."
rpmbuild --define "_topdir ${BUILD_ROOT}/${package_name}" --noclean -bb ${BUILD_ROOT}/${package_name}/SPECS/fledge-gui.spec
echo "Done."
exit 0