~ubuntu-on-ec2/ubuntu-on-ec2/live-build

« back to all changes in this revision

Viewing changes to scripts/build/lb_chroot_archives

  • Committer: Scott Moser
  • Date: 2011-07-28 16:07:31 UTC
  • mfrom: (1810.1.35)
  • Revision ID: smoser@ubuntu.com-20110728160731-9rrfmzjae4nr7fwz
* Using updated kernel default flavours for sid also for wheezy.
* Adding live-manual to recommends.
* Adding initial live-build-cron package.
[ Richard Nelson ]
* Move lxde package-lists to use gdm3 instead of gdm.
* Remove lxde test on LB_TASKS for gdm so we now get gdm3.
[ Daniel Baumann ]
* Correct gdm/gdm3 handling, prefere gdm for squeeze as before and use
  gdm3 for everything else.
* Adding extlinux to rescue package list.
* Adding live-boot-doc to recommends.
* Adding live-config-doc to recommends.
* Correcting wrong chroot call in chroot_archives, only affecting
  derivatives.
[ Daniel Baumann ]
* Using -wildcards option when calling mksquashfs with an excludes
  file.
[ Colin Watson ]
* Make --architectures armel only fail if --linux-flavours was not
  passed (Closes: #630464).
[ Daniel Baumann ]
* Renaming repositories option to archives for consistency with
  debian-policy terminology.
* Renaming chroot_sources script to chroot_archives for consistency
  with debian-policy terminology.
* Unifying config/chroot_archives and config/archives, now only using
  config/archives.
* Setting default distribution to wheezy (at least until #622838 is
  handled).
* Changing archives key suffix from .gpg to .key.
* Using .list suffix in config/archives.
* Unifying config/chroot_local-packagelists and config/binary_local-
  packagelists.
* Moving internal global package lists from 'lists' to 'package-
  lists'. This is not a user visible change.
* Moving config/chroot_local-tasklists/*.list to config/task-
  lists/*.chroot.list, analogue to config/package-lists.
* Since we don't have global tasks anymore, renaming lb_chroot_local-
  tasklists to lb_chroot_task-lists.
* Since we don't have global packages anymore, renaming
  lb_chroot_local-packages to lb_chroot_packages and
  config/chroot_local-packages to config/chroot_packages.
[ Colin Watson ]
* Fix default for LB_PARENT_ARCHIVE_AREAS (Closes: #630604).
[ Daniel Baumann ]
* Correct rmdir call in top-level Makefiles uninstall target to not
  fail if there was no prior live-build installation.
* Adjust name of archives directory in config tree.
* Removing forgotten reference to chroot_packages in lb_chroot.
* Correct keyring packages temporary workaround to not fail when
  aptitude is selected (Closes: #630919).
* Making copyright file distribution neutral.
* Making copyright headers distribution neutral.
* Making help message about missing po4a in manpages makefile
  distribution neutral.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
## live-build(7) - System Build Scripts
 
4
## Copyright (C) 2006-2011 Daniel Baumann <daniel@debian.org>
 
5
##
 
6
## live-build comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
 
7
## This is free software, and you are welcome to redistribute it
 
8
## under certain conditions; see COPYING for details.
 
9
 
 
10
 
 
11
set -e
 
12
 
 
13
# Including common functions
 
14
. "${LB_BASE:-/usr/share/live/build}"/scripts/build.sh
 
15
 
 
16
# Setting static variables
 
17
DESCRIPTION="$(Echo 'manage /etc/apt/sources.list')"
 
18
HELP=""
 
19
USAGE="${PROGRAM} {install|remove} [--force]"
 
20
 
 
21
Arguments "${@}"
 
22
 
 
23
# Reading configuration files
 
24
Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
 
25
Set_defaults
 
26
 
 
27
# Requiring stage file
 
28
Require_stagefile .stage/config .stage/bootstrap
 
29
 
 
30
_LB_LOCAL_KEY_EMAIL="live-build-local-key@invalid"
 
31
 
 
32
case "${1}" in
 
33
        install)
 
34
                Echo_message "Configuring file /etc/apt/sources.list"
 
35
 
 
36
                # Checking stage file
 
37
                Check_stagefile .stage/chroot_archives
 
38
 
 
39
                # Checking lock file
 
40
                Check_lockfile .lock
 
41
 
 
42
                # Creating lock file
 
43
                Create_lockfile .lock
 
44
 
 
45
                # Restoring cache
 
46
                Restore_cache cache/packages_chroot
 
47
 
 
48
                # Configure custom sources.list
 
49
 
 
50
cat > chroot/etc/apt/sources.list << EOF
 
51
# /etc/apt/sources.list
 
52
 
 
53
deb ${LB_PARENT_MIRROR_CHROOT} ${LB_PARENT_DISTRIBUTION} ${LB_PARENT_ARCHIVE_AREAS}
 
54
EOF
 
55
 
 
56
                if [ "${LB_SOURCE}" = "true" ]
 
57
                then
 
58
                        echo "deb-src ${LB_PARENT_MIRROR_CHROOT} ${LB_PARENT_DISTRIBUTION} ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
59
                fi
 
60
 
 
61
                if [ "${LB_DERIVATIVE}" = "true" ]
 
62
                then
 
63
 
 
64
cat > chroot/etc/apt/sources.list.d/${LB_MODE}.list << EOF
 
65
# /etc/apt/sources.list.d/${LB_MODE}.list
 
66
 
 
67
EOF
 
68
 
 
69
                        case "${LB_DISTRIBUTION}" in
 
70
                                *-backports)
 
71
                                        _DISTRIBUTIONS="$(echo ${LB_DISTRIBUTION} | sed -e 's|-backports||') ${LB_DISTRIBUTION}"
 
72
                                        ;;
 
73
 
 
74
                                *)
 
75
                                        _DISTRIBUTIONS="${LB_DISTRIBUTION}"
 
76
                                        ;;
 
77
                        esac
 
78
 
 
79
                        for _DISTRIBUTION in ${_DISTRIBUTIONS}
 
80
                        do
 
81
 
 
82
                                echo "deb ${LB_MIRROR_CHROOT} ${_DISTRIBUTION} ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
83
 
 
84
                                if [ "${LB_SOURCE}" = "true" ]
 
85
                                then
 
86
                                        echo "deb-src ${LB_MIRROR_CHROOT} ${_DISTRIBUTION} ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
87
                                fi
 
88
                        done
 
89
                fi
 
90
 
 
91
                if [ "${LB_SECURITY}" = "true" ]
 
92
                then
 
93
                        case "${LB_MODE}" in
 
94
                                debian|progress)
 
95
                                        case "${LB_PARENT_DISTRIBUTION}" in
 
96
                                                sid|wheezy)
 
97
 
 
98
                                                        ;;
 
99
 
 
100
                                                *)
 
101
                                                        echo "deb ${LB_PARENT_MIRROR_CHROOT_SECURITY} ${LB_PARENT_DISTRIBUTION}/updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
102
 
 
103
                                                        if [ "${LB_SOURCE}" = "true" ]
 
104
                                                        then
 
105
                                                                echo "deb-src ${LB_PARENT_MIRROR_CHROOT_SECURITY} ${LB_PARENT_DISTRIBUTION}/updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
106
                                                        fi
 
107
                                                        ;;
 
108
                                        esac
 
109
 
 
110
                                        if [ "${LB_MODE}" = progress ]
 
111
                                        then
 
112
                                                case "${LB_DISTRIBUTION}" in
 
113
                                                        *-backports)
 
114
 
 
115
                                                                ;;
 
116
 
 
117
                                                        *)
 
118
                                                                echo "deb ${LB_MIRROR_CHROOT_SECURITY} ${LB_DISTRIBUTION}-security ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
119
 
 
120
                                                                if [ "${LB_SOURCE}" = "true" ]
 
121
                                                                then
 
122
                                                                        echo "deb-src ${LB_MIRROR_CHROOT_SECURITY} ${LB_DISTRIBUTION}-security ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
123
                                                                fi
 
124
                                                                ;;
 
125
                                                esac
 
126
                                        else
 
127
                                                if [ "${LB_DERIVATIVE}" = "true" ]
 
128
                                                then
 
129
                                                        echo "deb ${LB_MIRROR_CHROOT_SECURITY} ${LB_DISTRIBUTION}/updates ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
130
 
 
131
                                                        if [ "${LB_SOURCE}" = "true" ]
 
132
                                                        then
 
133
                                                                echo "deb-src ${LB_MIRROR_CHROOT_SECURITY} ${LB_DISTRIBUTION}/updates ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
134
                                                        fi
 
135
                                                fi
 
136
                                        fi
 
137
                                        ;;
 
138
 
 
139
                                ubuntu)
 
140
                                        echo "deb ${LB_PARENT_MIRROR_CHROOT_SECURITY} ${LB_PARENT_DISTRIBUTION}-security ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
141
 
 
142
                                        if [ "${LB_SOURCE}" = "true" ]
 
143
                                        then
 
144
                                                echo "deb-src ${LB_PARENT_MIRROR_CHROOT_SECURITY} ${LB_PARENT_DISTRIBUTION}-security ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
145
                                        fi
 
146
                                        ;;
 
147
                        esac
 
148
                fi
 
149
 
 
150
                if [ "${LB_VOLATILE}" = "true" ]
 
151
                then
 
152
                        case "${LB_MODE}" in
 
153
                                debian|ubuntu)
 
154
                                        echo "deb ${LB_PARENT_MIRROR_CHROOT_VOLATILE} ${LB_PARENT_DISTRIBUTION}-updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
155
 
 
156
                                        if [ "${LB_SOURCE}" = "true" ]
 
157
                                        then
 
158
                                                echo "deb-src ${LB_PARENT_MIRROR_CHROOT_VOLATILE} ${LB_PARENT_DISTRIBUTION}-updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
159
                                        fi
 
160
                                        ;;
 
161
                        esac
 
162
 
 
163
                        if [ "${LB_DERIVATIVE}" = "true" ] && [ "${LB_MIRROR_CHROOT_VOLATILE}" != "none" ]
 
164
                        then
 
165
                                echo "deb ${LB_MIRROR_CHROOT_VOLATILE} ${LB_PARENT_DISTRIBUTION}-updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
166
 
 
167
                                if [ "${LB_SOURCE}" = "true" ]
 
168
                                then
 
169
                                        echo "deb-src ${LB_PARENT_MIRROR_CHROOT_VOLATILE} ${LB_PARENT_DISTRIBUTION}-updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
170
                                fi
 
171
                        fi
 
172
                fi
 
173
 
 
174
                if [ "${LB_BACKPORTS}" = "true" ]
 
175
                then
 
176
                        case "${LB_MODE}" in
 
177
                                debian)
 
178
                                        if [ "${LB_PARENT_DISTRIBUTION}" != "sid" ]
 
179
                                        then
 
180
                                                echo "deb ${LB_PARENT_MIRROR_CHROOT_BACKPORTS} ${LB_PARENT_DISTRIBUTION}-backports ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
181
 
 
182
                                                if [ "${LB_SOURCE}" = "true" ]
 
183
                                                then
 
184
                                                        echo "deb-src ${LB_PARENT_MIRROR_CHROOT_BACKPORTS} ${LB_PARENT_DISTRIBUTION}-backports ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
185
                                                fi
 
186
                                        fi
 
187
                                        ;;
 
188
                        esac
 
189
 
 
190
                        if [ "${LB_DERIVATIVE}" = "true" ] && [ "${LB_MIRROR_CHROOT_BACKPORTS}" != "none" ]
 
191
                        then
 
192
                                echo "deb ${LB_MIRROR_CHROOT_BACKPORTS} ${LB_DISTRIBUTION}-backports ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
193
 
 
194
                                if [ "${LB_SOURCE}" = "true" ]
 
195
                                then
 
196
                                        echo "deb-src ${LB_MIRROR_CHROOT_BACKPORTS} ${LB_DISTRIBUTION}-backports ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
197
                                fi
 
198
                        fi
 
199
                fi
 
200
 
 
201
                # Configure third-party archives
 
202
                if [ -n "${LB_ARCHIVES}" ]
 
203
                then
 
204
                        for REPOSITORY in ${LB_ARCHIVES}
 
205
                        do
 
206
                                # ubuntu workaround to allow using live.debian.net
 
207
                                if [ "${LB_MODE}" = "ubuntu" ] && [ "${REPOSITORY}" = "live.debian.net" ]
 
208
                                then
 
209
                                        _DISTRIBUTION="sid"
 
210
                                else
 
211
                                        _DISTRIBUTION="${LB_PARENT_DISTRIBUTION}"
 
212
                                fi
 
213
 
 
214
                                # Prefer archives from the config tree
 
215
                                # over the global ones.
 
216
                                if ! ls "${LB_BASE}/archives/${REPOSITORY}"* > /dev/null 2>&1
 
217
                                then
 
218
                                        continue
 
219
                                fi
 
220
 
 
221
                                # Adding sources.list entries (chroot)
 
222
                                if [ -e "${LB_BASE}/archives/${REPOSITORY}.chroot" ]
 
223
                                then
 
224
                                        sed -e "s|@DISTRIBUTION@|${_DISTRIBUTION}|g" \
 
225
                                            -e "s|@ARCHIVE_AREAS@|${LB_PARENT_ARCHIVE_AREAS}|g" \
 
226
                                        "${LB_BASE}/archives/${REPOSITORY}.chroot" > \
 
227
                                        "chroot/etc/apt/sources.list.d/${REPOSITORY}.list"
 
228
                                elif [ -e "${LB_BASE}/archives/${REPOSITORY}" ]
 
229
                                then
 
230
                                        sed -e "s|@DISTRIBUTION@|${_DISTRIBUTION}|g" \
 
231
                                            -e "s|@ARCHIVE_AREAS@|${LB_PARENT_ARCHIVE_AREAS}|g" \
 
232
                                        "${LB_BASE}/archives/${REPOSITORY}" > \
 
233
                                        "chroot/etc/apt/sources.list.d/${REPOSITORY}.list"
 
234
                                fi
 
235
 
 
236
                                if [ "${LB_APT_SECURE}" != false ]
 
237
                                then
 
238
                                        # Adding archive signing keys (chroot)
 
239
                                        if [ -e "${LB_BASE}/archives/${REPOSITORY}.chroot.key" ]
 
240
                                        then
 
241
                                                cat "${LB_BASE}/archives/${REPOSITORY}.chroot.key" | Chroot chroot "apt-key add -"
 
242
                                        elif [ -e "${LB_BASE}/archives/${REPOSITORY}.key" ]
 
243
                                        then
 
244
                                                cat "${LB_BASE}/archives/${REPOSITORY}.key" | Chroot chroot "apt-key add -"
 
245
                                        fi
 
246
                                fi
 
247
                        done
 
248
                fi
 
249
 
 
250
                # Check local sources.list
 
251
                if Find_files config/archives/*.chroot.list
 
252
                then
 
253
                        for FILE in config/archives/*.chroot.list
 
254
                        do
 
255
                                sed -e "s|@DISTRIBUTION@|${LB_DISTRIBUTION}|g" \
 
256
                                    -e "s|@ARCHIVE_AREAS@|${LB_ARCHIVE_AREAS}|g" \
 
257
                                    -e "s|@PARENT_DISTRIBUTION@|${LB_PARENT_DISTRIBUTION}|g" \
 
258
                                    -e "s|@PARENT_ARCHIVE_AREAS@|${LB_PARENT_ARCHIVE_AREAS}|g" \
 
259
                                "${FILE}" > "chroot/etc/apt/sources.list.d/$(basename ${FILE} .chroot.list).list"
 
260
                        done
 
261
                fi
 
262
 
 
263
                # Configure local package repository
 
264
                if Find_files config/chroot_packages/*.deb
 
265
                then
 
266
                        rm -rf chroot/root/packages
 
267
                        mkdir -p chroot/root/packages
 
268
 
 
269
                        if [ "$(stat --printf %d config/chroot_packages)" = "$(stat --printf %d chroot/root/packages)" ]
 
270
                        then
 
271
                                CP_OPTIONS="-l"
 
272
                        fi
 
273
 
 
274
                        # Copy packages
 
275
                        if Find_files config/chroot_packages/*_"${LB_ARCHITECTURES}".deb
 
276
                        then
 
277
                                for FILE in config/chroot_packages/*_"${LB_ARCHITECTURES}".deb
 
278
                                do
 
279
                                        if [ -L "${FILE}" ]
 
280
                                        then
 
281
                                                cp -L config/chroot_packages/*_"${LB_ARCHITECTURES}".deb chroot/root/packages
 
282
                                        else
 
283
                                                cp ${CP_OPTIONS} config/chroot_packages/*_"${LB_ARCHITECTURES}".deb chroot/root/packages
 
284
                                        fi
 
285
                                done
 
286
                        fi
 
287
 
 
288
                        if Find_files config/chroot_packages/*_all.deb
 
289
                        then
 
290
                                for FILE in config/chroot_packages/*_all.deb
 
291
                                do
 
292
                                        if [ -L "${FILE}" ]
 
293
                                        then
 
294
                                                cp -L config/chroot_packages/*_all.deb chroot/root/packages
 
295
                                        else
 
296
                                                cp ${CP_OPTIONS} config/chroot_packages/*_all.deb chroot/root/packages
 
297
                                        fi
 
298
                                done
 
299
                        fi
 
300
 
 
301
                        if Find_files chroot/root/packages/*.deb
 
302
                        then
 
303
                                # If we bootstrapped a minimal chroot, we need
 
304
                                # to install apt-utils before we have have
 
305
                                # completed all the indices.
 
306
                                case "${LB_PACKAGE_LISTS}" in
 
307
                                        stripped|minimal)
 
308
                                                Apt chroot update
 
309
                                                ;;
 
310
                                esac
 
311
 
 
312
                                # Check depends
 
313
                                Check_package chroot/usr/bin/apt-ftparchive apt-utils
 
314
 
 
315
                                # Installing depends
 
316
                                Install_package
 
317
 
 
318
                                # Generate Packages and Packages.gz 
 
319
                                echo "cd /root/packages && apt-ftparchive packages . > Packages" | Chroot chroot sh
 
320
                                gzip -9 -c chroot/root/packages/Packages > chroot/root/packages/Packages.gz
 
321
 
 
322
                                # Generate Release
 
323
                                echo "cd /root/packages && apt-ftparchive \
 
324
                                        -o APT::FTPArchive::Release::Origin=chroot_packages \
 
325
                                        release . > Release" | Chroot chroot sh
 
326
 
 
327
                                if [ "${LB_APT_SECURE}" = "true" ]
 
328
                                then
 
329
                                        _LB_DOTGNUPG_EXISTED=0
 
330
                                        if [ -d chroot/root/.gnupg ]
 
331
                                        then
 
332
                                                _LB_DOTGNUPG_EXISTED=1
 
333
                                        fi
 
334
 
 
335
                                        # Ensure ~/.gnupg exists (required for gnupg >= ~1.4.9)
 
336
                                        mkdir -p chroot/root/.gnupg
 
337
 
 
338
                                        # Temporarily replace /dev/random with /dev/urandom so as not
 
339
                                        # to block automated image builds; we don't care about the
 
340
                                        # security of this key anyway.
 
341
                                        if [ -e chroot/dev/random ]
 
342
                                        then
 
343
                                                mv chroot/dev/random chroot/dev/random.orig
 
344
                                                cp -a chroot/dev/urandom chroot/dev/random
 
345
                                        fi
 
346
 
 
347
                                        if Find_files cache/local-package-keyring.*
 
348
                                        then
 
349
                                                cp cache/local-package-keyring.* chroot/root
 
350
                                        else
 
351
                                                # Generate temporary key
 
352
                                                echo "Key-Type: RSA
 
353
                                                      Key-Length: 1024
 
354
                                                      Subkey-Type: ELG-E
 
355
                                                      Subkey-Length: 1024
 
356
                                                      Name-Real: live-build local packages key
 
357
                                                      Name-Email: ${_LB_LOCAL_KEY_EMAIL}
 
358
                                                      Expire-Date: 0
 
359
                                                      %secring /root/local-package-keyring.sec
 
360
                                                      %pubring /root/local-package-keyring.pub
 
361
                                                      %commit" | Chroot chroot "gpg --batch --gen-key" || _LB_RET=${?}
 
362
 
 
363
                                                case "${_LB_RET}" in
 
364
                                                        ""|2)
 
365
                                                                # Gnupg sometimes seems to return with a status of 2 when there was not
 
366
                                                                # enough entropy (and key creation blocks temporarily) even if the
 
367
                                                                # operation was ultimately successful.
 
368
                                                                ;;
 
369
                                                        *)
 
370
                                                                Echo_error "GPG exited with error status %s" "${_LB_RET}"
 
371
                                                                exit ${_LB_RET}
 
372
                                                                ;;
 
373
                                                esac
 
374
 
 
375
                                                # Save keyrings to avoid regeneration
 
376
                                                cp chroot/root/local-package-keyring.* cache/
 
377
                                        fi
 
378
 
 
379
                                        # Sign release
 
380
                                        Chroot chroot "gpg --no-default-keyring --secret-keyring /root/local-package-keyring.sec \
 
381
                                                --keyring /root/local-package-keyring.pub -abs -o \
 
382
                                                /root/packages/Release.gpg /root/packages/Release"
 
383
 
 
384
                                        # Import key
 
385
                                        Chroot chroot "gpg --no-default-keyring --secret-keyring /root/local-package-keyring.sec \
 
386
                                                --keyring /root/local-package-keyring.pub --armor \
 
387
                                                --export ${_LB_LOCAL_KEY_EMAIL}" | Chroot chroot "apt-key add -"
 
388
 
 
389
                                        # Remove temporary keyrings
 
390
                                        rm chroot/root/local-package-keyring.pub
 
391
                                        rm chroot/root/local-package-keyring.sec
 
392
 
 
393
                                        # Revert /dev/random
 
394
                                        if [ -e chroot/dev/random.orig ]
 
395
                                        then
 
396
                                                mv chroot/dev/random.orig chroot/dev/random
 
397
                                        fi
 
398
 
 
399
                                        # Remove /root/.gnupg if we created it during the signing process
 
400
                                        if [ "${_LB_DOTGNUPG_EXISTED}" -eq 0 ]
 
401
                                        then
 
402
                                                rm -rf chroot/root/.gnupg
 
403
                                        fi
 
404
                                fi
 
405
 
 
406
                                # Add to sources.list.d
 
407
                                echo "deb file:/root/packages ./" > chroot/etc/apt/sources.list.d/packages.list
 
408
 
 
409
                                # Removing depends
 
410
                                Remove_package
 
411
                        else
 
412
                                Echo_warning "Local packages must be named with suffix '_all.deb' or '_\$architecture.deb'."
 
413
                        fi
 
414
                fi
 
415
 
 
416
                # Update indices from cache
 
417
                if [ "${LB_CACHE_INDICES}" = "true" ] && [ -d cache/indices_bootstrap ]
 
418
                then
 
419
                        if Find_files cache/indices_bootstrap/secring.gpg*
 
420
                        then
 
421
                                cp -f cache/indices_bootstrap/secring.gpg* chroot/etc/apt
 
422
                        fi
 
423
 
 
424
                        if Find_files cache/indices_bootstrap/trusted.gpg*
 
425
                        then
 
426
                                cp -rf cache/indices_bootstrap/trusted.gpg* chroot/etc/apt
 
427
                        fi
 
428
 
 
429
                        if [ -f cache/indices_bootstrap/pkgcache.bin ]
 
430
                        then
 
431
                                cp -f cache/indices_bootstrap/pkgcache.bin chroot/var/cache/apt
 
432
                        fi
 
433
 
 
434
                        if [ -f cache/indices_bootstrap/srcpkgcache.bin ]
 
435
                        then
 
436
                                cp -f cache/indices_bootstrap/srcpkgcache.bin chroot/var/cache/apt
 
437
                        fi
 
438
 
 
439
                        if Find_files cache/indices_bootstrap/*_Packages
 
440
                        then
 
441
                                cp -f cache/indices_bootstrap/*_Packages chroot/var/lib/apt/lists
 
442
                        fi
 
443
 
 
444
                        if Find_files cache/indices_bootstrap/*_Sources
 
445
                        then
 
446
                                cp -f cache/indices_bootstrap/*_Sources chroot/var/lib/apt/lists
 
447
                        fi
 
448
 
 
449
                        if Find_files cache/indices_bootstrap/*Release*
 
450
                        then
 
451
                                cp -f cache/indices_bootstrap/*Release* chroot/var/lib/apt/lists
 
452
                        fi
 
453
 
 
454
                        if [ "${LB_APT}" = "aptitude" ] && [ ! -x /usr/bin/aptitude ]
 
455
                        then
 
456
                                Chroot chroot "apt-get ${APT_OPTIONS} update"
 
457
                                Chroot chroot "apt-get ${APT_OPTIONS} install aptitude"
 
458
                        fi
 
459
                else # Get fresh indices
 
460
                        # Check local archive keys
 
461
                        if Find_files config/archives/*.chroot.key
 
462
                        then
 
463
                                for FILE in config/archives/*.chroot.key
 
464
                                do
 
465
                                        cp ${FILE} chroot/root
 
466
                                        Chroot chroot "apt-key add /root/$(basename ${FILE})"
 
467
                                        rm -f chroot/root/$(basename ${FILE})
 
468
                                done
 
469
                        fi
 
470
 
 
471
                        # Check local keyring packages
 
472
                        if Find_files config/archives/*.deb
 
473
                        then
 
474
                                for PACKAGE in config/archives/*.deb
 
475
                                do
 
476
                                        cp ${PACKAGE} chroot/root
 
477
                                        Chroot chroot "dpkg -i /root/$(basename ${PACKAGE})"
 
478
                                        rm -f chroot/root/$(basename ${PACKAGE})
 
479
                                done
 
480
                        fi
 
481
 
 
482
                        # Installing aptitude (FIXME)
 
483
                        if [ "${LB_APT}" = "aptitude" ] && [ ! -x /usr/bin/aptitude ]
 
484
                        then
 
485
                                Chroot chroot "apt-get ${APT_OPTIONS} update"
 
486
                                Chroot chroot "apt-get ${APT_OPTIONS} install aptitude"
 
487
                        fi
 
488
 
 
489
                        # Rebuild apt indices from scratch.
 
490
                        # Due to the fact that apt doesn't understand
 
491
                        # pinning on the fly, we need to manually remove
 
492
                        # the cached indices and rebuild them again.
 
493
                        rm -rf chroot/var/cache/apt/*.bin
 
494
 
 
495
                        Apt chroot update
 
496
 
 
497
                        # Installing keyring packages
 
498
                        if [ -n "${LB_KEYRING_PACKAGES}" ]
 
499
                        then
 
500
                                if [ "${LB_DERIVATIVE}" = "true" ]
 
501
                                then
 
502
                                        # Temporary hack (FIXME)
 
503
                                        Chroot chroot "apt-get ${APT_OPTIONS} --force-yes install ${LB_KEYRING_PACKAGES}"
 
504
                                else
 
505
                                        Apt chroot "install ${LB_KEYRING_PACKAGES}"
 
506
                                fi
 
507
                        fi
 
508
 
 
509
                        rm -rf chroot/var/cache/apt/*.bin
 
510
 
 
511
                        Apt chroot update
 
512
                        Apt chroot "upgrade"
 
513
                        Apt chroot "dist-upgrade"
 
514
 
 
515
                        if [ "${LB_CACHE_INDICES}" = "true" ]
 
516
                        then
 
517
                                mkdir -p cache/indices_bootstrap
 
518
 
 
519
                                cp -f chroot/etc/apt/secring.gpg* cache/indices_bootstrap
 
520
                                cp -rf chroot/etc/apt/trusted.gpg* cache/indices_bootstrap
 
521
 
 
522
                                cp -f chroot/var/cache/apt/pkgcache.bin cache/indices_bootstrap
 
523
 
 
524
                                if Find_files chroot/var/cache/apt/srcpkgcache.bin
 
525
                                then
 
526
                                        cp -f chroot/var/cache/apt/srcpkgcache.bin cache/indices_bootstrap
 
527
                                fi
 
528
 
 
529
                                cp -f chroot/var/lib/apt/lists/*_Packages cache/indices_bootstrap
 
530
 
 
531
                                if Find_files chroot/var/lib/apt/lists/*_Sources
 
532
                                then
 
533
                                        cp -f chroot/var/lib/apt/lists/*_Sources cache/indices_bootstrap
 
534
                                fi
 
535
 
 
536
                                cp -f chroot/var/lib/apt/lists/*Release* cache/indices_bootstrap
 
537
                        fi
 
538
                fi
 
539
 
 
540
                # Saving cache
 
541
                Save_cache cache/packages_chroot
 
542
 
 
543
                # Creating stage file
 
544
                Create_stagefile .stage/chroot_archives
 
545
                ;;
 
546
 
 
547
        remove)
 
548
                Echo_message "Deconfiguring file /etc/apt/sources.list"
 
549
 
 
550
                # Checking lock file
 
551
                Check_lockfile .lock
 
552
 
 
553
                # Creating lock file
 
554
                Create_lockfile .lock
 
555
 
 
556
                # Configure generic indices
 
557
                # Don't do anything if it's not required
 
558
                if [ "${LB_PARENT_MIRROR_CHROOT}" = "${LB_PARENT_MIRROR_BINARY}" ] && \
 
559
                [ "${LB_PARENT_MIRROR_CHROOT_SECURITY}" = "${LB_PARENT_MIRROR_BINARY_SECURITY}" ] && \
 
560
                [ ! -d chroot/root/packages ]
 
561
                then
 
562
                        # Removing stage file
 
563
                        rm -f .stage/chroot_archives
 
564
 
 
565
                        exit 0
 
566
                fi
 
567
 
 
568
                # Cleaning apt list cache
 
569
                rm -rf chroot/var/lib/apt/lists
 
570
                mkdir -p chroot/var/lib/apt/lists/partial
 
571
 
 
572
                # Configure custom sources.list
 
573
 
 
574
cat > chroot/etc/apt/sources.list << EOF
 
575
# /etc/apt/sources.list
 
576
 
 
577
deb ${LB_PARENT_MIRROR_BINARY} ${LB_PARENT_DISTRIBUTION} ${LB_PARENT_ARCHIVE_AREAS}
 
578
EOF
 
579
 
 
580
                if [ "${LB_SOURCE}" = "true" ]
 
581
                then
 
582
                        echo "deb-src ${LB_PARENT_MIRROR_BINARY} ${LB_PARENT_DISTRIBUTION} ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
583
                fi
 
584
 
 
585
                if [ "${LB_DERIVATIVE}" = "true" ]
 
586
                then
 
587
 
 
588
cat > chroot/etc/apt/sources.list.d/${LB_MODE}.list << EOF
 
589
# /etc/apt/sources.list.d/${LB_MODE}.list
 
590
 
 
591
EOF
 
592
 
 
593
                        case "${LB_DISTRIBUTION}" in
 
594
                                *-backports)
 
595
                                        _DISTRIBUTIONS="$(echo ${LB_DISTRIBUTION} | sed -e 's|-backports||') ${LB_DISTRIBUTION}"
 
596
                                        ;;
 
597
 
 
598
                                *)
 
599
                                        _DISTRIBUTIONS="${LB_DISTRIBUTION}"
 
600
                                        ;;
 
601
                        esac
 
602
 
 
603
                        for _DISTRIBUTION in ${_DISTRIBUTIONS}
 
604
                        do
 
605
 
 
606
                                echo "deb ${LB_MIRROR_BINARY} ${_DISTRIBUTION} ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
607
 
 
608
                                if [ "${LB_SOURCE}" = "true" ]
 
609
                                then
 
610
                                        echo "deb-src ${LB_MIRROR_BINARY} ${_DISTRIBUTION} ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
611
                                fi
 
612
                        done
 
613
                fi
 
614
 
 
615
                if [ "${LB_SECURITY}" = "true" ]
 
616
                then
 
617
                        case "${LB_MODE}" in
 
618
                                debian|progress)
 
619
                                        case "${LB_PARENT_DISTRIBUTION}" in
 
620
                                                sid|wheezy)
 
621
 
 
622
                                                        ;;
 
623
 
 
624
                                                *)
 
625
                                                        echo "deb ${LB_PARENT_MIRROR_BINARY_SECURITY} ${LB_PARENT_DISTRIBUTION}/updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
626
 
 
627
                                                        if [ "${LB_SOURCE}" = "true" ]
 
628
                                                        then
 
629
                                                                echo "deb-src ${LB_PARENT_MIRROR_BINARY_SECURITY} ${LB_PARENT_DISTRIBUTION}/updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
630
                                                        fi
 
631
                                                        ;;
 
632
                                        esac
 
633
 
 
634
                                        if [ "${LB_MODE}" = progress ]
 
635
                                        then
 
636
                                                case "${LB_DISTRIBUTION}" in
 
637
                                                        *-backports)
 
638
 
 
639
                                                                ;;
 
640
 
 
641
                                                        *)
 
642
                                                                echo "deb ${LB_MIRROR_BINARY_SECURITY} ${LB_DISTRIBUTION}-security ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
643
 
 
644
                                                                if [ "${LB_SOURCE}" = "true" ]
 
645
                                                                then
 
646
                                                                        echo "deb-src ${LB_MIRROR_BINARY_SECURITY} ${LB_DISTRIBUTION}-security ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
647
                                                                fi
 
648
                                                                ;;
 
649
                                                esac
 
650
                                        else
 
651
                                                if [ "${LB_DERIVATIVE}" = "true" ]
 
652
                                                then
 
653
                                                        echo "deb ${LB_MIRROR_BINARY_SECURITY} ${LB_DISTRIBUTION}/updates ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
654
 
 
655
                                                        if [ "${LB_SOURCE}" = "true" ]
 
656
                                                        then
 
657
                                                                echo "deb-src ${LB_MIRROR_BINARY_SECURITY} ${LB_DISTRIBUTION}/updates ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
658
                                                        fi
 
659
                                                fi
 
660
                                        fi
 
661
                                        ;;
 
662
 
 
663
                                ubuntu)
 
664
                                        echo "deb ${LB_PARENT_MIRROR_BINARY_SECURITY} ${LB_PARENT_DISTRIBUTION}-security ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
665
 
 
666
                                        if [ "${LB_SOURCE}" = "true" ]
 
667
                                        then
 
668
                                                echo "deb-src ${LB_PARENT_MIRROR_BINARY_SECURITY} ${LB_PARENT_DISTRIBUTION}-security ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
669
                                        fi
 
670
                                        ;;
 
671
                        esac
 
672
                fi
 
673
 
 
674
                if [ "${LB_VOLATILE}" = "true" ]
 
675
                then
 
676
                        case "${LB_MODE}" in
 
677
                                debian|ubuntu)
 
678
                                        echo "deb ${LB_PARENT_MIRROR_BINARY_VOLATILE} ${LB_PARENT_DISTRIBUTION}-updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
679
 
 
680
                                        if [ "${LB_SOURCE}" = "true" ]
 
681
                                        then
 
682
                                                echo "deb-src ${LB_PARENT_MIRROR_BINARY_VOLATILE} ${LB_PARENT_DISTRIBUTION}-updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
683
                                        fi
 
684
                                        ;;
 
685
                        esac
 
686
 
 
687
                        if [ "${LB_DERIVATIVE}" = "true" ] && [ "${LB_MIRROR_BINARY_VOLATILE}" != "none" ]
 
688
                        then
 
689
                                echo "deb ${LB_MIRROR_BINARY_VOLATILE} ${LB_PARENT_DISTRIBUTION}-updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
690
 
 
691
                                if [ "${LB_SOURCE}" = "true" ]
 
692
                                then
 
693
                                        echo "deb-src ${LB_PARENT_MIRROR_BINARY_VOLATILE} ${LB_PARENT_DISTRIBUTION}-updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
694
                                fi
 
695
                        fi
 
696
                fi
 
697
 
 
698
                if [ "${LB_BACKPORTS}" = "true" ]
 
699
                then
 
700
                        case "${LB_MODE}" in
 
701
                                debian)
 
702
                                        if [ "${LB_PARENT_DISTRIBUTION}" != "sid" ]
 
703
                                        then
 
704
                                                echo "deb ${LB_PARENT_MIRROR_BINARY_BACKPORTS} ${LB_PARENT_DISTRIBUTION}-backports ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
705
 
 
706
                                                if [ "${LB_SOURCE}" = "true" ]
 
707
                                                then
 
708
                                                        echo "deb-src ${LB_PARENT_MIRROR_BINARY_BACKPORTS} ${LB_PARENT_DISTRIBUTION}-backports ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list
 
709
                                                fi
 
710
                                        fi
 
711
                                        ;;
 
712
                        esac
 
713
 
 
714
                        if [ "${LB_DERIVATIVE}" = "true" ] && [ "${LB_MIRROR_BINARY_BACKPORTS}" != "none" ]
 
715
                        then
 
716
                                echo "deb ${LB_MIRROR_BINARY_BACKPORTS} ${LB_DISTRIBUTION}-backports ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
717
 
 
718
                                if [ "${LB_SOURCE}" = "true" ]
 
719
                                then
 
720
                                        echo "deb-src ${LB_MIRROR_BINARY_BACKPORTS} ${LB_DISTRIBUTION}-backports ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
 
721
                                fi
 
722
                        fi
 
723
                fi
 
724
 
 
725
                # Configure third-party archives
 
726
                if [ -n "${LB_ARCHIVES}" ]
 
727
                then
 
728
                        for REPOSITORY in ${LB_ARCHIVES}
 
729
                        do
 
730
                                # Removing sources.list entries (chroot)
 
731
                                rm -f "chroot/etc/apt/sources.list.d/${REPOSITORY}.list"
 
732
 
 
733
                                # Prefer archives from the config tree
 
734
                                # over the global ones.
 
735
                                if ! ls "${LB_BASE}/archives/${REPOSITORY}"* > /dev/null 2>&1
 
736
                                then
 
737
                                        continue
 
738
                                fi
 
739
 
 
740
                                # Adding sources.list entries (binary)
 
741
                                if [ -e "${LB_BASE}/archives/${REPOSITORY}.binary" ]
 
742
                                then
 
743
                                        sed -e "s|@DISTRIBUTION@|${LB_PARENT_DISTRIBUTION}|g" \
 
744
                                            -e "s|@ARCHIVE_AREAS@|${LB_PARENT_ARCHIVE_AREAS}|g" \
 
745
                                        "${LB_BASE}/archives/${REPOSITORY}.binary" > \
 
746
                                        "chroot/etc/apt/sources.list.d/${REPOSITORY}.list"
 
747
                                elif [ -e "${LB_BASE}/archives/${REPOSITORY}" ]
 
748
                                then
 
749
                                        sed -e "s|@DISTRIBUTION@|${LB_PARENT_DISTRIBUTION}|g" \
 
750
                                            -e "s|@ARCHIVE_AREAS@|${LB_PARENT_ARCHIVE_AREAS}|g" \
 
751
                                        "${LB_BASE}/archives/${REPOSITORY}" > \
 
752
                                        "chroot/etc/apt/sources.list.d/${REPOSITORY}.list"
 
753
                                fi
 
754
 
 
755
                                if [ "${LB_APT_SECURE}" != false ]
 
756
                                then
 
757
                                        # Adding archive signing keys (binary)
 
758
                                        if [ -e "${LB_BASE}/archives/${REPOSITORY}.binary.key" ]
 
759
                                        then
 
760
                                                cat "${LB_BASE}/archives/${REPOSITORY}.binary.key" | Chroot chroot "apt-key add -"
 
761
                                        elif [ -e "${LB_BASE}/archives/${REPOSITORY}.key" ]
 
762
                                        then
 
763
                                                cat "${LB_BASE}/archives/${REPOSITORY}.key" | Chroot chroot "apt-key add -"
 
764
                                        fi
 
765
                                fi
 
766
                        done
 
767
                fi
 
768
 
 
769
                # Check local sources.list
 
770
                if Find_files config/archives/*.binary.list
 
771
                then
 
772
                        for FILE in config/archives/*.binary.list
 
773
                        do
 
774
                                sed -e "s|@DISTRIBUTION@|${LB_DISTRIBUTION}|g" \
 
775
                                    -e "s|@ARCHIVE_AREAS@|${LB_ARCHIVE_AREAS}|g" \
 
776
                                    -e "s|@PARENT_DISTRIBUTION@|${LB_PARENT_DISTRIBUTION}|g" \
 
777
                                    -e "s|@PARENT_ARCHIVE_AREAS@|${LB_PARENT_ARCHIVE_AREAS}|g" \
 
778
                                "${FILE}" > "chroot/etc/apt/sources.list.d/$(basename ${FILE} .binary.list).list"
 
779
                        done
 
780
                fi
 
781
 
 
782
                # Check local archive keys
 
783
                if Find_files config/archives/*.binary.key
 
784
                then
 
785
                        for FILE in config/archives/*.binary.key
 
786
                        do
 
787
                                cp ${FILE} chroot/root
 
788
                                Chroot chroot "apt-key add /root/$(basename ${FILE})"
 
789
                                rm -f chroot/root/$(basename ${FILE})
 
790
                        done
 
791
                fi
 
792
 
 
793
                # Updating indices
 
794
                Apt chroot update
 
795
 
 
796
                # Cleaning apt package cache
 
797
                rm -rf chroot/var/cache/apt
 
798
                mkdir -p chroot/var/cache/apt/archives/partial
 
799
 
 
800
                # Cleaning apt package lists
 
801
                if [ "${LB_APT_INDICES}" = "false" ]
 
802
                then
 
803
                        rm -rf chroot/var/lib/apt/lists
 
804
                        mkdir -p chroot/var/lib/apt/lists/partial
 
805
                fi
 
806
 
 
807
                # Remove local package repository
 
808
                rm -f chroot/etc/apt/sources.list.d/packages.list
 
809
                rm -rf chroot/root/packages
 
810
 
 
811
                # Remove local packages key if it exists
 
812
                if apt-key list | grep -q ${_LB_LOCAL_KEY_EMAIL}
 
813
                then
 
814
                        apt-key del ${_LB_LOCAL_KEY_EMAIL}
 
815
                fi
 
816
 
 
817
                # Removing stage file
 
818
                rm -f .stage/chroot_archives
 
819
                ;;
 
820
 
 
821
        *)
 
822
                Usage
 
823
                ;;
 
824
esac