-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·423 lines (369 loc) · 10 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#!/usr/bin/env bash
# shellcheck disable=SC1039
# shellcheck disable=SC2034
set -e
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
arch='amd64'
oldstable='beowulf'
stable='chimaera'
testing='daedalus'
version='3.0'
function usage()
{
cat <<EOF
NAME:
build.sh - Docker images' builder of Devuan.
USAGE:
build.sh -d <dist>
OPTIONS:
-h, --help Show help
-d, --dist Choose Devuan distribution
eg: jessie, ascii, beowulf, chimaera
-t, --timezone Choose your preferred timezone
default: Europe/Amsterdam
-u, --user Docker Hub username or organisation
default: $USER
-p, --push Docker Hub push
default: no
-l, --latest Force the "latest"
default: chimaera
-v, --verbose Verbose mode
-V, --version Show version
VERSION:
docker-devuan version: ${version}
EOF
}
function docker_bootstrap()
{
# variables
image="/tmp/image-${distname}-${arch}"
include="${include},\
apt-transport-https,\
apt-utils,\
ca-certificates,\
curl,\
devuan-keyring,\
git,\
locales"
exclude="debconf-i18n,\
git-man,\
info,\
man-db,\
manpages"
components='main'
echo '-- bootstrap' 1>&3
if [ "$(id -u)" -ne 0 ]
then
sudo='sudo'
fi
# clean old image
if [ -d "/tmp/image-${distname}-${arch}" ]
then
${sudo} rm -fr "${image}"
fi
# create minimal debootstrap image
if [ ! -f "/usr/share/debootstrap/scripts/${distname}" ] || \
[ ! -h "/usr/share/debootstrap/scripts/${distname}" ]
then
echo "File /usr/share/debootstrap/scripts/${distname} is missing." 1>&3
echo "1.) did you install backports version of debootstrap ?" 1>&3
echo "2.) ln -s sid /usr/share/debootstrap/scripts/${distname}" 1>&3
exit 1
else
echo " * debootstrap ${image}" 1>&3
${sudo} debootstrap \
--arch="${arch}" \
--include="${include}" \
--exclude="${exclude}" \
--variant=minbase \
--no-check-gpg \
"${distname}" \
"${image}" \
"${mirror}"
if [ ${?} -ne 0 ]
then
echo "There is an issue with debootstrap." 1>&3
echo "Please run again with -v." 1>&3
exit 1
fi
fi
# create /etc/default/locale
echo ' * /etc/default/locale' 1>&3
cat <<EOF | \
${sudo} tee "${image}/etc/default/locale"
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_COLLATE=en_US.UTF-8
LC_ALL=en_US.UTF-8
EOF
# create /etc/timezone
echo ' * /etc/timezone' 1>&3
cat <<EOF | \
${sudo} tee "${image}/etc/timezone"
${timezone}
EOF
# create /etc/resolv.conf
echo ' * /etc/resolv.conf' 1>&3
cat <<EOF | \
${sudo} tee "${image}/etc/resolv.conf"
nameserver 8.8.4.4
nameserver 8.8.8.8
EOF
# create /etc/apt/sources.list
echo ' * /etc/apt/sources.list' 1>&3
${sudo} cp -r "sources.list/${distname}" "${image}/etc/apt/sources.list"
# create /etc/dpkg/dpkg.cfg.d/disable-doc
echo ' * /etc/dpkg/dpkg.cfg.d/disable-doc' 1>&3
cat <<EOF | \
${sudo} tee "${image}/etc/dpkg/dpkg.cfg.d/disable-doc"
path-exclude /usr/share/doc/*
path-include /usr/share/doc/*/copyright
path-exclude /usr/share/info/*
path-exclude /usr/share/man/*
EOF
# create /etc/apt/apt.conf.d/force-ipv4
echo ' * /etc/apt/apt.conf.d/force-ipv4' 1>&3
cat <<EOF | \
${sudo} tee "${image}/etc/apt/apt.conf.d/force-ipv4"
Acquire::ForceIPv4 "true";
EOF
# create /etc/apt/apt.conf.d/disable-auto-install
echo ' * /etc/apt/apt.conf.d/disable-auto-install' 1>&3
cat <<EOF | \
${sudo} tee "${image}/etc/apt/apt.conf.d/disable-auto-install"
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOF
# create /etc/apt/apt.conf.d/disable-cache
echo ' * /etc/apt/apt.conf.d/disable-cache' 1>&3
cat <<EOF | \
${sudo} tee "${image}/etc/apt/apt.conf.d/disable-cache"
Dir::Cache::pkgcache "";
Dir::Cache::srcpkgcache "";
EOF
# create /etc/apt/apt.conf.d/force-conf
echo ' * /etc/apt/apt.conf.d/force-conf' 1>&3
cat <<EOF | \
${sudo} tee "${image}/etc/apt/apt.conf.d/force-conf"
Dpkg::Options {
"--force-confnew";
"--force-confmiss";
}
EOF
# create /etc/apt/apt.conf.d/disable-languages
echo ' * /etc/apt/apt.conf.d/disable-languages' 1>&3
cat <<EOF | \
${sudo} tee "${image}/etc/apt/apt.conf.d/disable-languages"
Acquire::Languages "none";
EOF
# create /usr/bin/apt-clean
echo ' * /usr/bin/apt-clean' 1>&3
cat <<EOF | \
${sudo} tee "${image}/usr/bin/apt-clean"
#!/bin/bash
# Please read https://wiki.debian.org/ReduceDebian
find /usr/share/doc -type f ! -name copyright -delete
find /usr/share/i18n -type f -delete
find /usr/share/locale -type f -delete
find /usr/share/man -type f -delete
find /var/cache/apt -type f -delete
find /var/lib/apt/lists -type f -delete
apt-get autoclean -qq -y
apt-get autoremove -qq -y
apt-get clean -qq -y
# EOF
EOF
${sudo} chmod 755 "${image}/usr/bin/apt-clean"
# mount
${sudo} mount --bind /dev "${image}/dev"
${sudo} mount --bind /dev/pts "${image}/dev/pts"
${sudo} mount --bind /proc "${image}/proc"
${sudo} mount --bind /sys "${image}/sys"
# update root certificates
${sudo} mkdir -p "${image}/usr/local/share/"
${sudo} cp -r ca-certificates "${image}/usr/local/share/"
# upgrade (without output...)
echo ' * apt-get upgrade' 1>&3
${sudo} chroot "${image}" bash -c \
"export DEBIAN_FRONTEND=noninteractive && \
update-ca-certificates -f && \
apt-get update && \
apt-get upgrade -y && \
apt-get dist-upgrade -y && \
apt-clean"
# unmount
${sudo} umount "${image}/dev/pts"
${sudo} umount "${image}/dev"
# ${sudo} umount "${image}/proc"
${sudo} umount "${image}/sys"
# create archive
if [ -f "${image}.tar" ]
then
${sudo} rm "${image}.tar"
fi
${sudo} tar -C "${image}" -c -f "${image}.tar" --numeric-owner .
}
# create images from bootstrap archive
function docker_import()
{
echo "-- docker import from ${image}" 1>&3
mount -t proc proc /proc
docker import "${image}.tar" "${user}devuan:${distname}"
docker run "${user}devuan:${distname}" \
echo " * build ${user}devuan:${distname}" 1>&3
docker tag "${user}devuan:${distname}" "${user}devuan:${distid}"
docker run "${user}devuan:${distid}" \
echo " * build ${user}devuan:${distid}" 1>&3
for import in latest oldstable stable testing
do
if [ "${distname}" = "${!import}" ]
then
docker tag "${user}devuan:${distname}" "${user}devuan:${import}"
docker run "${user}devuan:${import}" \
echo " * build ${user}devuan:${import}" 1>&3
fi
done
}
# push image to docker hub
function docker_push()
{
echo "-- docker push" 1>&3
echo " * push ${user}devuan:${distname}" 1>&3
docker push "${user}devuan:${distname}"
echo " * push ${user}devuan:${distid}" 1>&3
docker push "${user}devuan:${distid}"
for push in latest oldstable stable testing
do
if [ "${distname}" = "${!push}" ]
then
echo " * push ${user}devuan:${push}" 1>&3
docker push "${user}devuan:${push}"
fi
done
}
while getopts 'hd:t:u:plvV' OPTIONS
do
case ${OPTIONS} in
h)
# -h / --help
usage
exit 0
;;
d)
# -d / --dist
dist=${OPTARG}
;;
t)
# -t / --timezone
timezone=${OPTARG}
;;
u)
# -u / --user
user="${OPTARG}/"
;;
p)
# -p / --push
push='true'
;;
l)
# -l / --latest
latest=${OPTARG}
;;
v)
# -v / --verbose
verbose='true'
;;
V)
# -v / --version
echo "${version}"
exit 0
;;
*)
usage
exit 1
;;
esac
done
if [ ! -x "$(command -v sudo)" ]
then
echo "Please install sudo (see README.md)"
exit 1
fi
if [ ! -x "$(command -v debootstrap)" ]
then
echo "Please install debootstrap (see README.md)"
exit 1
fi
# -d / --dist
if [ -n "${dist}" ]
then
case ${dist} in
jessie|1|1.0)
distname='jessie'
distid='1'
mirror='http://mirror.vptech.eu/devuan/merged'
;;
ascii|2|2.0)
distname='ascii'
distid='2'
mirror='http://mirror.vptech.eu/devuan/merged'
include='gnupg2'
;;
beowulf|3|3.0)
distname='beowulf'
distid='3'
mirror='http://mirror.vptech.eu/devuan/merged'
include='gnupg2'
;;
chimaera|4|4.0)
distname='chimaera'
distid='4'
mirror='http://mirror.vptech.eu/devuan/merged'
include='gnupg2'
;;
daedalus|5|5.0)
distname='daedalus'
distid='5'
mirror='http://mirror.vptech.eu/devuan/merged'
include='gnupg2'
;;
*)
usage
exit 1
;;
esac
else
usage
exit 1
fi
# -t / --timezone
if [ -z "${timezone}" ]
then
timezone='Europe/Amsterdam'
fi
# -u / --user
if [ -z "${user}" ]
then
user=${USER}
fi
# -l / --latest
if [ -z "${latest}" ]
then
latest='chimaera'
fi
# -v / --verbose
if [ -z "${verbose}" ]
then
exec 3>&1
exec 1>/dev/null
exec 2>/dev/null
else
exec 3>&1
fi
docker_bootstrap
docker_import
if [ -n "${push}" ]
then
docker_push
fi
# EOF