2007-06-14 12:29:32 -07:00
|
|
|
#!/bin/bash
|
2008-08-11 20:06:35 +02:00
|
|
|
#
|
2013-05-06 09:47:36 -04:00
|
|
|
# Copyright 2006-2013 (C) Canonical Ltd.
|
2010-02-09 07:12:39 -08:00
|
|
|
# Authors:
|
|
|
|
# Kees Cook <kees@ubuntu.com>
|
|
|
|
# Emmet Hikory <persia@ubuntu.com>
|
|
|
|
# Scott Moser <smoser@ubuntu.com>
|
2011-04-24 16:17:55 +02:00
|
|
|
# Stefano Rivera <stefanor@ubuntu.com>
|
2012-10-28 18:18:04 +01:00
|
|
|
# Steve Langasek <steve.langasek@ubuntu.com>
|
2013-05-06 09:47:36 -04:00
|
|
|
# Marc Deslauriers <marc.deslauriers@ubuntu.com>
|
2008-08-11 20:06:35 +02:00
|
|
|
#
|
|
|
|
# ##################################################################
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
2008-08-12 20:15:15 +02:00
|
|
|
# as published by the Free Software Foundation; either version 3
|
|
|
|
# of the License, or (at your option) any later version.
|
2009-03-30 12:40:15 -07:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# 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.
|
|
|
|
#
|
2008-08-12 20:15:15 +02:00
|
|
|
# See file /usr/share/common-licenses/GPL for more details.
|
2008-08-11 20:06:35 +02:00
|
|
|
#
|
|
|
|
# ##################################################################
|
2007-08-04 13:52:30 +02:00
|
|
|
#
|
2010-02-09 00:22:06 -08:00
|
|
|
# This script creates chroots designed to be used in a snapshot mode
|
2021-09-28 19:47:59 +02:00
|
|
|
# (with LVM, btrfs, zfs, overlay, overlay or aufs) with schroot and sbuild.
|
2007-06-14 12:29:32 -07:00
|
|
|
# Much love to "man sbuild-setup", https://wiki.ubuntu.com/PbuilderHowto,
|
|
|
|
# and https://help.ubuntu.com/community/SbuildLVMHowto.
|
|
|
|
#
|
2009-03-30 12:40:15 -07:00
|
|
|
# It will deal with sbuild having not be installed and configured before.
|
2007-06-14 12:29:32 -07:00
|
|
|
set -e
|
|
|
|
|
2008-06-13 10:53:59 -07:00
|
|
|
# Set up configurable defaults (loaded after option processing)
|
|
|
|
LV_SIZE="5G"
|
|
|
|
SNAPSHOT_SIZE="4G"
|
2010-02-09 00:22:06 -08:00
|
|
|
SOURCE_CHROOTS_DIR="/var/lib/schroot/chroots"
|
2010-02-09 22:00:44 +09:00
|
|
|
SOURCE_CHROOTS_TGZ="/var/lib/schroot/tarballs"
|
2010-10-25 12:27:50 -04:00
|
|
|
CHROOT_SNAPSHOT_DIR="/var/lib/schroot/snapshots"
|
2013-05-06 09:47:36 -04:00
|
|
|
SCHROOT_PROFILE="sbuild"
|
2021-04-26 20:11:42 +02:00
|
|
|
CCACHE_DIR="/var/cache/ccache-sbuild"
|
|
|
|
CCACHE_SIZE="4G"
|
2008-06-13 10:53:59 -07:00
|
|
|
|
2007-06-14 12:29:32 -07:00
|
|
|
function usage()
|
|
|
|
{
|
2020-06-15 19:15:59 -04:00
|
|
|
echo "Usage: $0 [OPTIONS] Release"
|
2007-06-14 12:29:32 -07:00
|
|
|
echo "Options:"
|
2007-07-26 16:15:41 +10:00
|
|
|
echo " --arch=ARCH What architecture to select"
|
|
|
|
echo " --name=NAME Base name for the schroot (arch is appended)"
|
2008-03-11 09:23:50 +01:00
|
|
|
echo " --personality=PERSONALITY What personality to use (defaults to match --arch)"
|
2010-02-09 00:22:06 -08:00
|
|
|
echo " --vg=VG use LVM snapshots, with group VG"
|
2021-09-28 19:47:59 +02:00
|
|
|
echo " --zfs-dataset=DATASET use ZFS snapshots, with parent dataset DATASET"
|
2007-07-26 16:15:41 +10:00
|
|
|
echo " --debug Turn on script debugging"
|
2009-01-03 10:50:53 -08:00
|
|
|
echo " --skip-updates Do not include -updates pocket in sources.list"
|
2016-05-08 23:26:53 -06:00
|
|
|
echo " --skip-security Do not include -security pocket in sources.list"
|
2012-11-06 11:45:24 +02:00
|
|
|
echo " --skip-proposed Do not include -proposed pocket in sources.list"
|
2007-07-26 16:15:41 +10:00
|
|
|
echo " --source-template=FILE Use FILE as the sources.list template"
|
|
|
|
echo " --debootstrap-mirror=URL Use URL as the debootstrap source"
|
2010-07-27 23:07:34 -07:00
|
|
|
echo " --debootstrap-include=list Comma separated list of packages to include"
|
|
|
|
echo " --debootstrap-exclude=list Comma separated list of packages to exclude"
|
2016-05-08 23:18:28 -06:00
|
|
|
echo " --debootstrap-opts=OPTS Extra options passed to debootstrap"
|
2011-10-25 16:33:28 -04:00
|
|
|
echo " --debootstrap-proxy=URL Use PROXY as apt proxy"
|
2014-12-23 16:14:21 +00:00
|
|
|
echo " --debootstrap-keyring=KEYRING"
|
|
|
|
echo " Use KEYRING to check signatures of retrieved Release files"
|
|
|
|
echo " --debootstrap-no-check-gpg Disables checking gpg signatures of retrieved Release files"
|
2021-03-26 14:23:00 +01:00
|
|
|
echo " --skip-eatmydata Don't install and use eatmydata"
|
|
|
|
echo " --eatmydata Install and use eatmydata (default)"
|
2021-04-26 20:11:42 +02:00
|
|
|
echo " --ccache Install configure and use ccache as default"
|
|
|
|
echo " --ccache-dir=PATH Sets the CCACHE_DIR to PATH"
|
|
|
|
echo " (can be shared between all schroots, defaults to ${CCACHE_DIR})"
|
|
|
|
echo " --ccache-size=SIZE Sets the ccache max-size to SIZE"
|
|
|
|
echo " (shared by each CCACHE_DIR, defaults to ${CCACHE_SIZE})"
|
2010-02-09 00:22:06 -08:00
|
|
|
echo " --distro=DISTRO Install specific distro:"
|
2011-04-24 16:17:55 +02:00
|
|
|
echo " 'ubuntu' or 'debian' "
|
|
|
|
echo " (defaults to determining from release name)"
|
2012-10-28 18:18:04 +01:00
|
|
|
echo " --target=ARCH Target architecture for cross-building"
|
2010-02-09 07:12:39 -08:00
|
|
|
echo " --type=SCHROOT_TYPE Define the schroot type:"
|
2021-09-28 19:47:59 +02:00
|
|
|
echo " 'directory' (default), 'file', or 'btrfs-snapshot'."
|
2010-02-09 07:12:39 -08:00
|
|
|
echo " 'lvm-snapshot' is selected via --vg"
|
2021-09-28 19:47:59 +02:00
|
|
|
echo " 'zfs-snapshot' is selected via --zfs-dataset"
|
2008-06-13 10:53:59 -07:00
|
|
|
echo ""
|
2010-02-08 20:04:33 -05:00
|
|
|
echo "Configuration (via ~/.mk-sbuild.rc)"
|
2008-06-13 10:53:59 -07:00
|
|
|
echo " LV_SIZE Size of source LVs (default ${LV_SIZE})"
|
|
|
|
echo " SNAPSHOT_SIZE Size of snapshot LVs (default ${SNAPSHOT_SIZE})"
|
2010-02-09 22:00:44 +09:00
|
|
|
echo " SOURCE_CHROOTS_DIR Directory to store directory source chroots"
|
|
|
|
echo " SOURCE_CHROOTS_TGZ Directory to store file source chroots"
|
2010-10-25 12:27:50 -04:00
|
|
|
echo " CHROOT_SNAPSHOT_DIR Directory to mount open btrfs snaphshot chroots (default ${CHROOT_SNAPSHOT_DIR})"
|
2008-06-13 10:53:59 -07:00
|
|
|
echo " SCHROOT_CONF_SUFFIX Lines to append to schroot.conf entries"
|
2013-05-06 09:47:36 -04:00
|
|
|
echo " SCHROOT_PROFILE Profile to use with schroot (default ${SCHROOT_PROFILE})"
|
2009-01-03 10:50:53 -08:00
|
|
|
echo " SKIP_UPDATES Enable --skip-updates"
|
2012-11-06 11:45:24 +02:00
|
|
|
echo " SKIP_PROPOSED Enable --skip-proposed"
|
2016-05-08 23:26:53 -06:00
|
|
|
echo " SKIP_SECURITY Enable --skip-security"
|
2010-02-18 11:11:16 -08:00
|
|
|
echo " DEBOOTSTRAP_MIRROR Mirror location (same as --debootstrap-mirror)"
|
2010-07-27 23:07:34 -07:00
|
|
|
echo " DEBOOTSTRAP_INCLUDE Included packages (same as --debootstrap-include)"
|
|
|
|
echo " DEBOOTSTRAP_EXCLUDE Excluded packages (same as --debootstrap-exclude)"
|
2016-05-08 23:18:28 -06:00
|
|
|
echo " DEBOOTSTRAP_OPTS Extra options passed to debootstrap (same as --debootstrap-opts)"
|
2011-10-25 16:33:28 -04:00
|
|
|
echo " DEBOOTSTRAP_PROXY Apt proxy (same as --debootstrap-proxy)"
|
2014-12-23 16:14:21 +00:00
|
|
|
echo " DEBOOTSTRAP_KEYRING GPG keyring (same as --debootstrap-keyring)"
|
|
|
|
echo " DEBOOTSTRAP_NO_CHECK_GPG Disable GPG verification (same as --debootstrap-no-check-gpg)"
|
2021-03-26 14:23:00 +01:00
|
|
|
echo " EATMYDATA Enable or disable eatmydata usage, see --eatmydata and --skip-eatmydata"
|
2021-04-26 20:11:42 +02:00
|
|
|
echo " CCACHE Enable --ccache"
|
|
|
|
echo " CCACHE_DIR Path for ccache (can be shared between all schroots, "
|
|
|
|
echo " same as --ccache-dir, default ${CCACHE_DIR})"
|
|
|
|
echo " CCACHE_SIZE Sets the ccache max-size (shared by each CCACHE_DIR, "
|
|
|
|
echo " same as --ccache-size, default ${CCACHE_SIZE})"
|
2009-03-30 12:40:15 -07:00
|
|
|
echo " TEMPLATE_SOURCES A template for sources.list"
|
|
|
|
echo " TEMPLATE_SCHROOTCONF A template for schroot.conf stanza"
|
2011-04-24 16:01:42 +02:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
exit $1
|
2007-06-14 12:29:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
usage
|
|
|
|
fi
|
2021-04-26 18:14:51 +02:00
|
|
|
supported_options=(
|
|
|
|
help
|
|
|
|
debug
|
|
|
|
skip-updates
|
|
|
|
skip-security
|
|
|
|
skip-proposed
|
|
|
|
skip-eatmydata
|
2021-04-26 20:11:42 +02:00
|
|
|
ccache
|
2021-04-26 18:14:51 +02:00
|
|
|
arch:
|
|
|
|
name:
|
|
|
|
source-template:
|
|
|
|
debootstrap-mirror:
|
|
|
|
debootstrap-include:
|
|
|
|
debootstrap-exclude:
|
|
|
|
debootstrap-opts:
|
|
|
|
debootstrap-proxy:
|
|
|
|
debootstrap-no-check-gpg
|
|
|
|
debootstrap-keyring:
|
|
|
|
personality:
|
|
|
|
distro:
|
|
|
|
vg:
|
2021-09-28 19:47:59 +02:00
|
|
|
zfs-dataset:
|
2021-04-26 18:14:51 +02:00
|
|
|
type:
|
|
|
|
target:
|
2021-04-26 20:11:42 +02:00
|
|
|
ccache-dir:
|
|
|
|
ccache-size:
|
2021-04-26 18:14:51 +02:00
|
|
|
)
|
|
|
|
OPTS=$(getopt -o 'h' --long "$(IFS=, && echo "${supported_options[*]}")" -- "$@")
|
2007-06-14 12:29:32 -07:00
|
|
|
eval set -- "$OPTS"
|
|
|
|
|
2010-02-08 20:04:33 -05:00
|
|
|
VG=""
|
2011-04-24 16:17:55 +02:00
|
|
|
DISTRO=""
|
2021-04-26 20:11:42 +02:00
|
|
|
COMMAND_PREFIX=""
|
2007-06-14 12:29:32 -07:00
|
|
|
name=""
|
2011-10-25 16:33:28 -04:00
|
|
|
proxy="_unset_"
|
2014-12-23 16:14:21 +00:00
|
|
|
DEBOOTSTRAP_NO_CHECK_GPG=0
|
2021-03-26 14:23:00 +01:00
|
|
|
EATMYDATA=1
|
2021-04-26 20:11:42 +02:00
|
|
|
CCACHE=0
|
2011-10-25 16:33:28 -04:00
|
|
|
|
2007-06-14 12:29:32 -07:00
|
|
|
while :; do
|
|
|
|
case "$1" in
|
|
|
|
--debug)
|
2021-04-26 19:29:06 +02:00
|
|
|
DEBUG=1
|
2007-06-14 12:29:32 -07:00
|
|
|
set -x
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--arch)
|
2009-12-12 14:04:01 +09:00
|
|
|
CHROOT_ARCH="$2"
|
2019-06-04 11:07:10 +01:00
|
|
|
case $2 in
|
2023-05-30 21:05:56 -07:00
|
|
|
armhf|i386)
|
2019-06-04 11:07:10 +01:00
|
|
|
if [ -z "$personality" ]; then
|
|
|
|
personality="linux32"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2007-06-14 12:29:32 -07:00
|
|
|
shift 2
|
|
|
|
;;
|
2008-03-06 11:34:43 -05:00
|
|
|
--personality)
|
|
|
|
personality="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2009-01-03 10:50:53 -08:00
|
|
|
--skip-updates)
|
|
|
|
SKIP_UPDATES="1"
|
|
|
|
shift
|
|
|
|
;;
|
2012-11-06 11:45:24 +02:00
|
|
|
--skip-proposed)
|
|
|
|
SKIP_PROPOSED="1"
|
|
|
|
shift
|
|
|
|
;;
|
2016-05-08 23:26:53 -06:00
|
|
|
--skip-security)
|
|
|
|
SKIP_SECURITY="1"
|
|
|
|
shift
|
|
|
|
;;
|
2007-06-14 12:29:32 -07:00
|
|
|
--name)
|
|
|
|
name="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2008-06-13 10:31:55 -07:00
|
|
|
--source-template)
|
|
|
|
TEMPLATE_SOURCES="$2"
|
|
|
|
shift 2
|
|
|
|
if [ ! -r $TEMPLATE_SOURCES ]; then
|
|
|
|
echo "W: Template file $TEMPLATE_SOURCES is not readable"
|
|
|
|
echo "W: Continuing with default sources!"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--debootstrap-mirror)
|
|
|
|
DEBOOTSTRAP_MIRROR="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2010-07-27 23:07:34 -07:00
|
|
|
--debootstrap-include)
|
|
|
|
DEBOOTSTRAP_INCLUDE="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--debootstrap-exclude)
|
|
|
|
DEBOOTSTRAP_EXCLUDE="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2016-05-08 23:18:28 -06:00
|
|
|
--debootstrap-opts)
|
|
|
|
DEBOOTSTRAP_OPTS="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2011-10-25 16:33:28 -04:00
|
|
|
--debootstrap-proxy)
|
|
|
|
proxy="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2014-12-23 16:14:21 +00:00
|
|
|
--debootstrap-keyring)
|
|
|
|
# Store the absolute path because we cd to the root directory later.
|
|
|
|
DEBOOTSTRAP_KEYRING=$(readlink -f "$2")
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--debootstrap-no-check-gpg)
|
|
|
|
DEBOOTSTRAP_NO_CHECK_GPG=1
|
|
|
|
shift
|
|
|
|
;;
|
2021-03-26 14:23:00 +01:00
|
|
|
--skip-eatmydata)
|
|
|
|
EATMYDATA=0
|
2011-11-13 01:31:02 +02:00
|
|
|
shift
|
|
|
|
;;
|
2021-04-26 20:11:42 +02:00
|
|
|
--ccache)
|
|
|
|
CCACHE=1
|
|
|
|
shift
|
|
|
|
;;
|
2009-03-30 12:40:15 -07:00
|
|
|
--distro)
|
|
|
|
DISTRO="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2010-02-09 07:12:39 -08:00
|
|
|
--vg)
|
2010-02-08 20:04:33 -05:00
|
|
|
VG="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2021-09-28 19:47:59 +02:00
|
|
|
--zfs-dataset)
|
|
|
|
ZFS_PARENT_DATASET="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2010-02-09 21:29:29 +09:00
|
|
|
--type)
|
|
|
|
SCHROOT_TYPE="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2012-10-28 18:18:04 +01:00
|
|
|
--target)
|
|
|
|
TARGET_ARCH="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2021-04-26 20:11:42 +02:00
|
|
|
--ccache-dir)
|
|
|
|
CCACHE_DIR="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--ccache-size)
|
|
|
|
CCACHE_SIZE="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2007-06-14 12:29:32 -07:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
2011-04-24 16:01:42 +02:00
|
|
|
-h|--help|*)
|
|
|
|
usage 0
|
2007-06-14 12:29:32 -07:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2011-04-24 15:59:22 +02:00
|
|
|
# For when schroot enters the chroot, we cannot be in a directory that
|
|
|
|
# will not exist in the chroot.
|
|
|
|
cd /
|
|
|
|
|
2012-05-06 12:40:47 +02:00
|
|
|
if [ -w /etc/passwd -a ! -e ~/.sbuildrc -a ! -e ~/.mk-sbuild.rc ]; then
|
|
|
|
cat >&2 <<EOF
|
|
|
|
It's recommended to run this script as a regular user, not root, so that it
|
|
|
|
uses the configuration files in your home directory.
|
|
|
|
It will use sudo to escalate to root as necessary.
|
|
|
|
|
|
|
|
If you really do want to use it as root, create a .sbuildrc or .mk-sbuild.rc
|
|
|
|
in root's home.
|
|
|
|
EOF
|
2011-04-24 15:59:22 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Perform once-only things to initially set up for using sbuild+schroot
|
|
|
|
if [ ! -w /var/lib/sbuild ]; then
|
|
|
|
# Load all the packages you'll need to do work
|
|
|
|
sudo apt-get install sbuild schroot debootstrap
|
|
|
|
# Add self to the sbuild group
|
|
|
|
sudo adduser "$USER" sbuild
|
|
|
|
|
|
|
|
# Prepare a usable default .sbuildrc
|
|
|
|
if [ ! -e ~/.sbuildrc ]; then
|
|
|
|
cat > ~/.sbuildrc <<EOM
|
|
|
|
# *** VERIFY AND UPDATE \$mailto and \$maintainer_name BELOW ***
|
|
|
|
|
|
|
|
# Mail address where logs are sent to (mandatory, no default!)
|
|
|
|
\$mailto = '$USER';
|
|
|
|
|
|
|
|
# Name to use as override in .changes files for the Maintainer: field
|
2011-05-23 17:18:09 +01:00
|
|
|
#\$maintainer_name='$USER <$USER@localhost>';
|
2011-04-24 15:59:22 +02:00
|
|
|
|
|
|
|
# Directory for chroot symlinks and sbuild logs. Defaults to the
|
|
|
|
# current directory if unspecified.
|
|
|
|
#\$build_dir='$HOME/ubuntu/build';
|
|
|
|
|
|
|
|
# Directory for writing build logs to
|
|
|
|
\$log_dir="$HOME/ubuntu/logs";
|
|
|
|
|
|
|
|
# don't remove this, Perl needs it:
|
|
|
|
1;
|
|
|
|
EOM
|
|
|
|
sensible-editor ~/.sbuildrc
|
|
|
|
# Create target directories, if needed
|
|
|
|
eval $(egrep '^\$(build|log)_dir[ ]*=' ~/.sbuildrc | cut -c2-)
|
|
|
|
if [ -n "$log_dir" ]; then
|
|
|
|
mkdir -p "$log_dir"
|
|
|
|
fi
|
|
|
|
if [ -n "$build_dir" ]; then
|
|
|
|
mkdir -p "$build_dir"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Your ~/.sbuildrc already exists -- leaving it as-is."
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo '***********************************************'
|
|
|
|
echo '* Before continuing, you MUST restart your *'
|
|
|
|
echo '* session to gain "sbuild" group permissions! *'
|
|
|
|
echo '***********************************************'
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! id | fgrep -q '(sbuild)'; then
|
|
|
|
echo "You must be a member of the 'sbuild' group." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-02-09 21:29:29 +09:00
|
|
|
# To build the chroot, we need to know which release of Ubuntu to debootstrap
|
2010-02-08 20:04:33 -05:00
|
|
|
RELEASE="$1"
|
|
|
|
if [ -z "$RELEASE" ]; then
|
2007-06-14 12:29:32 -07:00
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2011-04-24 20:36:27 +02:00
|
|
|
# Determine distribution and possible synonyms
|
|
|
|
synonym=""
|
2011-04-24 21:52:26 +02:00
|
|
|
EXPERIMENTAL=0
|
2011-11-13 00:40:26 +02:00
|
|
|
if [ "$RELEASE" = "experimental" ]; then
|
|
|
|
DISTRO="${DISTRO:-debian}"
|
|
|
|
EXPERIMENTAL=1
|
|
|
|
name="${name:-experimental}"
|
|
|
|
RELEASE=$(debian-distro-info --devel)
|
|
|
|
elif debian-distro-info --all | grep -Fqx "$RELEASE"; then
|
2011-04-24 20:36:27 +02:00
|
|
|
DISTRO="${DISTRO:-debian}"
|
|
|
|
if [ "$RELEASE" = $(debian-distro-info --devel) ]; then
|
|
|
|
synonym=unstable
|
|
|
|
elif [ "$RELEASE" = $(debian-distro-info --testing) ]; then
|
|
|
|
synonym=testing
|
|
|
|
elif [ "$RELEASE" = $(debian-distro-info --stable) ]; then
|
|
|
|
synonym=stable
|
|
|
|
elif [ "$RELEASE" = $(debian-distro-info --old) ]; then
|
|
|
|
synonym=oldstable
|
2011-04-24 16:17:55 +02:00
|
|
|
fi
|
2011-04-24 20:36:27 +02:00
|
|
|
elif ubuntu-distro-info --all | grep -Fqx "$RELEASE"; then
|
|
|
|
DISTRO="${DISTRO:-ubuntu}"
|
|
|
|
elif [ "$RELEASE" = "unstable" ]; then
|
|
|
|
DISTRO="${DISTRO:-debian}"
|
|
|
|
synonym="$RELEASE"
|
|
|
|
RELEASE=$(debian-distro-info --devel)
|
|
|
|
elif [ "$RELEASE" = "testing" ]; then
|
|
|
|
DISTRO="${DISTRO:-debian}"
|
|
|
|
synonym="$RELEASE"
|
|
|
|
RELEASE=$(debian-distro-info --testing)
|
|
|
|
elif [ "$RELEASE" = "stable" ]; then
|
|
|
|
DISTRO="${DISTRO:-debian}"
|
|
|
|
synonym="$RELEASE"
|
|
|
|
RELEASE=$(debian-distro-info --stable)
|
|
|
|
elif [ "$RELEASE" = "oldstable" ]; then
|
|
|
|
DISTRO="${DISTRO:-debian}"
|
|
|
|
synonym="$RELEASE"
|
|
|
|
RELEASE=$(debian-distro-info --old)
|
|
|
|
elif [ -z "$DISTRO" ]; then
|
|
|
|
echo "Unable to determine distribution, please provide --distro" >&2
|
|
|
|
exit 1
|
2011-04-24 16:17:55 +02:00
|
|
|
fi
|
|
|
|
|
2022-06-16 10:20:22 +02:00
|
|
|
# By default DEBOOTSTRAP_SCRIPT must match RELEASE
|
|
|
|
DEBOOTSTRAP_SCRIPT="$RELEASE"
|
2022-04-27 14:17:10 +01:00
|
|
|
|
2023-01-13 18:33:08 +09:00
|
|
|
dist_ge() {
|
|
|
|
local releases="$($3-distro-info --all)"
|
|
|
|
local left=999
|
|
|
|
local right=0
|
|
|
|
local seq=1
|
|
|
|
|
|
|
|
for i in $releases; do
|
2018-04-24 05:12:33 -06:00
|
|
|
if [ $1 = $i ]; then
|
2023-01-13 18:33:08 +09:00
|
|
|
local left=$seq
|
|
|
|
break
|
2018-04-24 05:12:33 -06:00
|
|
|
fi
|
|
|
|
seq=$((seq+1))
|
2023-01-13 18:33:08 +09:00
|
|
|
done
|
|
|
|
|
|
|
|
seq=1
|
|
|
|
for i in $releases; do
|
2018-04-24 05:12:33 -06:00
|
|
|
if [ $2 = $i ]; then
|
2023-01-13 18:33:08 +09:00
|
|
|
local right=$seq
|
|
|
|
break
|
2018-04-24 05:12:33 -06:00
|
|
|
fi
|
|
|
|
seq=$((seq+1))
|
2023-01-13 18:33:08 +09:00
|
|
|
done
|
|
|
|
|
|
|
|
[ $left -ge $right ] && return 0 || return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
ubuntu_dist_ge () {
|
|
|
|
dist_ge $1 $2 ubuntu
|
|
|
|
}
|
|
|
|
|
|
|
|
debian_dist_ge () {
|
|
|
|
dist_ge $1 $2 debian
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$DISTRO" = "ubuntu" ]; then
|
2022-06-16 10:20:22 +02:00
|
|
|
# On Ubuntu, set DEBOOTSTRAP_SCRIPT to gutsy to allow building new RELEASES without new debootstrap
|
|
|
|
DEBOOTSTRAP_SCRIPT=gutsy
|
2018-04-24 05:12:33 -06:00
|
|
|
fi
|
|
|
|
|
2007-06-14 12:29:32 -07:00
|
|
|
# By default, name the schroot the same as the release
|
|
|
|
if [ -z "$name" ]; then
|
|
|
|
name="$RELEASE"
|
2011-04-24 20:36:27 +02:00
|
|
|
else
|
|
|
|
# Disable synonym when a custom name is used:
|
|
|
|
synonym=""
|
2007-06-14 12:29:32 -07:00
|
|
|
fi
|
|
|
|
|
2010-02-09 11:40:16 +09:00
|
|
|
# By default, use the native architecture.
|
2010-02-03 11:46:08 -08:00
|
|
|
HOST_ARCH=$(dpkg --print-architecture)
|
2009-12-12 14:04:01 +09:00
|
|
|
if [ -z "$CHROOT_ARCH" ]; then
|
2010-02-09 11:40:16 +09:00
|
|
|
CHROOT_ARCH="$HOST_ARCH"
|
2009-12-12 14:04:01 +09:00
|
|
|
fi
|
|
|
|
|
2013-01-12 15:26:08 +02:00
|
|
|
if [ -z "$TARGET_ARCH" ]; then
|
|
|
|
CHROOT_NAME="${name}-${CHROOT_ARCH}"
|
|
|
|
else
|
2013-02-05 19:46:02 +00:00
|
|
|
CHROOT_NAME="${name}-${CHROOT_ARCH}-${TARGET_ARCH}"
|
2013-01-12 15:26:08 +02:00
|
|
|
fi
|
2010-02-09 11:40:16 +09:00
|
|
|
|
2011-04-24 20:36:27 +02:00
|
|
|
if [ -z "$synonym" ]; then
|
|
|
|
CHROOT_SYNONYM=""
|
|
|
|
else
|
|
|
|
CHROOT_SYNONYM="${synonym}-${CHROOT_ARCH}"
|
|
|
|
fi
|
|
|
|
|
2008-06-13 10:53:59 -07:00
|
|
|
# Load customizations
|
2010-02-08 20:04:33 -05:00
|
|
|
if [ -r ~/.mk-sbuild.rc ]; then
|
|
|
|
. ~/.mk-sbuild.rc
|
2008-06-13 10:53:59 -07:00
|
|
|
fi
|
|
|
|
|
2011-11-13 01:31:02 +02:00
|
|
|
# Will eatmydata be available?
|
|
|
|
if [ $EATMYDATA -eq 1 ]; then
|
|
|
|
case "$RELEASE" in
|
|
|
|
hardy|lucid|maverick|lenny|squeeze)
|
|
|
|
echo "eatmydata is known not to be available in $RELEASE, ignoring --eatmydata"
|
|
|
|
EATMYDATA=0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
DEBOOTSTRAP_INCLUDE="${DEBOOTSTRAP_INCLUDE:+$DEBOOTSTRAP_INCLUDE,}eatmydata"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2021-04-26 20:11:42 +02:00
|
|
|
if [ $CCACHE -eq 1 ]; then
|
|
|
|
if [ -z "$CCACHE_DIR" ] || [[ "$(dirname "$CCACHE_DIR")" == '/' ]]; then
|
|
|
|
echo "Invalid ccache dir: ${CCACHE_DIR}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# We can safely use a global cache path, in such case changing size applies
|
|
|
|
# to all the schroots
|
|
|
|
setup_script="$CCACHE_DIR"/mk-sbuild-setup
|
|
|
|
if [ -d "$CCACHE_DIR" ]; then
|
|
|
|
echo "Reusing $CCACHE_DIR as CCACHE_DIR, will be configured to use max-size=${CCACHE_SIZE}"
|
|
|
|
rm -f "$setup_script"
|
|
|
|
else
|
|
|
|
echo "Configuring $CCACHE_DIR as CCACHE_DIR with max-size=${CCACHE_SIZE}"
|
|
|
|
sudo install --group=sbuild --mode=2775 -d "$CCACHE_DIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x "$setup_script" ]; then
|
|
|
|
cat <<END | sudo tee "$setup_script" 1>/dev/null
|
|
|
|
#!/bin/sh
|
|
|
|
export CCACHE_DIR="$CCACHE_DIR"
|
|
|
|
export CCACHE_MAXSIZE="${CCACHE_SIZE}"
|
|
|
|
export CCACHE_UMASK=002
|
|
|
|
export CCACHE_COMPRESS=1
|
|
|
|
unset CCACHE_HARDLINK
|
|
|
|
export CCACHE_NOHARDLINK=1
|
|
|
|
export PATH="/usr/lib/ccache:\$PATH"
|
|
|
|
exec "\$@"
|
|
|
|
END
|
|
|
|
sudo chmod a+rx "$setup_script"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! sudo grep -qs "$CCACHE_DIR" /etc/schroot/sbuild/fstab; then
|
|
|
|
# This acts on host configuration, but there is no other way to handle
|
|
|
|
# this, however it won't affect anything
|
|
|
|
cat <<END | sudo tee -a /etc/schroot/sbuild/fstab 1>/dev/null
|
|
|
|
${CCACHE_DIR} ${CCACHE_DIR} none rw,bind 0 0
|
|
|
|
END
|
|
|
|
fi
|
|
|
|
|
|
|
|
DEBOOTSTRAP_INCLUDE="${DEBOOTSTRAP_INCLUDE:+$DEBOOTSTRAP_INCLUDE,}ccache"
|
|
|
|
BUILD_PKGS="$BUILD_PKGS ccache"
|
|
|
|
COMMAND_PREFIX="${COMMAND_PREFIX:+$COMMAND_PREFIX,}$setup_script"
|
|
|
|
fi
|
|
|
|
|
2010-02-09 21:29:29 +09:00
|
|
|
if [ -z "$SCHROOT_TYPE" ]; then
|
2010-02-09 22:00:44 +09:00
|
|
|
# To build the LV, we need to know which volume group to use
|
2010-02-09 21:29:29 +09:00
|
|
|
if [ -n "$VG" ]; then
|
2010-02-09 07:12:39 -08:00
|
|
|
SCHROOT_TYPE="lvm-snapshot"
|
2021-09-28 19:47:59 +02:00
|
|
|
# To build the ZFS dataset, we need to know which parent to use
|
|
|
|
elif [ -n "$ZFS_PARENT_DATASET" ]; then
|
|
|
|
SCHROOT_TYPE="zfs-snapshot"
|
2010-02-09 21:29:29 +09:00
|
|
|
else
|
2010-02-09 07:12:39 -08:00
|
|
|
SCHROOT_TYPE="directory"
|
2010-02-09 21:29:29 +09:00
|
|
|
fi
|
2007-06-14 12:29:32 -07:00
|
|
|
fi
|
|
|
|
|
2010-02-09 21:29:29 +09:00
|
|
|
case "$SCHROOT_TYPE" in
|
|
|
|
"lvm-snapshot")
|
2010-02-08 20:04:33 -05:00
|
|
|
# Make sure LVM tools that operate on the snapshots have needed module
|
|
|
|
if ! sudo dmsetup targets | grep -q ^snapshot; then
|
|
|
|
sudo modprobe dm_snapshot
|
|
|
|
echo dm_snapshot | sudo tee -a /etc/modules >/dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set up some variables for use in the paths and names
|
2013-02-12 11:03:04 +00:00
|
|
|
if [ -z "$TARGET_ARCH" ]; then
|
2013-02-13 14:12:06 -05:00
|
|
|
CHROOT_LV="${name}_${CHROOT_ARCH}_chroot"
|
2013-02-12 11:03:04 +00:00
|
|
|
else
|
2013-02-13 14:12:06 -05:00
|
|
|
CHROOT_LV="${name}_${CHROOT_ARCH}_${TARGET_ARCH}_chroot"
|
2013-02-12 11:03:04 +00:00
|
|
|
fi
|
2010-02-08 20:04:33 -05:00
|
|
|
CHROOT_PATH="/dev/$VG/$CHROOT_LV"
|
2010-02-09 21:29:29 +09:00
|
|
|
|
2010-02-10 06:08:02 +09:00
|
|
|
# Install lvm2 if missing
|
|
|
|
if ! dpkg -l lvm2 >/dev/null 2>&1; then
|
|
|
|
sudo apt-get install lvm2
|
|
|
|
fi
|
|
|
|
|
2010-02-08 20:04:33 -05:00
|
|
|
# Does the specified VG exist? (vgdisplay doesn't set error codes...)
|
|
|
|
if [ `sudo vgdisplay -c "$VG" | wc -l` -eq 0 ]; then
|
2010-02-09 07:12:39 -08:00
|
|
|
echo "Volume group '${VG}' does not appear to exist" >&2
|
2010-02-09 00:22:06 -08:00
|
|
|
exit 1
|
2010-02-08 20:04:33 -05:00
|
|
|
fi
|
|
|
|
;;
|
2010-02-09 21:29:29 +09:00
|
|
|
"directory")
|
2010-02-08 20:04:33 -05:00
|
|
|
if [ ! -d "${SOURCE_CHROOTS_DIR}" ]; then
|
2010-02-09 00:22:06 -08:00
|
|
|
sudo mkdir -p "${SOURCE_CHROOTS_DIR}"
|
2010-02-08 20:04:33 -05:00
|
|
|
fi
|
2010-02-09 22:00:44 +09:00
|
|
|
# Set up some variables for use in the paths and names
|
|
|
|
CHROOT_PATH="${SOURCE_CHROOTS_DIR}/${CHROOT_NAME}"
|
2010-02-08 20:04:33 -05:00
|
|
|
;;
|
2010-02-09 22:00:44 +09:00
|
|
|
"file")
|
2010-02-09 21:29:29 +09:00
|
|
|
if [ ! -d "$SOURCE_CHROOTS_TGZ" ]; then
|
|
|
|
sudo mkdir -p "$SOURCE_CHROOTS_TGZ"
|
|
|
|
fi
|
2010-02-09 22:00:44 +09:00
|
|
|
# Set up some variables for use in the paths and names
|
|
|
|
CHROOT_PATH="${SOURCE_CHROOTS_TGZ}/${CHROOT_NAME}.tgz"
|
2010-02-08 20:04:33 -05:00
|
|
|
;;
|
2021-09-28 19:47:59 +02:00
|
|
|
"btrfs-snapshot" | "zfs-snapshot")
|
2010-10-25 12:27:50 -04:00
|
|
|
if [ ! -d "${SOURCE_CHROOTS_DIR}" ]; then
|
2011-04-24 16:39:39 +02:00
|
|
|
sudo mkdir -p "${SOURCE_CHROOTS_DIR}"
|
2010-10-25 12:27:50 -04:00
|
|
|
fi
|
|
|
|
if [ ! -d "${CHROOT_SNAPSHOT_DIR}" ]; then
|
2011-04-24 16:39:39 +02:00
|
|
|
sudo mkdir -p "${CHROOT_SNAPSHOT_DIR}"
|
2010-10-25 12:27:50 -04:00
|
|
|
fi
|
|
|
|
CHROOT_PATH="${SOURCE_CHROOTS_DIR}/${CHROOT_NAME}"
|
|
|
|
;;
|
2010-02-09 00:22:06 -08:00
|
|
|
*)
|
|
|
|
echo 'unknown source type!?' >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
2010-02-08 20:04:33 -05:00
|
|
|
esac
|
2007-06-14 12:29:32 -07:00
|
|
|
|
|
|
|
# Is the specified release known to debootstrap?
|
2010-02-09 00:22:06 -08:00
|
|
|
variant_opt="--variant=buildd"
|
2022-06-16 10:20:22 +02:00
|
|
|
if [ ! -r "/usr/share/debootstrap/scripts/$DEBOOTSTRAP_SCRIPT" ]; then
|
|
|
|
echo "Specified release ($DEBOOTSTRAP_SCRIPT) not known to debootstrap" >&2
|
2007-06-14 12:29:32 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-12-16 15:33:11 +02:00
|
|
|
BUILD_PKGS="build-essential fakeroot apt-utils"
|
2009-03-30 12:40:15 -07:00
|
|
|
# Handle distro-specific logic, unknown to debootstrap
|
|
|
|
case "$DISTRO" in
|
|
|
|
ubuntu)
|
|
|
|
if [ -z "$DEBOOTSTRAP_MIRROR" ]; then
|
2009-12-12 14:04:01 +09:00
|
|
|
case "$CHROOT_ARCH" in
|
|
|
|
amd64 | i386)
|
|
|
|
DEBOOTSTRAP_MIRROR="http://archive.ubuntu.com/ubuntu"
|
|
|
|
;;
|
2013-12-20 15:03:55 +00:00
|
|
|
*)
|
2009-12-12 14:04:01 +09:00
|
|
|
DEBOOTSTRAP_MIRROR="http://ports.ubuntu.com/ubuntu-ports"
|
|
|
|
;;
|
|
|
|
esac
|
2009-03-30 12:40:15 -07:00
|
|
|
fi
|
|
|
|
if [ -z "$COMPONENTS" ]; then
|
|
|
|
COMPONENTS="main restricted universe multiverse"
|
|
|
|
fi
|
2012-11-06 11:45:24 +02:00
|
|
|
if [ -z "$SOURCES_PROPOSED_SUITE" ]; then
|
|
|
|
SOURCES_PROPOSED_SUITE="RELEASE-proposed"
|
|
|
|
fi
|
2009-03-30 12:40:15 -07:00
|
|
|
if [ -z "$SOURCES_SECURITY_SUITE" ]; then
|
2011-04-24 21:53:50 +02:00
|
|
|
SOURCES_SECURITY_SUITE="RELEASE-security"
|
2009-03-30 12:40:15 -07:00
|
|
|
fi
|
|
|
|
if [ -z "$SOURCES_SECURITY_URL" ]; then
|
2009-12-12 14:04:01 +09:00
|
|
|
case "$CHROOT_ARCH" in
|
|
|
|
amd64 | i386)
|
|
|
|
SOURCES_SECURITY_URL="http://security.ubuntu.com/ubuntu"
|
|
|
|
;;
|
2013-12-20 15:03:55 +00:00
|
|
|
*)
|
2009-12-12 14:04:01 +09:00
|
|
|
SOURCES_SECURITY_URL="http://ports.ubuntu.com/ubuntu-ports"
|
|
|
|
;;
|
|
|
|
esac
|
2009-03-30 12:40:15 -07:00
|
|
|
fi
|
2012-10-28 18:18:04 +01:00
|
|
|
if [ -n "$TARGET_ARCH" ]; then
|
|
|
|
# target chroots only supported in precise and later, so ignore
|
|
|
|
# the fact that powerpc was once not on ports.
|
|
|
|
case "$TARGET_ARCH" in
|
|
|
|
amd64 | i386)
|
|
|
|
TARGET_MIRROR="http://archive.ubuntu.com/ubuntu"
|
|
|
|
TARGET_SOURCES_SECURITY_URL="http://security.ubuntu.com/ubuntu"
|
|
|
|
;;
|
2013-12-20 15:03:55 +00:00
|
|
|
*)
|
2012-10-28 18:18:04 +01:00
|
|
|
TARGET_MIRROR="http://ports.ubuntu.com/ubuntu-ports"
|
|
|
|
TARGET_SOURCES_SECURITY_URL="http://ports.ubuntu.com/ubuntu-ports"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2009-03-30 12:49:05 -07:00
|
|
|
# Add edgy+ buildd tools
|
2018-04-24 05:12:33 -06:00
|
|
|
if ubuntu_dist_ge "$RELEASE" "edgy"; then
|
|
|
|
# Add pkgbinarymangler (edgy and later)
|
|
|
|
BUILD_PKGS="$BUILD_PKGS pkgbinarymangler"
|
2009-03-30 12:49:05 -07:00
|
|
|
# Disable recommends for a smaller chroot (gutsy and later only)
|
2018-04-24 05:12:33 -06:00
|
|
|
if ubuntu_dist_ge "$RELEASE" "gutsy"; then
|
|
|
|
BUILD_PKGS="--no-install-recommends $BUILD_PKGS"
|
2018-10-23 22:06:10 +02:00
|
|
|
SKIP_RECOMMENDS=1
|
2018-04-24 05:12:33 -06:00
|
|
|
fi
|
|
|
|
# Add pkg-create-dbgsym (edgy through zesty)
|
|
|
|
if ! ubuntu_dist_ge "$RELEASE" "artful"; then
|
|
|
|
BUILD_PKGS="$BUILD_PKGS pkg-create-dbgsym"
|
|
|
|
fi
|
2009-03-30 12:49:05 -07:00
|
|
|
fi
|
2009-03-30 12:40:15 -07:00
|
|
|
;;
|
|
|
|
debian)
|
|
|
|
if [ -z "$DEBOOTSTRAP_MIRROR" ]; then
|
2017-04-29 14:36:06 -04:00
|
|
|
DEBOOTSTRAP_MIRROR="http://deb.debian.org/debian"
|
2009-03-30 12:40:15 -07:00
|
|
|
fi
|
|
|
|
if [ -z "$COMPONENTS" ]; then
|
|
|
|
COMPONENTS="main non-free contrib"
|
|
|
|
fi
|
2012-11-06 11:45:24 +02:00
|
|
|
if [ -z "$SOURCES_PROPOSED_SUITE" ]; then
|
|
|
|
SOURCES_PROPOSED_SUITE="RELEASE-proposed-updates"
|
|
|
|
fi
|
2009-03-30 12:40:15 -07:00
|
|
|
# Debian only performs security updates
|
|
|
|
SKIP_UPDATES=1
|
|
|
|
if [ -z "$SOURCES_SECURITY_SUITE" ]; then
|
2023-01-13 18:48:24 +09:00
|
|
|
if debian_dist_ge "$RELEASE" "bullseye"; then
|
|
|
|
SOURCES_SECURITY_SUITE="RELEASE-security"
|
|
|
|
else
|
|
|
|
SOURCES_SECURITY_SUITE="RELEASE/updates"
|
|
|
|
fi
|
2009-03-30 12:40:15 -07:00
|
|
|
fi
|
|
|
|
if [ -z "$SOURCES_SECURITY_URL" ]; then
|
|
|
|
SOURCES_SECURITY_URL="http://security.debian.org/"
|
|
|
|
fi
|
2012-10-28 18:18:04 +01:00
|
|
|
if [ -n "$TARGET_ARCH" ]; then
|
|
|
|
TARGET_MIRROR="$DEBOOTSTRAP_MIRROR"
|
|
|
|
TARGET_SOURCES_SECURITY_URL="$SOURCES_SECURITY_URL"
|
|
|
|
fi
|
2012-11-06 11:45:24 +02:00
|
|
|
# Unstable and Experimental do not have security or proposed repositories
|
|
|
|
if [ "$RELEASE" = 'unstable' ] || [ "$RELEASE" = 'sid' ] || [ "$RELEASE" = 'experimental' ]; then
|
2009-05-04 09:16:24 -07:00
|
|
|
SKIP_SECURITY=1
|
2012-11-06 11:45:24 +02:00
|
|
|
SKIP_PROPOSED=1
|
2009-05-04 09:16:24 -07:00
|
|
|
fi
|
2010-10-13 13:22:45 -07:00
|
|
|
# Keep the chroot as minimal as possible
|
|
|
|
BUILD_PKGS="--no-install-recommends $BUILD_PKGS"
|
2018-10-23 22:06:10 +02:00
|
|
|
SKIP_RECOMMENDS=1
|
2009-03-30 12:40:15 -07:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown --distro '$DISTRO': aborting" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2008-07-16 17:18:10 -05:00
|
|
|
|
2012-10-28 18:18:04 +01:00
|
|
|
if [ -n "$TARGET_ARCH" ]; then
|
|
|
|
# Ultimately we would like there to be a "cross-build-essential-$arch"
|
|
|
|
# package. In practice, the cross-g++ package is sufficient to pull in
|
|
|
|
# everything we need.
|
2012-10-28 18:33:04 +01:00
|
|
|
if ! target_tuple=$(dpkg-architecture -a"$TARGET_ARCH" -qDEB_HOST_GNU_TYPE 2>/dev/null)
|
2012-10-28 18:18:04 +01:00
|
|
|
then
|
|
|
|
echo "Unknown target architecture $TARGET_ARCH" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-30 15:37:08 +02:00
|
|
|
BUILD_PKGS="$BUILD_PKGS g++-$target_tuple pkg-config dpkg-cross libc-dev:$TARGET_ARCH"
|
2012-10-28 18:18:04 +01:00
|
|
|
fi
|
|
|
|
|
2011-11-16 13:53:29 +02:00
|
|
|
debootstrap_opts="--components=$(echo $COMPONENTS | tr ' ' ,)"
|
2010-07-27 23:07:34 -07:00
|
|
|
if [ -n "$DEBOOTSTRAP_INCLUDE" ] ; then
|
2011-11-16 13:53:29 +02:00
|
|
|
debootstrap_opts="$debootstrap_opts --include=$DEBOOTSTRAP_INCLUDE"
|
2010-07-27 23:07:34 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$DEBOOTSTRAP_EXCLUDE" ] ; then
|
|
|
|
debootstrap_opts="$debootstrap_opts --exclude=$DEBOOTSTRAP_EXCLUDE"
|
|
|
|
fi
|
|
|
|
|
2014-12-23 16:14:21 +00:00
|
|
|
if [ $DEBOOTSTRAP_NO_CHECK_GPG -eq 1 ]; then
|
|
|
|
debootstrap_opts="$debootstrap_opts --no-check-gpg"
|
|
|
|
elif [ -n "$DEBOOTSTRAP_KEYRING" ]; then
|
|
|
|
debootstrap_opts="$debootstrap_opts --keyring=$DEBOOTSTRAP_KEYRING"
|
|
|
|
fi
|
|
|
|
|
2016-05-08 23:18:28 -06:00
|
|
|
if [ -n "$DEBOOTSTRAP_OPTS" ] ; then
|
|
|
|
debootstrap_opts="$debootstrap_opts $DEBOOTSTRAP_OPTS"
|
|
|
|
fi
|
|
|
|
|
2011-10-25 16:33:28 -04:00
|
|
|
# if http_proxy is set in the environment (even empty) set 'proxy' to it
|
2011-12-08 02:23:09 -05:00
|
|
|
[ "$proxy" = "_unset_" -a "${DEBOOTSTRAP_PROXY-xx}" != "xx" ] &&
|
2011-10-25 19:25:09 -04:00
|
|
|
proxy=${DEBOOTSTRAP_PROXY}
|
2011-12-08 02:23:09 -05:00
|
|
|
[ "$proxy" = "_unset_" -a "${http_proxy-xx}" != "xx" ] && proxy=${http_proxy}
|
2011-10-25 16:33:28 -04:00
|
|
|
if [ "$proxy" = "_unset_" ]; then
|
2011-10-25 19:26:16 -04:00
|
|
|
_out=$(apt-config shell x Acquire::HTTP::Proxy) &&
|
|
|
|
_out=$(sh -c 'eval $1 && echo $x' -- "$_out") && [ -n "$_out" ] &&
|
|
|
|
proxy="$_out"
|
2011-10-25 16:33:28 -04:00
|
|
|
fi
|
|
|
|
[ "$proxy" = "_unset_" ] && proxy=""
|
|
|
|
|
2010-02-03 11:46:08 -08:00
|
|
|
DEBOOTSTRAP_COMMAND=debootstrap
|
2010-03-09 08:34:59 +09:00
|
|
|
# Use qemu-kvm-extras-static for foreign chroots
|
2010-03-08 18:05:37 +09:00
|
|
|
if [ "$CHROOT_ARCH" != "$HOST_ARCH" ] ; then
|
|
|
|
case "$CHROOT_ARCH-$HOST_ARCH" in
|
|
|
|
# Sometimes we don't need qemu
|
2023-05-30 21:05:56 -07:00
|
|
|
amd64-i386|arm64-armhf|armhf-arm64|i386-amd64|powerpc-ppc64|ppc64-powerpc)
|
2010-03-08 18:05:37 +09:00
|
|
|
;;
|
|
|
|
# Sometimes we do
|
|
|
|
*)
|
2010-03-09 08:34:59 +09:00
|
|
|
DEBOOTSTRAP_COMMAND=qemu-debootstrap
|
|
|
|
if ! which "$DEBOOTSTRAP_COMMAND"; then
|
2011-04-24 16:42:48 +02:00
|
|
|
sudo apt-get install qemu-user-static
|
2010-03-08 18:05:37 +09:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2010-02-03 11:46:08 -08:00
|
|
|
fi
|
|
|
|
|
2010-02-09 21:29:29 +09:00
|
|
|
case "$SCHROOT_TYPE" in
|
|
|
|
"lvm-snapshot")
|
2010-02-08 20:04:33 -05:00
|
|
|
# Allocate the "golden" chroot LV
|
|
|
|
sudo lvcreate -n "$CHROOT_LV" -L "$LV_SIZE" "$VG"
|
|
|
|
sudo mkfs -t ext4 "$CHROOT_PATH"
|
|
|
|
|
|
|
|
# Mount
|
|
|
|
MNT=`mktemp -d -t schroot-XXXXXX`
|
|
|
|
sudo mount "$CHROOT_PATH" "$MNT"
|
|
|
|
;;
|
2010-02-09 21:29:29 +09:00
|
|
|
"directory")
|
2010-02-08 20:04:33 -05:00
|
|
|
MNT="${CHROOT_PATH}"
|
|
|
|
if [ -d "${MNT}" ]; then
|
2010-02-09 00:22:06 -08:00
|
|
|
echo "E: ${MNT} already exists; aborting" >&2
|
|
|
|
exit 1
|
2010-02-08 20:04:33 -05:00
|
|
|
fi
|
|
|
|
sudo mkdir -p "${MNT}"
|
|
|
|
;;
|
2010-10-25 12:27:50 -04:00
|
|
|
"btrfs-snapshot")
|
|
|
|
MNT="${CHROOT_PATH}"
|
|
|
|
if sudo btrfs subvolume list "${MNT}" >/dev/null 2>&1; then
|
|
|
|
echo "E: Subvolume ${MNT} already exists; aborting" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sudo btrfs subvolume create "${MNT}"
|
|
|
|
;;
|
2021-09-28 19:47:59 +02:00
|
|
|
|
|
|
|
"zfs-snapshot")
|
|
|
|
ZFS_DATASET="${ZFS_PARENT_DATASET}/${CHROOT_NAME}"
|
|
|
|
if sudo zfs list "${ZFS_DATASET}" >/dev/null 2>&1; then
|
|
|
|
echo "E: ZFS dataset ${ZFS_DATASET} already exists; aborting" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sudo zfs create -p -o mountpoint=legacy "${ZFS_DATASET}"
|
|
|
|
|
|
|
|
# Mount
|
|
|
|
MNT=`mktemp -d -t schroot-XXXXXX`
|
|
|
|
sudo mount -t zfs "${ZFS_DATASET}" "${MNT}"
|
|
|
|
;;
|
2010-02-09 22:00:44 +09:00
|
|
|
"file")
|
2010-02-09 21:29:29 +09:00
|
|
|
MNT=`mktemp -d -t schroot-XXXXXX`
|
2010-02-08 20:04:33 -05:00
|
|
|
esac
|
|
|
|
|
2011-11-16 13:52:18 +02:00
|
|
|
case "$SCHROOT_TYPE" in
|
|
|
|
directory|file)
|
2018-04-05 18:51:50 +02:00
|
|
|
if grep -q '\soverlay$' /proc/filesystems \
|
|
|
|
|| /sbin/modprobe -q --dry-run overlay; then
|
|
|
|
OVERLAY_FS=overlay
|
2018-04-05 18:53:29 +02:00
|
|
|
elif grep -q '\soverlayfs$' /proc/filesystems \
|
2018-04-05 18:51:50 +02:00
|
|
|
|| /sbin/modprobe -q --dry-run overlayfs; then
|
|
|
|
OVERLAY_FS=overlayfs
|
|
|
|
else
|
|
|
|
OVERLAY_FS=aufs
|
|
|
|
fi
|
2011-11-16 13:52:18 +02:00
|
|
|
esac
|
|
|
|
|
2011-02-08 16:00:57 -08:00
|
|
|
# work around apt's GPG invocation that fails without root's .gnupg directory
|
|
|
|
sudo mkdir -p -m 0700 "$MNT"/root/.gnupg
|
|
|
|
|
2010-02-08 20:04:33 -05:00
|
|
|
# debootstrap the chroot
|
2022-06-16 10:20:22 +02:00
|
|
|
sudo ${proxy:+"http_proxy=${proxy}"} "$DEBOOTSTRAP_COMMAND" --arch="$CHROOT_ARCH" $variant_opt $debootstrap_opts "$RELEASE" "$MNT" "${DEBOOTSTRAP_MIRROR:-http://archive.ubuntu.com/ubuntu}" "$DEBOOTSTRAP_SCRIPT"
|
2010-02-03 11:46:08 -08:00
|
|
|
|
2021-03-26 13:20:38 +01:00
|
|
|
if [ $EATMYDATA -eq 1 ]; then
|
|
|
|
sudo mkdir -p "${MNT}/usr/local/libexec/mk-sbuild"
|
|
|
|
sudo ln -s /usr/bin/eatmydata "${MNT}/usr/local/libexec/mk-sbuild/dpkg"
|
|
|
|
echo 'Dir::Bin::dpkg "/usr/local/libexec/mk-sbuild/dpkg";' \
|
|
|
|
| sudo tee "${MNT}/etc/apt/apt.conf.d/00mk-sbuild-eatmydata" > /dev/null
|
|
|
|
fi
|
|
|
|
|
2007-06-14 12:29:32 -07:00
|
|
|
# Update the package sources
|
|
|
|
TEMP_SOURCES=`mktemp -t sources-XXXXXX`
|
2007-07-26 16:15:41 +10:00
|
|
|
if [ -z "$TEMPLATE_SOURCES" ]; then
|
2010-02-08 20:04:33 -05:00
|
|
|
TEMPLATE_SOURCES=~/.mk-sbuild.sources
|
2007-07-26 16:15:41 +10:00
|
|
|
fi
|
2012-10-28 18:18:04 +01:00
|
|
|
if [ -n "$TARGET_ARCH" ]; then
|
|
|
|
MIRROR_ARCHS="[arch=$CHROOT_ARCH] "
|
|
|
|
fi
|
2007-06-14 12:29:32 -07:00
|
|
|
if [ -r "$TEMPLATE_SOURCES" ]; then
|
|
|
|
cat "$TEMPLATE_SOURCES" > "$TEMP_SOURCES"
|
|
|
|
else
|
2009-03-30 12:06:04 -07:00
|
|
|
cat > "$TEMP_SOURCES" <<EOM
|
2012-10-28 18:18:04 +01:00
|
|
|
deb ${MIRROR_ARCHS}${DEBOOTSTRAP_MIRROR} RELEASE ${COMPONENTS}
|
2009-03-30 12:40:15 -07:00
|
|
|
deb-src ${DEBOOTSTRAP_MIRROR} RELEASE ${COMPONENTS}
|
2009-01-03 10:50:53 -08:00
|
|
|
EOM
|
2012-10-28 18:18:04 +01:00
|
|
|
if [ -n "$TARGET_ARCH" ]; then
|
|
|
|
cat >> "$TEMP_SOURCES" <<EOM
|
|
|
|
deb [arch=$TARGET_ARCH] $TARGET_MIRROR RELEASE $COMPONENTS
|
|
|
|
EOM
|
|
|
|
fi
|
2011-04-24 21:52:26 +02:00
|
|
|
if [ "$EXPERIMENTAL" -eq 1 ]; then
|
|
|
|
cat >> "$TEMP_SOURCES" <<EOM
|
2012-10-28 18:18:04 +01:00
|
|
|
deb ${MIRROR_ARCHS}${DEBOOTSTRAP_MIRROR} experimental ${COMPONENTS}
|
2011-04-24 21:52:26 +02:00
|
|
|
deb-src ${DEBOOTSTRAP_MIRROR} experimental ${COMPONENTS}
|
|
|
|
EOM
|
2012-10-28 18:18:04 +01:00
|
|
|
if [ -n "$TARGET_ARCH" ]; then
|
|
|
|
cat >> "$TEMP_SOURCES" <<EOM
|
|
|
|
deb [arch=$TARGET_ARCH] $TARGET_MIRROR experimental $COMPONENTS
|
|
|
|
EOM
|
|
|
|
fi
|
2011-04-24 21:52:26 +02:00
|
|
|
fi
|
2009-03-30 12:06:04 -07:00
|
|
|
if [ -z "$SKIP_UPDATES" ]; then
|
|
|
|
cat >> "$TEMP_SOURCES" <<EOM
|
2012-10-28 18:18:04 +01:00
|
|
|
deb ${MIRROR_ARCHS}${DEBOOTSTRAP_MIRROR} RELEASE-updates ${COMPONENTS}
|
2009-03-30 12:40:15 -07:00
|
|
|
deb-src ${DEBOOTSTRAP_MIRROR} RELEASE-updates ${COMPONENTS}
|
2009-01-03 10:50:53 -08:00
|
|
|
EOM
|
2012-10-28 18:18:04 +01:00
|
|
|
if [ -n "$TARGET_ARCH" ]; then
|
|
|
|
cat >> "$TEMP_SOURCES" <<EOM
|
|
|
|
deb [arch=$TARGET_ARCH] $TARGET_MIRROR RELEASE-updates $COMPONENTS
|
2012-11-06 11:45:24 +02:00
|
|
|
EOM
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -z "$SKIP_PROPOSED" ]; then
|
2022-11-16 17:49:13 -08:00
|
|
|
TEMP_PREFERENCES=`mktemp -t preferences-XXXXXX`
|
|
|
|
cat >> "$TEMP_PREFERENCES" <<EOM
|
|
|
|
# override for NotAutomatic: yes
|
|
|
|
Package: *
|
2023-04-12 09:28:38 -07:00
|
|
|
Pin: release a=*-proposed
|
|
|
|
Pin-Priority: 500
|
2022-11-16 17:49:13 -08:00
|
|
|
EOM
|
2012-11-06 11:45:24 +02:00
|
|
|
cat >> "$TEMP_SOURCES" <<EOM
|
|
|
|
deb ${MIRROR_ARCHS}${DEBOOTSTRAP_MIRROR} $SOURCES_PROPOSED_SUITE ${COMPONENTS}
|
|
|
|
deb-src ${DEBOOTSTRAP_MIRROR} $SOURCES_PROPOSED_SUITE ${COMPONENTS}
|
|
|
|
EOM
|
|
|
|
if [ -n "$TARGET_ARCH" ]; then
|
|
|
|
cat >> "$TEMP_SOURCES" <<EOM
|
2012-11-06 11:48:51 +02:00
|
|
|
deb [arch=$TARGET_ARCH] $TARGET_MIRROR $SOURCES_PROPOSED_SUITE $COMPONENTS
|
2012-10-28 18:18:04 +01:00
|
|
|
EOM
|
|
|
|
fi
|
2009-03-30 12:06:04 -07:00
|
|
|
fi
|
2009-05-04 09:16:24 -07:00
|
|
|
if [ -z "$SKIP_SECURITY" ]; then
|
|
|
|
cat >> "$TEMP_SOURCES" <<EOM
|
2012-10-28 18:18:04 +01:00
|
|
|
deb ${MIRROR_ARCHS}${SOURCES_SECURITY_URL} ${SOURCES_SECURITY_SUITE} ${COMPONENTS}
|
2009-03-30 12:40:15 -07:00
|
|
|
deb-src ${SOURCES_SECURITY_URL} ${SOURCES_SECURITY_SUITE} ${COMPONENTS}
|
2007-06-14 12:29:32 -07:00
|
|
|
EOM
|
2012-10-28 18:18:04 +01:00
|
|
|
if [ -n "$TARGET_ARCH" ]; then
|
|
|
|
cat >> "$TEMP_SOURCES" <<EOM
|
|
|
|
deb [arch=$TARGET_ARCH] $TARGET_SOURCES_SECURITY_URL $SOURCES_SECURITY_SUITE $COMPONENTS
|
|
|
|
EOM
|
|
|
|
fi
|
2009-05-04 09:16:24 -07:00
|
|
|
fi
|
2007-06-14 12:29:32 -07:00
|
|
|
fi
|
|
|
|
cat "$TEMP_SOURCES" | sed -e "s|RELEASE|$RELEASE|g" | \
|
|
|
|
sudo bash -c "cat > $MNT/etc/apt/sources.list"
|
|
|
|
rm -f "$TEMP_SOURCES"
|
2022-11-16 17:49:13 -08:00
|
|
|
if [ -n "$TEMP_PREFERENCES" ]; then
|
2023-05-30 09:55:06 -07:00
|
|
|
sudo mv "$TEMP_PREFERENCES" $MNT/etc/apt/preferences.d/proposed.pref
|
2022-11-16 17:49:13 -08:00
|
|
|
fi
|
2011-04-24 21:52:26 +02:00
|
|
|
|
2007-06-14 12:29:32 -07:00
|
|
|
# Copy the timezone (comment this out if you want to leave the chroot at UTC)
|
2016-05-09 00:00:40 -06:00
|
|
|
sudo cp -P --remove-destination /etc/localtime /etc/timezone "$MNT"/etc/
|
2010-02-09 00:22:06 -08:00
|
|
|
# Create a schroot entry for this chroot
|
2007-06-14 12:29:32 -07:00
|
|
|
TEMP_SCHROOTCONF=`mktemp -t schrootconf-XXXXXX`
|
2010-02-08 20:04:33 -05:00
|
|
|
TEMPLATE_SCHROOTCONF=~/.mk-sbuild.schroot.conf
|
2010-02-09 22:00:44 +09:00
|
|
|
TYPED_TEMPLATE_SCHROOTCONF="${TEMPLATE_SCHROOTCONF}.${SCHROOT_TYPE}"
|
2010-02-08 20:04:33 -05:00
|
|
|
|
2010-02-09 00:22:06 -08:00
|
|
|
if [ -r "${TYPED_TEMPLATE_SCHROOTCONF}" ]; then
|
2010-02-08 20:04:33 -05:00
|
|
|
cat "${TYPED_TEMPLATE_SCHROOTCONF}" > "$TEMP_SCHROOTCONF"
|
2011-10-19 22:39:52 +02:00
|
|
|
elif [ -r "${TEMPLATE_SCHROOTCONF}" ]; then
|
2007-06-14 12:29:32 -07:00
|
|
|
cat "$TEMPLATE_SCHROOTCONF" > "$TEMP_SCHROOTCONF"
|
|
|
|
else
|
2011-09-25 16:09:28 +02:00
|
|
|
ADMIN_GROUPS="sbuild,root"
|
|
|
|
if getent group admin > /dev/null; then
|
|
|
|
ADMIN_GROUPS+=",admin"
|
|
|
|
fi
|
|
|
|
cat > "$TEMP_SCHROOTCONF" <<EOM
|
2007-06-14 12:29:32 -07:00
|
|
|
[CHROOT_NAME]
|
|
|
|
description=CHROOT_NAME
|
2011-09-25 16:09:28 +02:00
|
|
|
groups=$ADMIN_GROUPS
|
|
|
|
root-groups=$ADMIN_GROUPS
|
|
|
|
# Uncomment these lines to allow members of these groups to access
|
2010-01-18 16:14:20 -08:00
|
|
|
# the -source chroots directly (useful for automated updates, etc).
|
2011-09-25 16:09:28 +02:00
|
|
|
#source-root-users=$ADMIN_GROUPS
|
|
|
|
#source-root-groups=$ADMIN_GROUPS
|
2010-02-09 22:00:44 +09:00
|
|
|
type=SCHROOT_TYPE
|
2013-05-06 09:47:36 -04:00
|
|
|
profile=$SCHROOT_PROFILE
|
2010-02-09 00:22:06 -08:00
|
|
|
EOM
|
2021-04-26 20:11:42 +02:00
|
|
|
if [ -n "$COMMAND_PREFIX" ]; then
|
|
|
|
cat >> "$TEMP_SCHROOTCONF" <<EOM
|
|
|
|
command-prefix=${COMMAND_PREFIX}
|
|
|
|
EOM
|
|
|
|
fi
|
2010-02-09 22:00:44 +09:00
|
|
|
case "$SCHROOT_TYPE" in
|
|
|
|
"lvm-snapshot")
|
2010-02-09 00:22:06 -08:00
|
|
|
cat >> "$TEMP_SCHROOTCONF" <<EOM
|
|
|
|
device=CHROOT_PATH
|
|
|
|
mount-options=-o noatime
|
|
|
|
lvm-snapshot-options=--size SNAPSHOT_SIZE
|
2007-06-14 12:29:32 -07:00
|
|
|
EOM
|
2010-02-09 21:29:29 +09:00
|
|
|
;;
|
2010-02-09 07:12:39 -08:00
|
|
|
directory|file)
|
2010-02-09 00:22:06 -08:00
|
|
|
cat >> "${TEMP_SCHROOTCONF}" <<EOM
|
2011-11-16 13:52:18 +02:00
|
|
|
union-type=$OVERLAY_FS
|
2010-02-09 07:12:39 -08:00
|
|
|
${SCHROOT_TYPE}=CHROOT_PATH
|
2007-06-14 12:29:32 -07:00
|
|
|
EOM
|
2010-02-09 21:29:29 +09:00
|
|
|
;;
|
2010-10-25 12:27:50 -04:00
|
|
|
btrfs-snapshot)
|
|
|
|
cat >> "${TEMP_SCHROOTCONF}" <<EOM
|
|
|
|
btrfs-source-subvolume=CHROOT_PATH
|
|
|
|
btrfs-snapshot-directory=CHROOT_SNAPSHOT_DIR
|
|
|
|
EOM
|
2010-12-03 00:10:41 +01:00
|
|
|
;;
|
2021-09-28 19:47:59 +02:00
|
|
|
zfs-snapshot)
|
|
|
|
cat >> "${TEMP_SCHROOTCONF}" <<EOM
|
|
|
|
zfs-dataset=ZFS_DATASET
|
|
|
|
EOM
|
|
|
|
;;
|
|
|
|
|
2010-02-09 21:29:29 +09:00
|
|
|
esac
|
2007-06-14 12:29:32 -07:00
|
|
|
fi
|
2008-03-06 11:34:43 -05:00
|
|
|
if [ ! -z "$personality" ]; then
|
|
|
|
echo "personality=$personality" >> "$TEMP_SCHROOTCONF"
|
|
|
|
fi
|
2011-04-24 20:36:27 +02:00
|
|
|
if [ ! -z "$CHROOT_SYNONYM" ]; then
|
|
|
|
echo "aliases=$CHROOT_SYNONYM" >> "$TEMP_SCHROOTCONF"
|
|
|
|
fi
|
2008-06-13 10:53:59 -07:00
|
|
|
if [ ! -z "$SCHROOT_CONF_SUFFIX" ]; then
|
|
|
|
echo "$SCHROOT_CONF_SUFFIX" >> "$TEMP_SCHROOTCONF"
|
|
|
|
fi
|
2011-04-24 19:11:41 +02:00
|
|
|
sed -e "s|CHROOT_NAME|$CHROOT_NAME|g" \
|
|
|
|
-e "s|CHROOT_PATH|$CHROOT_PATH|g" \
|
|
|
|
-e "s|SNAPSHOT_SIZE|$SNAPSHOT_SIZE|g" \
|
|
|
|
-e "s|SCHROOT_TYPE|$SCHROOT_TYPE|g" \
|
|
|
|
-e "s|CHROOT_SNAPSHOT_DIR|$CHROOT_SNAPSHOT_DIR|g" \
|
2021-09-28 19:47:59 +02:00
|
|
|
-e "s|ZFS_DATASET|$ZFS_DATASET|g" \
|
2011-04-24 19:11:41 +02:00
|
|
|
"$TEMP_SCHROOTCONF" \
|
|
|
|
| sudo tee "/etc/schroot/chroot.d/sbuild-$CHROOT_NAME" > /dev/null
|
2007-06-14 12:29:32 -07:00
|
|
|
rm -f "$TEMP_SCHROOTCONF"
|
2011-04-24 12:49:21 +02:00
|
|
|
|
|
|
|
# Disable daemons in chroot:
|
|
|
|
sudo bash -c "cat >> $MNT/usr/sbin/policy-rc.d" <<EOM
|
|
|
|
#!/bin/sh
|
|
|
|
while true; do
|
|
|
|
case "\$1" in
|
|
|
|
-*) shift ;;
|
|
|
|
makedev) exit 0;;
|
|
|
|
x11-common) exit 0;;
|
|
|
|
*) exit 101;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
EOM
|
|
|
|
sudo chmod a+x "$MNT"/usr/sbin/policy-rc.d
|
|
|
|
|
2007-06-14 12:29:32 -07:00
|
|
|
# Create image finalization script
|
|
|
|
sudo bash -c "cat >> $MNT/finish.sh" <<EOM
|
|
|
|
#!/bin/bash
|
2021-04-26 19:29:06 +02:00
|
|
|
if [ "$DEBUG" = 1 ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
2007-06-14 12:29:32 -07:00
|
|
|
set -e
|
2011-10-25 16:33:28 -04:00
|
|
|
if [ -n "$proxy" ]; then
|
|
|
|
mkdir -p /etc/apt/apt.conf.d/
|
|
|
|
cat > /etc/apt/apt.conf.d/99mk-sbuild-proxy <<EOF
|
2013-04-02 13:55:07 +01:00
|
|
|
// proxy settings copied from mk-sbuild
|
2011-10-25 17:08:29 -04:00
|
|
|
Acquire { HTTP { Proxy "$proxy"; }; };
|
2011-10-25 16:33:28 -04:00
|
|
|
EOF
|
|
|
|
fi
|
2012-10-28 18:18:04 +01:00
|
|
|
EOM
|
|
|
|
|
2018-10-23 22:06:10 +02:00
|
|
|
if [ -n "$SKIP_RECOMMENDS" ]; then
|
|
|
|
sudo bash -c "cat >> $MNT/finish.sh" <<EOM
|
|
|
|
mkdir -p /etc/apt/apt.conf.d/
|
|
|
|
cat > /etc/apt/apt.conf.d/99mk-sbuild-no-recommends <<EOF
|
|
|
|
// disable install recommends
|
|
|
|
APT::Install-Recommends "0";
|
|
|
|
EOF
|
|
|
|
EOM
|
|
|
|
fi
|
|
|
|
|
2012-10-28 18:18:04 +01:00
|
|
|
if [ -n "$TARGET_ARCH" ]; then
|
|
|
|
sudo bash -c "cat >> $MNT/finish.sh" <<EOM
|
|
|
|
# Configure target architecture
|
|
|
|
dpkg --add-architecture "$TARGET_ARCH"
|
|
|
|
EOM
|
|
|
|
fi
|
|
|
|
|
|
|
|
sudo bash -c "cat >> $MNT/finish.sh" <<EOM
|
2007-06-14 12:29:32 -07:00
|
|
|
# Reload package lists
|
|
|
|
apt-get update || true
|
|
|
|
# Pull down signature requirements
|
2009-03-30 12:40:15 -07:00
|
|
|
apt-get -y --force-yes install gnupg ${DISTRO}-keyring
|
2007-06-14 12:29:32 -07:00
|
|
|
# Reload package lists
|
|
|
|
apt-get update || true
|
|
|
|
# Disable debconf questions so that automated builds won't prompt
|
|
|
|
echo set debconf/frontend Noninteractive | debconf-communicate
|
|
|
|
echo set debconf/priority critical | debconf-communicate
|
|
|
|
# Install basic build tool set, trying to match buildd
|
2009-03-17 11:54:51 -05:00
|
|
|
apt-get -y --force-yes install $BUILD_PKGS
|
2007-06-14 12:29:32 -07:00
|
|
|
# Set up expected /dev entries
|
2007-10-23 10:14:41 -07:00
|
|
|
if [ ! -r /dev/stdin ]; then ln -s /proc/self/fd/0 /dev/stdin; fi
|
|
|
|
if [ ! -r /dev/stdout ]; then ln -s /proc/self/fd/1 /dev/stdout; fi
|
|
|
|
if [ ! -r /dev/stderr ]; then ln -s /proc/self/fd/2 /dev/stderr; fi
|
2007-06-14 12:29:32 -07:00
|
|
|
# Clean up
|
2011-10-25 19:19:59 -04:00
|
|
|
rm /finish.sh
|
2007-06-14 12:29:32 -07:00
|
|
|
apt-get clean
|
|
|
|
EOM
|
2010-02-09 00:22:06 -08:00
|
|
|
sudo chmod a+x "$MNT"/finish.sh
|
2010-02-08 20:04:33 -05:00
|
|
|
|
2010-02-09 21:29:29 +09:00
|
|
|
case "$SCHROOT_TYPE" in
|
2021-09-28 19:47:59 +02:00
|
|
|
"lvm-snapshot"|"zfs-snapshot")
|
2010-02-09 07:12:39 -08:00
|
|
|
sudo umount "$MNT"
|
|
|
|
rmdir "$MNT"
|
2010-02-09 21:29:29 +09:00
|
|
|
;;
|
2010-10-25 12:27:50 -04:00
|
|
|
"directory"|"btrfs-snapshot")
|
2010-02-09 21:29:29 +09:00
|
|
|
;;
|
2010-02-09 22:00:44 +09:00
|
|
|
"file")
|
2010-02-09 07:12:39 -08:00
|
|
|
cd "$MNT"
|
|
|
|
sudo tar czf "$CHROOT_PATH" .
|
|
|
|
cd /
|
2010-02-09 21:29:29 +09:00
|
|
|
sudo rm -r "$MNT"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2007-06-14 12:29:32 -07:00
|
|
|
# Run finalization script on the "golden" copy via schroot.
|
2012-06-06 09:55:08 -04:00
|
|
|
sudo schroot -c source:$CHROOT_NAME -u root /finish.sh
|
2007-06-14 12:29:32 -07:00
|
|
|
|
|
|
|
# Finished
|
|
|
|
echo ""
|
|
|
|
echo "Done building $CHROOT_NAME."
|
|
|
|
echo ""
|
2012-06-06 09:55:08 -04:00
|
|
|
echo " To CHANGE the golden image: sudo schroot -c source:${CHROOT_NAME} -u root"
|
2007-06-14 12:29:32 -07:00
|
|
|
echo " To ENTER an image snapshot: schroot -c ${CHROOT_NAME}"
|
2010-08-10 11:48:06 -07:00
|
|
|
echo " To BUILD within a snapshot: sbuild -A -d ${CHROOT_NAME} PACKAGE*.dsc"
|
2020-08-12 22:58:54 +03:00
|
|
|
if [ -n "$TARGET_ARCH" ] && [ "$CHROOT_ARCH" != "$TARGET_ARCH" ] ; then
|
2014-07-16 14:46:17 +08:00
|
|
|
echo " To BUILD for ${TARGET_ARCH}: sbuild -A -d ${CHROOT_NAME} --host ${TARGET_ARCH} PACKAGE*.dsc"
|
2014-07-16 07:23:54 +08:00
|
|
|
fi
|
2007-06-14 12:29:32 -07:00
|
|
|
echo ""
|
2011-04-24 16:39:39 +02:00
|
|
|
|
|
|
|
# vi: set et:
|