a6ac135a69c6a66a1b44e7a58f9b2c1dcce4d5bd
3 ### Construct a fresh build-chroot base
5 ### (c) 2018 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the distorted.org.uk chroot maintenance tools.
12 ### distorted-chroot is free software: you can redistribute it and/or
13 ### modify it under the terms of the GNU General Public License as
14 ### published by the Free Software Foundation; either version 2 of the
15 ### License, or (at your option) any later version.
17 ### distorted-chroot is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ### General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with distorted-chroot. If not, write to the Free Software
24 ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 . state
/config.sh
# @@@config@@@
29 ## Convert the PROXY configuration setting into something that will affect
31 case $PROXY in nil
) ;; *) http_proxy
=$PROXY; export PROXY
;; esac
33 ## Parse the command-line.
35 while getopts "f" opt
; do
41 shift $
(( $OPTIND - 1 ))
42 case $# in 2) ;; *) badp
=t
;; esac
43 case $badp in t
) echo >&2 "usage: $0 [-f] DIST ARCH"; exit 2 ;; esac
46 case $d-$a in *-*-*) echo >&2 "$0: bad chroot name \`$arg'"; exit 2 ;; esac
47 if [ ! -d
/dev
/$VG/ ]; then echo >&2 "$0: no volume group \`$VG'"; exit 2; fi
49 ## Decide whether we need to do special things for installing a foreign
52 for fa
in $FOREIGN_ARCHS; do
55 qemup
=t dbsopts
=--foreign
56 eval qarch
=\$
${a}_QEMUARCH qhost
=\$
${a}_QEMUHOST
62 ## Construct the logical volume and lay a filesystem onto it.
66 if mountpoint
-q
$mnt; then umount
$mnt; fi
67 if [ -b
/dev
/$VG/$lv ]; then
69 nil
) echo >&2 "$0: volume \`$lv' already exists"; exit 2 ;;
70 t
) lvremove
-f
$VG/$lv ;;
73 lvcreate
--yes $LVSZ -n
$lv $VG
74 mkfs
-j
-L
$d-$a /dev
/$VG/$lv
75 mount
-orelatime
,data
=writeback
,commit
=3600,barrier
=0 /dev
/$VG/$lv $mnt/
79 ## Install the base system.
81 pkgs
=; for p
in $want; do pkgs
=${pkgs:+$pkgs,}$p; done
82 eatmydata debootstrap
$dbsopts --arch
=$a --variant
=minbase \
83 --include
=$pkgs $d $mnt/fs
/ $DEBMIRROR
85 ## If this is a cross-installation, then install the necessary `qemu' and
86 ## complete the installation.
89 install $LOCAL/cross
/$d-$qhost/QEMU
/qemu-
$qarch-static \
91 chroot
$mnt/fs
/ /debootstrap
/debootstrap
--second-stage
92 ln -sf
/usr
/local.schroot
/cross
/$d-$qhost/QEMU
/qemu-
$qarch-static \
97 ## Set up `/usr/local'.
98 rm -rf
$mnt/fs
/usr
/local/; ln -s
local.schroot
/$a $mnt/fs
/usr
/local
100 ## Install the `apt' configuration.
101 rm -rf
$mnt/fs
/etc
/apt
/apt.conf
$mnt/fs
/etc
/apt
/sources.list
102 for c
in $LOCAL/etc
/apt
/apt.conf.d
/*; do
103 ln -s
/usr
/local.schroot
/${c#$LOCAL/} $mnt/fs
/etc
/apt
/apt.conf.d
/
105 ln -s
/usr
/local.schroot
/etc
/apt
/sources.
$d $mnt/fs
/etc
/apt
/sources.list
107 cat >$mnt/fs
/etc
/apt
/apt.conf.d
/20arch
<<EOF
115 ## Set up the locale and time zone from the host system.
116 cp /etc
/locale.gen
/etc
/timezone
$mnt/fs
/etc
/
117 tz
=$
(cat /etc
/timezone
); ln -sf
/usr
/share
/zoneinfo
/$tz $mnt/fs
/etc
/localtime
118 ln -sf
/proc
/mounts
$mnt/fs
/etc
/mtab
120 cp /etc
/default
/locale
$mnt/fs
/etc
/default
/
122 ## Prevent daemons from starting within the chroot.
123 cat >$mnt/fs
/usr
/sbin
/policy-rc.d
<<EOF
125 echo >&2 "policy-rc.d: Services disabled by policy."
128 chmod +x
$mnt/fs
/usr
/sbin
/policy-rc.d
130 ## Hack the dynamic linker to prefer libraries in `/usr' over `/usr/local'.
131 cat >$mnt/fs
/etc
/ld.so.conf.d
/libc.conf
<<EOF
132 # libc default configuration
134 cat >$mnt/fs
/etc
/ld.so.conf.d
/zzz-local.conf
<<EOF
136 ### Local hack to make /usr/local/ late.
140 ## We're done setting the chroot environment up.
143 ## If this is a foreign architecture then we need to set it up.
146 ## Keep the chroot's native Qemu out of our way: otherwise we'll stop
147 ## being able to run programs in the chroot. There's a hack here because
148 ## the `--no-rename' option was required in the same version in which is
149 ## was introduced, so there's no single incantation that will work across
151 schroot
-uroot
-csource
:$lv -- eatmydata sh
-e
-c
"
152 if dpkg-divert >/dev/null 2>&1 --no-rename --help
153 then no_rename=--no-rename
157 dpkg-divert --package install-cross-tools \$no_rename \
158 --divert /usr/bin/qemu-$qarch-static.$a --add /usr/bin/qemu-$qarch-static"
160 ## Install faster native tools.
161 $STATE/bin
/install-cross-tools
$d $a
164 ## Install extra packages now that everything should go fairly quickly.
166 pkgs
=; for p
in $want; do pkgs
=${pkgs:+$pkgs,}$p; done
167 schroot
-uroot
-csource
:$lv -- eatmydata apt-get
-y
install $pkgs
169 ## Set the chroot's package state up properly.
170 schroot
-uroot
-csource
:$lv -- eatmydata sh
-e
-c
'
175 apt-get -y autoremove
178 ###----- That's all, folks --------------------------------------------------