1
1
#! /bin/sh
2
2
3
- . ` dirname " $0 " ` /functions
3
+ #
4
+ # This script installs the dependencies to be bundled with CFEngine.
5
+ # The dependencies are built into you working directory.
6
+ #
7
+ # The script expects the following repositories to exist side by side:
8
+ # .
9
+ # ├── buildscripts
10
+ # ├── core
11
+ # ├── enterprise
12
+ # ├── nova
13
+ # └── masterfiles
14
+ #
15
+ # ^ When building community you won't need enterprise, nova.
16
+ #
17
+ # The script can be run as follows:
18
+ # ```
19
+ # $ PROJECT=[enterprise|community] EXPLICIT_ROLE=[hub|agent] BUILD_TYPE=[DEBUG|RELEASE] ./buildscripts/build-scripts/install-dependencies
20
+ # ```
21
+ #
22
+
23
+ . " $( dirname " $0 " ) " /functions
4
24
. detect-environment
5
25
. compile-options
6
26
7
27
# We use packaging scripts
8
28
PATH=$PATH :$BASEDIR /buildscripts/deps-packaging
9
29
10
- # Not all dependencies support building in parallel.
11
- # TODO: Investigate if this is still the case or disable parallel jobs for only
12
- # the dependencies that not support it. (ENT-13041)
13
- MAKEFLAGS=-j1
14
-
15
- set -x
16
-
17
30
# This should be already set from sourcing "functions" at the top, but
18
31
# make sure, because we don't want build-artifacts-cache to have bogus
19
32
# packages.
20
33
set -e
21
34
22
-
23
35
install_pkg_files ()
24
36
{
25
- retry_wrapper pkg-install-$DEP_PACKAGING " $@ "
37
+ retry_wrapper " pkg-install-$DEP_PACKAGING " " $@ "
26
38
}
27
39
28
-
29
40
# OpenSSL 1.1 requires Perl 5.10.0 and some modules existing only in 5.13.4 to
30
41
# build and test properly, so we require 5.13.4 at least. See NOTES.PERL in
31
42
# OpenSSL.
@@ -38,42 +49,42 @@ install_pkg_files()
38
49
# perl-Module-Load-Conditional for RHELs).
39
50
check_and_install_perl ()
40
51
{
41
- [ x" $PERL " = x ] && [ -x " $HOME /perl-my/bin/perl" ] \
52
+ # Unless $PERL us already set:
53
+ # - set it to $HOME/perl-my/bin/perl if it exists and is executable
54
+ # - otherwise look for it elsewhere
55
+ [ -z " $PERL " ] && [ -x " $HOME /perl-my/bin/perl" ] \
42
56
&& PERL=" $HOME /perl-my/bin/perl" \
43
- || PERL=` func_whereis perl`
57
+ || PERL=$( func_whereis perl)
44
58
45
59
PERL_OK=yes
46
- PERL_MINOR_VERSION=` $PERL -e ' print "$]"."\n"' | cut -d. -f2`
47
- if [ " $PERL_MINOR_VERSION " -lt 013004 ]
48
- then
49
- echo " $PERL version is $PERL_MINOR_VERSION ," \
50
- " too old"
60
+ PERL_MINOR_VERSION=$( $PERL -e ' print "$]"."\n"' | cut -d. -f2)
61
+ if [ " $PERL_MINOR_VERSION " -lt 013004 ]; then
62
+ log_debug " $PERL version is too old (minor version $PERL_MINOR_VERSION )"
51
63
PERL_OK=" no"
52
64
fi
65
+
53
66
if ! $PERL -e ' use List::Util qw(pairs);' ; then
54
- echo " $PERL has List::Util that does not export pairs. Needs to be at least version 1.29 for OpenSSL version 3.3.2."
67
+ log_debug $PERL has List::Util that does not export pairs. Needs to be at least version 1.29 for OpenSSL version 3.3.2.
55
68
PERL_OK=" no"
56
69
fi
70
+
57
71
if [ " $PERL_OK " != " yes" ]; then
58
- echo " $PERL is too old or modules are missing, building new one from source..."
72
+ log_debug $PERL is too old or modules are missing, building new one from source...
59
73
60
74
# -fno-stack-protector: Ensure built perl will not depend on libssp.so
61
- if echo | gcc -E -fno-stack-protector - > /dev/null 2>&1
62
- then
75
+ if echo | gcc -E -fno-stack-protector - > /dev/null 2>&1 ; then
63
76
PERL_CFLAGS=' -Accflags=-fno-stack-protector'
64
77
fi
65
78
66
79
# Solaris 11 insists on having a dependency to libgcc_s.so which
67
80
# resides in /opt/csw/lib. Unfortunately the following hack is not
68
81
# working on other platforms so we have to hide it.
69
- if [ $OS = solaris ] && [ $OS_VERSION = 11 ]
70
- then
82
+ if [ " $OS " = solaris ] && [ " $OS_VERSION " = 11 ]; then
71
83
PERL_LDFLAGS=' -Aldflags=-static-libgcc'
72
84
PERL_LDDLFLAGS=' -Alddlflags=-static-libgcc -Alddlflags=-shared'
73
85
fi
74
86
75
- if [ $OS = aix ] && [ $OS_VERSION != 5.3 ]
76
- then
87
+ if [ " $OS " = aix ] && [ " $OS_VERSION " != 5.3 ]; then
77
88
# AIX says it provides the nexttoward() 128bit floating point API,
78
89
# but it actually doesn't provide the function. So let's make sure
79
90
# the function is declared missing and not used.
@@ -85,15 +96,26 @@ check_and_install_perl()
85
96
# from the perl dev team - they are only intended for development
86
97
PERL_VERSION=5.40.1
87
98
PERL_SHA256=02f8c45bb379ed0c3de7514fad48c714fd46be8f0b536bfd5320050165a1ee26
88
- wget https://www.cpan.org/src/5.0/perl-${PERL_VERSION} .tar.gz
89
- [ ` func_sha256 perl-${PERL_VERSION} .tar.gz` != " ${PERL_SHA256} " ] \
90
- && fatal " perl checksum error"
99
+
100
+ log_debug Fetching perl tarball...
101
+ run_and_print_on_failure wget https://www.cpan.org/src/5.0/perl-${PERL_VERSION} .tar.gz
102
+ if [ " $( func_sha256 perl-${PERL_VERSION} .tar.gz) " != " ${PERL_SHA256} " ]; then
103
+ fatal " perl checksum error"
104
+ fi
105
+
106
+ log_debug Extracting perl tarball...
91
107
gzip -dc perl-${PERL_VERSION} .tar.gz | tar xf -
92
108
cd perl-${PERL_VERSION}
93
- ./Configure -des -Dprefix=$HOME /perl-my -Dcc=gcc -Dmake=$MAKE \
94
- $PERL_EXTRA_FLAGS $PERL_CFLAGS $PERL_LDFLAGS $PERL_LDDLFLAGS
95
- $MAKE
96
- $MAKE install
109
+
110
+ log_debug Running ./Configure on perl project...
111
+ run_and_print_on_failure ./Configure -des -Dprefix=" $HOME " /perl-my -Dcc=gcc -Dmake=" $MAKE " \
112
+ " $PERL_EXTRA_FLAGS " " $PERL_CFLAGS " " $PERL_LDFLAGS " " $PERL_LDDLFLAGS "
113
+
114
+ log_debug Running make on perl project...
115
+ run_and_print_on_failure $MAKE
116
+
117
+ log_debug Running make install on perl project...
118
+ run_and_print_on_failure $MAKE install
97
119
PERL=$HOME /perl-my/bin/perl
98
120
fi
99
121
@@ -106,91 +128,105 @@ check_and_install_perl
106
128
107
129
# non-gnu exotics don't support sed -i,
108
130
# and only hub or deb packages use files mentioned below
109
- if [ " $BUILDPREFIX " != " /var/cfengine" -a \( " $DEP_PACKAGING " = " deb" -o " $ROLE " = hub \) ]
110
- then
111
- # Apply necessary changes for alternate prefix
112
- sed -i " s:/var/cfengine:$BUILDPREFIX :" \
113
- $BASEDIR /buildscripts/deps-packaging/* /debian/* .install \
114
- $BASEDIR /buildscripts/deps-packaging/* /mingw/debian/* .install \
115
- $BASEDIR /buildscripts/deps-packaging/apache/httpd.conf
131
+ if [ " $BUILDPREFIX " != /var/cfengine ]; then
132
+ if [ " $DEP_PACKAGING " = deb ] || [ " $ROLE " = hub ]; then
133
+ # Apply necessary changes for alternate prefix
134
+ sed -i " s:/var/cfengine:$BUILDPREFIX :" \
135
+ " $BASEDIR /buildscripts/deps-packaging/*/debian/*.install" \
136
+ " $BASEDIR /buildscripts/deps-packaging/*/mingw/debian/*.install" \
137
+ " $BASEDIR /buildscripts/deps-packaging/apache/httpd.conf"
138
+ fi
116
139
fi
117
140
118
141
# Override for manual testing
119
- if [ " x $1 " != x ]
120
- then
121
- DEPS=" $@ "
142
+ if [ -n " $1 " ] ; then
143
+ log_debug " Overriding dependency list (manual testing) "
144
+ DEPS=" $* "
122
145
fi
123
146
124
-
125
147
for dep in $DEPS
126
148
do
127
149
case " $BUILD_TYPE " in
128
- DEBUG|CODE_COVERAGE)
129
- optimize=yes
130
- debugsym=no
131
- versuffix=+untested
132
- tests=no;;
133
- RELEASE)
134
- optimize=yes
135
- debugsym=no
136
- versuffix=+release
137
- tests=yes;;
138
- * )
139
- echo " Unknown build type: $BUILD_TYPE "
140
- exit 42;;
150
+ DEBUG|CODE_COVERAGE)
151
+ optimize=yes
152
+ debugsym=no
153
+ versuffix=+untested
154
+ tests=no
155
+ ;;
156
+ RELEASE)
157
+ optimize=yes
158
+ debugsym=no
159
+ versuffix=+release
160
+ tests=yes
161
+ ;;
162
+ * )
163
+ fatal " Unknown build type: $BUILD_TYPE "
164
+ ;;
141
165
esac
142
166
143
167
case " $ARCH " in
144
- x86|x64)
145
- crossver=+mingw$ARCH
146
- cross=$ARCH ;;
147
- * )
148
- crossver=
149
- cross=native;;
168
+ x86|x64)
169
+ crossver=+mingw$ARCH
170
+ cross=$ARCH
171
+ ;;
172
+ * )
173
+ crossver=
174
+ cross=native
175
+ ;;
150
176
esac
151
177
152
- revision= $( cat $BASEDIR /buildscripts/deps-packaging/revision )
153
- if [ " $BUILDPREFIX " != " /var/cfengine " ]
154
- then
178
+ # Add $PREFIX to version of built dependencies so they get different package names and are distinguishable from each
179
+ revision= $( cat " $BASEDIR " /buildscripts/deps-packaging/revision )
180
+ if [ " $BUILDPREFIX " != " /var/cfengine " ] ; then
155
181
safe_prefix=" +$( echo " $PREFIX " | sed ' s:/::g' ) "
156
182
fi
157
183
version=0+$revision$versuffix$crossver$safe_prefix
158
184
159
185
# FETCH dependency packages if needed
160
- package_files=` pkg-cache listpkgfiles $dep -$version `
186
+ package_files=$( pkg-cache listpkgfiles " $dep -$version " )
161
187
162
188
# If package cache did not have the packages
163
- if [ x " $package_files " = x ]
164
- then
189
+ if [ -z " $package_files " ] ; then
190
+ log_debug Building package $dep ...
165
191
# BUILD the packages
166
192
if [ " $dep " = " lmdb" ] && [ " $BUILD_TYPE " != " RELEASE" ]; then
167
- # Always build LMDB with debug symbols in non-release builds
168
- $BASEDIR /buildscripts/deps-packaging/pkg-build-$DEP_PACKAGING \
169
- $dep $tests $cross $optimize yes $version
193
+ # Always build LMDB with debug symbols in non-release builds.
194
+ # The reason is an ongoing issue where we fail to open database transactions.
195
+ # See ENT-10777 for more info.
196
+ " $BASEDIR /buildscripts/deps-packaging/pkg-build-$DEP_PACKAGING " \
197
+ " $dep " " $tests " " $cross " " $optimize " yes " $version "
170
198
else
171
- $BASEDIR /buildscripts/deps-packaging/pkg-build-$DEP_PACKAGING \
172
- $dep $tests $cross $optimize $debugsym $version
199
+ " $BASEDIR /buildscripts/deps-packaging/pkg-build-$DEP_PACKAGING " \
200
+ " $dep " " $tests " " $cross " " $optimize " " $debugsym " " $version "
173
201
fi
174
202
175
- package_files= ` pkg-find- $DEP_PACKAGING $BASEDIR / $dep `
176
-
177
- [ x " $package_files " = x ] && \
203
+ # Make sure package is there after building it
204
+ package_files= $( " pkg-find- $DEP_PACKAGING " " $BASEDIR / $dep " )
205
+ if [ -z " $package_files " ] ; then
178
206
fatal " Empty output dir after building dependency: $dep "
207
+ fi
179
208
180
209
# CACHE the newly built package
181
- pkg-cache putpkg $dep -$version $package_files
210
+ # shellcheck disable=SC2086
211
+ log_debug Caching package $dep ...
212
+ pkg-cache putpkg " $dep -$version " $package_files
182
213
183
214
# CLEAN UP
215
+ # shellcheck disable=SC2086
216
+ log_debug Removing package files for $dep ...
184
217
rm -f $package_files
185
218
186
219
# Now the package should be in the local cache
187
- package_files=` pkg-cache listpkgfiles $dep -$version `
188
- [ x " $package_files " = x ] && \
220
+ package_files=$( pkg-cache listpkgfiles " $dep -$version " )
221
+ if [ -z " $package_files " ] ; then
189
222
fatal " Cache did not find package after putpkg"
223
+ fi
190
224
fi
191
225
192
226
# INSTALL the packages
193
- install_pkg_files $package_files
227
+ # shellcheck disable=SC2086
228
+ log_debug Installing package files for $dep ...
229
+ install_pkg_files $package_files
194
230
195
231
# keep 50 most recent packages to preserve disk space
196
232
pkg-cache keep_newest 50
0 commit comments