This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·241 lines (209 loc) · 6.61 KB
/
build.sh
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
#!/bin/bash
##
# Compile xtee-misp2-* debian packages and add them to repo.
#
# The script is part of install_source directory content which all
# has to be layed out in home directory (normally /home/misp2)
# so that it contains the following directory structure:
# /home
# /misp2
# /git
# /MISP2-install-source
# /repo
# /xtee-misp2-postgresql
# /xtee-misp2-base
# /xtee-misp2-orbeon
# /xtee-misp2-application
# /build.sh
#
# Script has to be run by normal user (e.g. misp2) with MISP2-install-source set as current directory.
#
# Examples:
#
### Before running the script, change directory to 'MISP2-install-source' and make the script executable
#
# cd ~/git/MISP2-install-source
# chmod u+x build.sh
#
### To build all 5 xtee-misp2 packages and add them to /repo directory,
### run build.sh without arguments.
#
# ./build.sh
#
### To build selected packages, add respective package suffixes (E.g. postgresql, base, orbeon, application)
### as command line arguments. The following example only builds xtee-misp2-application package.
#
# ./build.sh application
#
### To build packages for specific Ubuntu distro, add distro codename as argument (E.g xenial or bionic).
#
# ./build.sh xenial
#
## During the build, relevant packages are added to /repo.
## To clean project directory from intermediary generated package files, run
#
# ./build.sh -clean
#
## To build without pulling changes from Git (-nogit)
## and without (re)building webapps (-nobuild)
## and without signing debian packages (-nosign), run:
#
# ./build.sh -nosign -nogit -nobuild
#
## To pull updates and build webapps, but not create debian packages, run:
#
# ./build.sh -nodebian
#
##
# Fail on error
set -e
# Do not allow to run as root
if [ "$EUID" == "0" ]
then
echo "This build script should not be run as root, otherwise various issues will occur."
echo "For instance, updated files will have root as owner."
exit 1
fi
# Change working directory to the location of currently run script
cd "$(dirname "$0")"
# Import functions
. resources/functions-build.sh
# Variable declarations
git_branch_install_source=master
git_branch_orbeon_war=master
git_branch_misp2_webapp=develop
prefix=xtee-misp2
repo_name="repo"
distros=$(get_distros "$*")
packages=$(get_packages "$*" "$prefix")
default_distro="bionic"
if (gpg --list-secret-keys | grep -q sec) && ! contains_word "$*" "-nosign"
then
echo "Packages are going to be signed."
add_to_repo=true
else
echo "Packages are NOT going to be signed."
add_to_repo=false
fi
if contains_word "$packages" "$prefix-application" && ! contains_word "$*" "-nobuild"
then
build_webapp=true
fi
if contains_word "$packages" "$prefix-orbeon" && ! contains_word "$*" "-nobuild"
then
build_orbeon=true
fi
if contains_word "$*" "-clean"
then
echo "Clean up build directory and restore package sources to default state."
# Clean up of previously generated packages (*.deb files only)
clean_up "$prefix"
# Restore default state of repository source
adjust_to_distro "$default_distro" "$repo_name" "$prefix" "$packages" "$add_to_repo"
exit 0
fi
if ! contains_word "$*" "-nogit"
then
# Cache Git credentials for 60 s to avoid inserting them multiple times
git config --global credential.helper 'cache --timeout=60'
# Update install source project
git pull origin "$git_branch_install_source"
if [ "$build_webapp" == true ]
then
# Update MISP2 webapp project
cd ../misp2-web-app
git pull origin "$git_branch_misp2_webapp"
cd ../misp2-install-source
fi
if [ "$build_orbeon" == true ]
then
# Update Orbeon webapp project
cd ../misp2-orbeon-war
git pull origin "$git_branch_orbeon_war"
cd ../misp2-install-source
fi
fi
# Build webapp WAR-s and copy them to Debian package build directories
if [ "$build_webapp" == true ]
then
cd ../misp2-web-app
echo "(Building MISP2 webapp)"
# Build webapp
mvn --batch-mode clean install
# Copy webapp to 'war' directory in xtee-misp2-application project
cp target/misp2.war ../misp2-install-source/$prefix-application/war/misp2.war
cd ../misp2-install-source
else
echo "(Not building MISP2 webapp)"
fi
# If application package is being built, check WAR version
if contains_word "$packages" "$prefix-application"
then
cd $prefix-application/war
echo "(Checking MISP webapp version)"
# Check WAR POM version if it matches application package version
check_war_version misp2.war $prefix-application "$*"
cd ../..
else
echo "(Not checking MISP2 webapp version)"
fi
if [ "$build_orbeon" == true ]
then
cd ../misp2-orbeon-war
echo "(Building Orbeon webapp)"
# Build Orbeon webapp WAR
ant war
# Copy webapp WAR file to 'war' directory in xtee-misp2-orbeon project
cp build/orbeon-misp2.war ../misp2-install-source/$prefix-orbeon/war/orbeon.war
cd ../misp2-install-source
else
echo "(Not building Orbeon webapp)"
fi
# Optional exit when '-nodebian' argument is given; in order to avoid time-consuming debian package build process
if contains_word "$*" "-nodebian"
then
echo "Exiting before package building (command line argument '-nodebian' received)."
exit 0
fi
# Loop through all Ubuntu distributions that packages are created for
for distro_codename in $distros
do
# Perform modifications in package source for specific target distribution
adjust_to_distro "$distro_codename" "$repo_name" "$prefix" "$packages" "$add_to_repo"
if [ "$add_to_repo" == "true" ]
then
# Clean up of previously generated packages (*.deb files only)
clean_up "$prefix"
fi
# Compile user-specified packages to *.deb files
compile_packages "$packages" "$add_to_repo" "$distro_codename"
# Package compilation done
if [ "$add_to_repo" == "true" ]
then
echo "Adding packages to $repo_name.."
# Copy packages to repo and build repo
cd "$repo_name"
# To remove old packages from repo, comment in the following line:
#rm dists/*/main/binary-amd64/$prefix-* || true
chmod u+x make-ee-repo.sh
./make-ee-repo.sh
cd ..
else
echo "Skipping adding packages to repo because of the '-nosign' argument"
fi
# Display build summary for built distribution
build_summary=$(display_build_summary "$distro_codename" "$compiled_packages" "$repo_name" "$add_to_repo")
echo $build_summary
summary="$summary\n$build_summary"
done
# Delete temporary build files in current directory
clean_up "$prefix"
# Recover source to initial state
adjust_to_distro "$default_distro" "$repo_name" "$prefix" "$packages" "$add_to_repo"
# Show summary (all distributions)
if [ "$add_to_repo" == "true" ]
then
echo -e "\nSummary:$summary"
else
echo -e "\nSummary:\nNB! Repo not signed. Added packages to different directory: '$target_repo_dir'.$summary"
fi