Add in the mess from the original symbiosisware version.
[distorted-chroot] / bin / mkbuildchroot
CommitLineData
e36b4f25
MW
1#! /bin/sh -e
2###
3### Construct a fresh build-chroot base
4###
5### (c) 2018 Mark Wooding
6###
7
8###----- Licensing notice ---------------------------------------------------
9###
10### This file is part of the distorted.org.uk chroot maintenance tools.
11###
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.
16###
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.
21###
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,
25### USA.
26
27. state/config.sh # @@@config@@@
28
29case $PROXY in nil) ;; *) http_proxy=$PROXY; export PROXY ;; esac
30
31badp=nil forcep=nil
32while getopts "f" opt; do
33 case $opt in
34 f) forcep=t ;;
35 *) badp=t ;;
36 esac
37done
38shift $(( $OPTIND - 1 ))
39case $# in 2) ;; *) badp=t ;; esac
40case $badp in t) echo >&2 "usage: $0 [-f] DIST ARCH"; exit 2 ;; esac
41d=$1 a=$2
42
43case $d-$a in *-*-*) echo >&2 "$0: bad chroot name \`$arg'"; exit 2 ;; esac
44if [ ! -d /dev/$VG/ ]; then echo >&2 "$0: no volume group \`$VG'"; exit 2; fi
45
46qemup=nil dbsopts=
47for fa in $FOREIGN_ARCHS; do
48 case $fa in
49 "$a")
50 qemup=t qbsopts=--foreign
51 eval qhost=\$${a}_QEMUARCH qhost=\$${a}_QEMUHOST
52 break
53 ;;
54 esac
55done
56
57lv=$LVPREFIX$d-$a
58mnt=mnt/$lv
59mkdir -p $mnt
60if mountpoint -q $mnt; then umount $mnt; fi
61if [ -b /dev/$VG/$lv ]; then
62 case $forcep in
63 nil) echo >&2 "$0: volume \`$lv' already exists"; exit 2 ;;
64 t) lvremove -f $VG/$lv ;;
65 esac
66fi
67lvcreate --yes $LVSZ -n$lv $VG
68mkfs -j -L$d-$a /dev/$VG/$lv
69mount -orelatime,data=writeback,commit=3600,barrier=0 /dev/$VG/$lv $mnt/
70mkdir -m755 $mnt/fs/
71chmod 750 $mnt/
72pkgs=ccache,eatmydata,fakeroot,libfile-fcntllock-perl,locales,tzdata
73eatmydata debootstrap $dbsopts --arch=$a --variant=minbase \
74 --include=$pkgs $d $mnt/fs/ $DEBMIRROR
75
76case $qemup in
77 t)
78 install $LOCAL/cross/$d-$qhost/QEMU/qemu-$qarch-static \
79 $mnt/fs/usr/bin/
80 chroot $mnt/fs/ /debootstrap/debootstrap --second-stage
81 ln -sf /usr/local.schroot/cross/$d-$qhost/QEMU/qemu-$qarch-static \
82 $mnt/fs/usr/bin/
83 ;;
84esac
85
86cd $mnt/fs/usr/
87rm -rf local/; ln -s local.schroot/$a local
88
89cd $mnt/fs/etc/apt/
90rm -rf apt.conf sources.list
91ln -s /usr/local.schroot/config/apt/conf.d/10sbuild apt.conf.d/
92ln -s /usr/local.schroot/config/apt/conf.d/90local apt.conf.d/
93ln -s /usr/local.schroot/config/apt/sources.$d sources.list
94
95cat >apt.conf.d/20arch <<EOF
96### -*-conf-*-
97
98APT {
99 Architecture "$a";
100};
101EOF
102
103cd $mnt/fs/etc/
104cp /etc/locale.gen /etc/timezone ./
105tz=$(cat timezone); ln -sf /usr/share/zoneinfo/$tz localtime
106ln -sf /proc/mounts mtab
107
108cd $mnt/fs/etc/default/
109cp /etc/default/locale .
110
111cd $mnt/fs/usr/sbin/
112cat >policy-rc.d <<EOF
113#! /bin/sh
114echo >&2 "policy-rc.d: Services disabled by policy."
115exit 101
116EOF
117chmod +x policy-rc.d
118
119cd $mnt/fs/etc/ld.so.conf.d/
120cat >libc.conf <<EOF
121# libc default configuration
122EOF
123cat >zzz-local.conf <<EOF
124### -*-conf-*-
125### Local hack to make /usr/local/ late.
126/usr/local/lib
127EOF
128
129cd /
130umount $mnt/
131
132case $qemup in
133 t)
134 schroot -uroot -csource:$LVPREFIX$d-$a -- eatmydata sh -e -c "
135 if dpkg-divert >/dev/null 2>&1 --no-rename --help
136 then no_rename=--no-rename
137 else no_rename=
138 fi
139
140 dpkg-divert --package install-cross-tools \$no_rename \
141 --divert /usr/bin/$qemu.$a --add /usr/bin/$qemu"
142 $STATE/bin/install-cross-tools $d $a
143 ;;
144esac
145
146schroot -uroot -csource:$LVPREFIX$d-$a -- eatmydata sh -e -c '
147 apt-get update
148 apt-get -y upgrade
149 locale-gen
150 ldconfig
151 apt-get -y autoremove
152 apt-get clean'
153
154###----- That's all, folks --------------------------------------------------