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
|
#!/bin/sh
set -eu
base=$(readlink -f $(dirname $(readlink -f $0))/../..)
. $base/lib/environment.sh
if [ $(whoami) != root ]; then
echo "E: This script must be run as root"
exit 1
fi
create_chroot() {
echo "I: creating $debci_suite chroot (may take a while)"
http_proxy="${http_proxy:-}"
if [ -z "$http_proxy" ]; then
# detect a local apt-cacher-ng cache running. 10.0.2.2 = default IP
# assigned to host system as seen from a kvm/virtualbox virtual machine
for ip in 127.0.0.1 10.0.2.2; do
if nc -z -w 1 $ip 3142; then
export http_proxy=http://$ip:3142/debian
fi
done
fi
# FIXME automate chroot creation for foreign architectures where a
# qemu-user-static binary is needed
debootstrap --arch="$debci_arch" "$debci_suite" "$debci_chroot_path" $debci_mirror
# use proxy
if [ -n "$http_proxy" ]; then
echo "Acquire::http::Proxy \"$http_proxy\";" > "${debci_chroot_path}/etc/apt/apt.conf.d/01proxy"
fi
# do not download translations
echo 'Acquire::Languages "none";' > "${debci_chroot_path}/etc/apt/apt.conf.d/99translations"
# add APT Source URIs
sed -e 's/^deb\s/deb-src /' "${debci_chroot_path}/etc/apt/sources.list" > "${debci_chroot_path}/etc/apt/sources.list.d/sources.list"
# never ask for input
echo 'debconf debconf/frontend select noninteractive' | chroot "$debci_chroot_path" debconf-set-selections
# use unsafe I/O in dpkg to speed up the installation of packages
echo 'force-unsafe-io' > "${debci_chroot_path}/etc/dpkg/dpkg.cfg.d/debci"
# create debci user inside the chroot, with the same UID as the debci user on
# the host system
chroot "$debci_chroot_path" adduser \
--system \
--disabled-password \
--shell /bin/sh \
--home /home/debci \
--uid "$debci_uid" \
debci
chroot "$debci_chroot_path" apt-get update
}
setup_schroot() {
local data_dir=$(readlink -f ${debci_data_basedir})
local user=$(stat -c %U "${data_dir}")
if [ -z "$user" ]; then
user=debci
fi
cat > /etc/schroot/chroot.d/"${debci_chroot_name}" <<EOF
[$debci_chroot_name]
type=directory
profile=debci
description=debci $debci_suite/$debci_arch chroot
directory=${debci_chroot_path}
users=$user
groups=$user
root-users=$user
source-root-users=$user
root-groups=root
union-type=aufs
EOF
if [ ! -e /etc/schroot/debci ]; then
ln -s "$debci_base_dir/etc/schroot/debci" /etc/schroot/debci
fi
}
setup_suite() {
# create chroot directory
if [ ! -d "${debci_chroots_dir}" ]; then
mkdir "${debci_chroots_dir}"
fi
if schroot --list --all | grep -q "^source:${debci_chroot_name}\$"; then
echo "I: schroot setup for ${debci_suite} already done, skipping"
else
setup_schroot
fi
local actual_chroot_path=$(schroot --config --chroot "$debci_chroot_name" | grep '^directory=' | cut -d = -f 2)
if [ -d "${actual_chroot_path}" ]; then
echo "I: chroot $debci_chroot_name already created, updating"
update-testbed
else
if [ "$actual_chroot_path" = "${debci_chroot_path}" ]; then
create_chroot
else
echo "E: chroot ${debci_chroot_name} does not exit in custom location ${actual_chroot_path}. Please create it first."
exit 1
fi
fi
}
if ! which schroot >/dev/null; then
echo "E: schroot not installed"
exit 1
fi
setup_suite
|