This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
forked from ospalax/addon-kea-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
290 lines (240 loc) · 6.36 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/sh
#
# Copyright (2019-2021) Petr Ospalý <[email protected]>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
set -ex
# Stages:
# 1. suite (ISC Kea itself)
# 2. hooks (custom hooks)
STAGE="${1:-suite}"
KEA_INSTALLPREFIX="${KEA_INSTALLPREFIX:-/usr/local}"
MAKE_JOBS="${MAKE_JOBS:-1}"
#
# functions
#
install_kea_runtime_deps()
{
apk update
apk add --no-cache \
boost \
postgresql-client \
mariadb-client \
mariadb-connector-c \
openssl \
ca-certificates \
curl \
xz \
;
# try to install stable version first, then try from edge or fail
apk add --no-cache log4cplus \
|| \
apk add --no-cache \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
log4cplus
}
install_kea_from_package()
{
apk add --no-cache \
"kea~${KEA_VERSION}" \
;
apk add --no-cache --virtual .build-deps1 \
alpine-sdk \
sudo \
"kea-dev~${KEA_VERSION}" \
;
# TODO: remove when apk will be build
# musl linker search paths
if ! [ -f /etc/ld-musl-$(arch).path ] ; then
echo "/lib:/usr/local/lib:/usr/lib" > /etc/ld-musl-$(arch).path
chmod 0644 /etc/ld-musl-$(arch).path
fi
}
install_kea_build_deps()
{
apk add --no-cache --virtual .build-deps2 \
alpine-sdk \
sudo \
build-base \
file \
gnupg \
pkgconf \
automake \
libtool \
docbook-xsl \
libxslt \
doxygen \
openssl-dev \
boost-dev \
postgresql-dev \
mariadb-dev \
musl-dev \
zlib-dev \
bzip2-dev \
sqlite-dev \
python3-dev \
;
# try to install stable version first, then try from edge or fail
apk add --no-cache log4cplus-dev \
|| \
apk add --no-cache \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
log4cplus-dev
# bug #2608 in kea 2.2.0, remove when fixed
if [ ${KEA_VERSION} = "2.2.0" ]; then
cp cfg_globals.h "/usr/include/kea/dhcpsrv/cfg_globals.h"
fi
}
install_kea_from_source()
{
curl -LOR \
"https://ftp.isc.org/isc/kea/${KEA_VERSION}/kea-${KEA_VERSION}.tar.gz{,.sha512.asc}"
mkdir -m 0700 -p /root/.gnupg
gpg2 \
--no-options \
--verbose \
--keyid-format 0xlong \
--keyserver-options \
auto-key-retrieve=true \
--verify \
kea-${KEA_VERSION}.tar.gz*asc \
kea-${KEA_VERSION}.tar.gz
tar xzpf kea-${KEA_VERSION}.tar.gz
rm -rf \
kea-${KEA_VERSION}.tar.gz* \
/root/.gnupg* \
cd kea-${KEA_VERSION}
./configure \
--prefix="${KEA_INSTALLPREFIX}" \
--enable-shell \
--with-mysql=/usr/bin/mysql_config \
--with-pgsql=/usr/bin/pg_config \
--with-openssl \
--with-log4cplus=/usr \
;
make -j ${MAKE_JOBS} && make install-strip
# bug #2608 in kea 2.2.0, remove when fixed
cp src/lib/dhcpsrv/cfg_globals.h "${KEA_INSTALLPREFIX}/include/kea/dhcpsrv/"
cd -
# musl linker search paths
if ! [ -f /etc/ld-musl-$(arch).path ] ; then
echo "/lib:/usr/local/lib:/usr/lib" > /etc/ld-musl-$(arch).path
chmod 0644 /etc/ld-musl-$(arch).path
fi
echo "${KEA_INSTALLPREFIX}/lib" >> /etc/ld-musl-$(arch).path
ldconfig "${KEA_INSTALLPREFIX}/lib"
}
install_hooks_from_source()
{
if is_true USE_DISTRO_PACKAGE ; then
# override the prefix - distribution version is always under /usr
KEA_INSTALLPREFIX="/usr"
export KEA_INSTALLPREFIX
fi
for hook in /ikea/hooks/*/ ; do
if [ -d "${hook}/${KEA_VERSION}/submodule" ] ; then
cd "${hook}/${KEA_VERSION}/submodule"
make install
cd -
fi
done
}
prepare_abuild()
{
adduser -D -G abuild abuild
mkdir -p /var/cache/distfiles
chgrp abuild /var/cache/distfiles
chmod g+w /var/cache/distfiles
cat /abuild.conf > /etc/abuild.conf
rm -f /abuild.conf
echo 'abuild ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
su - abuild -c 'abuild-keygen -a -i -n'
}
run_abuild()
{
for hook in /ikea/hooks/*/ ; do
if [ -e "${hook}/${KEA_VERSION}/APKBUILD" ] ; then
hook_name=$(basename "${hook}")
su - abuild -c "newapkbuild ${hook_name}"
cd ~abuild/"${hook_name}"
cat "${hook}/${KEA_VERSION}/APKBUILD" > APKBUILD
su abuild -c "abuild checksum && abuild -r"
cd -
fi
done
mv ~abuild/packages /
mv /packages/abuild /packages/"onekea-hooks-${KEA_VERSION}"
chown -R root:root /packages
}
clean_apk()
{
apk --purge del .build-deps1 .build-deps2 log4cplus-dev
}
# arg: <variable name>
is_true()
{
_value=$(eval echo "\$${1}" | tr '[:upper:]' '[:lower:]')
case "$_value" in
yes|true)
return 0
;;
esac
return 1
}
#
# main
#
# sanity checks first
if [ -z "$KEA_VERSION" ] ; then
echo "ERROR: Variable 'KEA_VERSION' is unset" 1>&2
exit 1
fi
case "$STAGE" in
suite)
if is_true USE_DISTRO_PACKAGE ; then
# install packages
install_kea_runtime_deps
install_kea_from_package
else
# install packages
install_kea_runtime_deps
install_kea_build_deps
# build and install ISC Kea suite
install_kea_from_source
# delete blob?
if ! is_true KEEP_BUILDBLOB ; then
rm -rf /ikea/kea-${KEA_VERSION}*
fi
fi
;;
hooks)
# install packages
install_kea_runtime_deps
install_kea_build_deps
# build and install ISC Kea hooks
if is_true INSTALL_HOOKS ; then
install_hooks_from_source
fi
# run alpine build system to create a package
prepare_abuild
run_abuild
# delete blob?
if ! is_true KEEP_BUILDBLOB ; then
rm -rf /ikea/hooks
fi
;;
*)
echo "ERROR: Unknown stage: '${STAGE}' (suite|hooks)" 1>&2
exit 1
;;
esac
# cleanup
if ! is_true KEEP_BUILDDEPS ; then
clean_apk
fi
# delete cache
rm -rf /var/cache/apk/*
exit 0