-
Notifications
You must be signed in to change notification settings - Fork 2
/
ubuntu-defaults-image
executable file
·355 lines (318 loc) · 10.2 KB
/
ubuntu-defaults-image
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
#! /bin/sh
# Build an image based on an Ubuntu flavor plus a defaults package.
#
# Authors: Colin Watson <cjwatson@ubuntu.com>
# Martin Pitt <martin.pitt@ubuntu.com>
# Rob Dyke <rob@neovahealth.co.uk>
# Copyright: (C) 2011 Canonical Ltd.
# Copyright: (C) 2017 Neova Health LLP
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
LOCALE=
PACKAGE=
XPACKAGES=
ARCH=
COMPONENTS=
MIRROR=
SECURITY_MIRROR=
PPAS=
REPOS=
FLAVOR=ubuntu
SUITE=$(lsb_release -sc)
KEEP_APT_OPT=
DELETE_APT_LISTS="rm -vf /var/lib/apt/lists/*_*"
# if which dpkg-architecture >/dev/null 2>&1; then
# ARCH="$(dpkg-architecture -qDEB_HOST_ARCH)"
# fi
help () {
cat >&2 <<EOF
Usage: $0 {--locale code|--package name} [options]
Options:
--locale ll_CC : Same as --package ubuntu-defaults-ll-cc
--package : Install additional package; can be a name or path to a local .deb
--xpackage : Install extra packages by package name
--arch : Architecture [default: $ARCH]
--flavor FLAVOR : Flavor of Ubuntu [default: $FLAVOR]
--release RELEASE : Ubuntu release the image is based on [default: $SUITE]
--components COMPONENTS : List of archive components to enable [default: main,restricted]
--mirror : Ubuntu mirror to be used during build
[default: http://archive.ubuntu.com/ubuntu/]
--security-mirror : Ubuntu security mirror to be used during build
[default: http://security.ubuntu.com/ubuntu/]
--ppa USER/PPANAME : Enable additional PPA [default: none]
--repo USER/NAME : Enable packagecloud repo [default: none]
--keep-apt : Do not remove apt indexes from live system
--keep-apt-components COMPONENTS :
Do not remove apt indexes for selected components from live
system [default: none]
EOF
}
# add $PPAS
add_ppas () {
for ppa in $PPAS; do
local FINGERPRINT=`wget -q -O- https://launchpad.net/api/1.0/~${ppa%/*}/+archive/${ppa#*/}/signing_key_fingerprint`
if ! expr match "$FINGERPRINT" '^\"[a-zA-Z0-9]\{16,\}"$' >/dev/null; then
echo "Invalid fingerprint returned by Launchpad: $FINGERPRINT" >&2
exit 1
fi
# chop off enclosing quotes
FINGERPRINT=${FINGERPRINT%'"'}
FINGERPRINT=${FINGERPRINT#'"'}
# fetch GPG key
gpg --no-default-keyring --primary-keyring config/archives/ubuntu-defaults.key --keyserver keyserver.ubuntu.com --recv-key "$FINGERPRINT"
# add ppa apt source
local DEB_PPA="deb http://ppa.launchpad.net/$ppa/ubuntu $SUITE main"
echo "$DEB_PPA" >> config/archives/ubuntu-defaults.list
done
}
# add $REPOS
add_repos () {
for repo in $REPOS; do
# fetch GPG key from packagecloud
wget https://packagecloud.io/$repo/gpgkey -O ${repo##*/}.gpgkey && apt-key --keyring config/archives/ubuntu-defaults.key add ${repo##*/}.gpgkey
rm ${repo##*/}.gpgkey
# add packagecloud apt source
local REPO_APT="deb https://packagecloud.io/$repo/ubuntu $SUITE main"
echo "$REPO_APT" >> config/archives/ubuntu-defaults.list
done
}
# add extra packages
add_xpackages () {
for xpackage in $XPACKAGES; do
echo "$xpackage" >> config/package-lists/ubuntu-defaults.list.chroot_install
done
}
eval set -- "$(getopt -o '' -l help,locale:,keep-apt,keep-apt-components:,package:,arch:,flavor:,release:,components:,mirror:,security-mirror:,ppa:,repo:,xpackage: -- "$@")" || { help; exit 1; }
while :; do
case $1 in
--help)
help
exit 0
;;
--locale)
LOCALE="$2"
shift 2
;;
--package)
PACKAGE="$2"
# PACKAGE="$PACKAGE $2"
shift 2
;;
--xpackage)
XPACKAGES="$XPACKAGES $2"
shift 2
;;
--arch)
ARCH="$2"
shift 2
;;
--flavor)
FLAVOR="$2"
shift 2
;;
--release)
SUITE="$2"
shift 2
;;
--components)
COMPONENTS="$(echo "$2" | sed 's/,/ /g' | tr -s ' ')"
shift 2
;;
--mirror)
MIRROR="$2"
shift 2
;;
--security-mirror)
SECURITY_MIRROR="$2"
shift 2
;;
--ppa)
if ! expr match "$2" '^[.[:alnum:]-]\+/[[:alnum:]-]\+$' >/dev/null; then
echo "Invalid PPA specification, must be lp_username/ppaname" >&2
exit 1
fi
PPAS="$PPAS $2"
shift 2
;;
--repo)
if ! expr match "$2" '^[.[:alnum:]-]\+/[[:alnum:]-]\+$' >/dev/null; then
echo "Invalid packagecloud specification, must be name/repo" >&2
exit 1
fi
REPOS="$REPOS $2"
shift 2
;;
--keep-apt)
KEEP_APT_OPT="$1"
DELETE_APT_LISTS="rm -vf /var/lib/apt/lists/*_Translation-*"
shift
;;
--keep-apt-components)
KEEP_APT_OPT="$1"
components="$(echo "$2" | sed 's/,/ /g')"
DELETE_APT_LISTS="rm -vf /var/lib/apt/lists/*_Translation-*
rm -vf /var/lib/apt/lists/*_main_*
rm -vf /var/lib/apt/lists/*_restricted_*
rm -vf /var/lib/apt/lists/*_universe_*
rm -vf /var/lib/apt/lists/*_multiverse_*"
for comp in $components; do
case $comp in
main|restricted|universe|multiverse)
DELETE_APT_LISTS=$(echo "$DELETE_APT_LISTS" | grep -v $comp)
;;
*)
echo "ERROR: unknown component $comp"
exit 1
;;
esac
done
shift 2
;;
--)
shift
break
;;
*)
help
exit 1
;;
esac
done
if ([ -z "$LOCALE" ] && [ -z "$PACKAGE" ]) || [ -z "$ARCH" ]; then
help
exit 1
fi
if ([ -n "$MIRROR" ] || [ -n "$SECURITY_MIRROR" ]) && [ -n "$KEEP_APT_OPT" ]; then
echo "ERROR: $KEEP_APT_OPT cannot currently be used along with --mirror or --security-mirror" >&2
exit 1
fi
if [ "$LOCALE" ] && [ -z "$PACKAGE" ]; then
PACKAGE="ubuntu-defaults-$(echo "$LOCALE" | tr '_A-Z' '-a-z')"
fi
if [ "$(id -u)" = 0 ]; then
SUDO=env
else
SUDO=sudo
fi
# Make sure all our dependencies (which are Recommends of our package) are
# installed. This is a bit dubious long-term, but seems to be needed to
# make autobuilds reliable.
case $ARCH in
*amd64|*i386)
$SUDO apt-get -y install syslinux-themes-ubuntu syslinux-themes-ubuntu-$SUITE gfxboot-theme-ubuntu memtest86+ syslinux || exit 1
;;
esac
$SUDO apt-get -y install genisoimage
rm -rf auto
mkdir -p auto
for f in config build clean; do
ln -s "/usr/share/livecd-rootfs/live-build/auto/$f" auto/
done
$SUDO lb clean
rm -f .stage/config
SUITE="$SUITE" PROJECT="$FLAVOR" ARCH="$ARCH" LB_ARCHITECTURES="$ARCH" \
LB_MIRROR_BOOTSTRAP="$MIRROR" LB_MIRROR_CHROOT_SECURITY="$SECURITY_MIRROR" \
IMAGEFORMAT=squashfs BINARYFORMAT=iso-hybrid lb config
if [ "$COMPONENTS" ]; then
sed -i "s/^\\(LB_PARENT_ARCHIVE_AREAS=\\).*/\\1\"$COMPONENTS\"/" \
config/bootstrap
fi
# Include HTTPS for apt in bootstrap
sed -i "s/^\\(LB_BOOTSTRAP_INCLUDE=\\).*/\\1\"gnupg libcurl3-gnutls apt-transport-https ca-certificates\"/" \
config/bootstrap
sed -i "s/^\\(LB_SYSLINUX_THEME=\\).*/\\1\"ubuntu-$SUITE\"/" config/binary
if [ "${PACKAGE%.deb}" = "$PACKAGE" ]; then
# package name, apt-get'able
echo "$PACKAGE" >> config/package-lists/ubuntu-defaults.list.chroot_install
else
# local deb
cp "$PACKAGE" config/packages.chroot/
fi
if [ -n "$PPAS" ]; then
add_ppas
fi
if [ -n "$REPOS" ]; then
add_repos
fi
if [ -n "$XPACKAGES" ]; then
add_xpackages
fi
PACKAGENAME=${PACKAGE%%_*}
PACKAGENAME=${PACKAGENAME##*/}
# install language support hook (try the one from the source tree first)
HOOK=$(dirname $(readlink -f $0))/../lib/language-support-hook
if ! [ -e "$HOOK" ]; then
HOOK=/usr/share/ubuntu-defaults-builder/language-support-hook
fi
sed "s/#DEFAULTS_PACKAGE#/$PACKAGENAME/" < "$HOOK" > config/hooks/00_language-support.chroot
# work around live-build failure with lzma initramfs (Debian #637979)
sed -i 's/^LB_INITRAMFS_COMPRESSION="lzma"/LB_INITRAMFS_COMPRESSION="gzip"/' config/common
# run hooks from defaults package
cat <<EOF > config/hooks/10_ubuntu-defaults.chroot
#!/bin/sh
set -e
HOOK=/usr/share/$PACKAGENAME/hooks/chroot
if [ -x \$HOOK ]; then
\$HOOK
fi
EOF
# clean up files that we do not need
cat <<EOF > config/hooks/90_cleanup.chroot
#!/bin/sh
set -e
echo "$0: Removing unnecessary files..."
rm -vf /var/cache/apt/*cache.bin
$DELETE_APT_LISTS
rm -vrf /tmp/*
EOF
# rename kernel and initrd to what syslinux expects
cat <<EOF > config/hooks/rename-kernel.binary
#!/bin/sh -e
if [ ! -e binary/casper/initrd.lz ]; then
echo "\$0: Renaming initramfs to initrd.lz..."
zcat binary/casper/initrd.img-* | lzma -c > binary/casper/initrd.lz
rm binary/casper/initrd.img-*
fi
if [ ! -e binary/casper/vmlinuz ]; then
echo "\$0: Renaming kernel to vmlinuz..."
# This will go wrong if there's ever more than one vmlinuz-* after
# excluding *.efi.signed. We can deal with that if and when it arises.
for x in binary/casper/vmlinuz-*; do
case \$x in
*.efi.signed)
;;
*)
mv \$x binary/casper/vmlinuz
if [ -e "\$x.efi.signed" ]; then
mv \$x.efi.signed binary/casper/vmlinuz.efi
fi
;;
esac
done
fi
EOF
# set default language
cat <<EOF > config/hooks/default-language.binary
#!/bin/sh -e
LOC=chroot/usr/share/$PACKAGENAME/language.txt
if [ -e "\$LOC" ]; then
echo "\$0: \$LOC exists, setting gfxboot default language..."
cp "\$LOC" binary/isolinux/lang
echo >> binary/isolinux/lang
else
echo "\$0: \$LOC does not exist, not setting gfxboot default language"
fi
EOF
DISPLAY= $SUDO PROJECT="$FLAVOR" ARCH="$ARCH" lb build