2007-06-14 12:29:32 -07:00
|
|
|
#!/bin/bash
|
2008-08-11 20:06:35 +02:00
|
|
|
#
|
2010-02-09 00:22:06 -08:00
|
|
|
# Copyright 2006-2010 (C) Canonical Ltd.
|
2009-03-30 12:40:15 -07:00
|
|
|
# Author: Kees Cook <kees@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
|
|
|
|
# (either with LVM 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
|
|
|
|
|
2009-05-04 10:38:32 -07:00
|
|
|
# For when schroot enters the chroot, we cannot be in a directory that
|
|
|
|
# will not exist in the chroot.
|
|
|
|
cd /
|
|
|
|
|
2007-06-14 12:29:32 -07:00
|
|
|
# Make sure we've got a regular user
|
|
|
|
if [ -w /etc/passwd ]; then
|
|
|
|
echo "Please run this script as a regular user, not root." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Perform once-only things to initially set up for using sbuild+schroot+lvm
|
|
|
|
if [ ! -w /var/lib/sbuild ]; then
|
|
|
|
# Load all the packages you'll need to do work
|
|
|
|
sudo apt-get install sbuild schroot debootstrap lvm2
|
|
|
|
# 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
|
|
|
|
# (mandatory, no default!).
|
|
|
|
\$maintainer_name='$USER <$USER@localhost>';
|
|
|
|
|
|
|
|
# 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
|
2009-03-30 11:52:00 -07:00
|
|
|
# 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
|
2007-06-14 12:29:32 -07:00
|
|
|
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
|
|
|
|
|
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"
|
2008-06-13 10:53:59 -07:00
|
|
|
|
2007-06-14 12:29:32 -07:00
|
|
|
function usage()
|
|
|
|
{
|
2010-02-08 20:04:33 -05:00
|
|
|
echo "Usage: $0 [OPTIONS] Release" >&2
|
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"
|
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"
|
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-02-09 00:22:06 -08:00
|
|
|
echo " --distro=DISTRO Install specific distro:"
|
|
|
|
echo " 'ubuntu'(default), or 'debian'"
|
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 00:22:06 -08:00
|
|
|
echo " SOURCE_CHROOTS_DIR Directory to put aufs source chroots into"
|
2008-06-13 10:53:59 -07:00
|
|
|
echo " SCHROOT_CONF_SUFFIX Lines to append to schroot.conf entries"
|
2009-01-03 10:50:53 -08:00
|
|
|
echo " SKIP_UPDATES Enable --skip-updates"
|
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"
|
2007-06-14 12:29:32 -07:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
usage
|
|
|
|
fi
|
2010-02-09 00:22:06 -08:00
|
|
|
OPTS=`getopt -o '' --long "help,debug,skip-updates,arch:,name:,source-template:,debootstrap-mirror:,personality:,distro:,volume-group:,vg:" -- "$@"`
|
2007-06-14 12:29:32 -07:00
|
|
|
eval set -- "$OPTS"
|
|
|
|
|
2010-02-08 20:04:33 -05:00
|
|
|
VG=""
|
2009-03-30 12:40:15 -07:00
|
|
|
DISTRO="ubuntu"
|
2007-06-14 12:29:32 -07:00
|
|
|
name=""
|
|
|
|
while :; do
|
|
|
|
case "$1" in
|
|
|
|
--debug)
|
|
|
|
set -x
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--arch)
|
|
|
|
# By default, use the native architecture.
|
2010-02-03 12:35:57 -08:00
|
|
|
arch_opt="--arch=$2"
|
2007-06-14 12:29:32 -07:00
|
|
|
arch_suffix="-$2"
|
2009-12-12 14:04:01 +09:00
|
|
|
CHROOT_ARCH="$2"
|
2008-07-16 17:18:10 -05:00
|
|
|
if [ "$2" = "i386" ] || [ "$2" = "lpia" ] && [ -z "$personality" ];
|
2008-03-11 09:23:50 +01:00
|
|
|
then
|
|
|
|
personality="linux32"
|
|
|
|
fi
|
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
|
|
|
|
;;
|
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
|
|
|
|
;;
|
2009-03-30 12:40:15 -07:00
|
|
|
--distro)
|
|
|
|
DISTRO="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2010-02-09 00:22:06 -08:00
|
|
|
--volume-group|--vg)
|
2010-02-08 20:04:33 -05:00
|
|
|
VG="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2007-06-14 12:29:32 -07:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
--help|*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2010-02-09 00:22:06 -08:00
|
|
|
# We need to know the release 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
|
|
|
|
|
|
|
|
# By default, name the schroot the same as the release
|
|
|
|
if [ -z "$name" ]; then
|
|
|
|
name="$RELEASE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
CHROOT_NAME="${name}${arch_suffix}"
|
|
|
|
|
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-03 11:46:08 -08:00
|
|
|
CHROOT_ARCH=$HOST_ARCH
|
2009-12-12 14:04:01 +09:00
|
|
|
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
|
|
|
|
|
2010-02-09 00:22:06 -08:00
|
|
|
SRC_TYPE="union"
|
|
|
|
SCHROOT_CONF_TYPE="directory"
|
|
|
|
# To build the LV, we need to know which volume group to use
|
|
|
|
if [ -n "${VG}" ]; then
|
|
|
|
SRC_TYPE="lvm"
|
|
|
|
SCHROOT_CONF_TYPE="lvm-snapshot"
|
2007-06-14 12:29:32 -07:00
|
|
|
fi
|
|
|
|
|
2010-02-08 20:04:33 -05:00
|
|
|
case "$SRC_TYPE" in
|
|
|
|
"lvm")
|
|
|
|
# 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
|
|
|
|
CHROOT_LV="${name}_chroot${arch_suffix}"
|
|
|
|
CHROOT_PATH="/dev/$VG/$CHROOT_LV"
|
|
|
|
# Does the specified VG exist? (vgdisplay doesn't set error codes...)
|
|
|
|
if [ `sudo vgdisplay -c "$VG" | wc -l` -eq 0 ]; then
|
2010-02-09 00:22:06 -08:00
|
|
|
exit 1
|
2010-02-08 20:04:33 -05:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"union")
|
|
|
|
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 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"
|
2008-01-21 09:45:16 -08:00
|
|
|
if [ ! -r "/usr/share/debootstrap/scripts/$RELEASE" ]; then
|
2007-06-14 12:29:32 -07:00
|
|
|
echo "Specified release not known to debootstrap" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-03-30 12:49:05 -07:00
|
|
|
BUILD_PKGS="build-essential fakeroot devscripts 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"
|
|
|
|
;;
|
|
|
|
armel | hppa | ia64 | lpia | sparc)
|
|
|
|
DEBOOTSTRAP_MIRROR="http://ports.ubuntu.com/ubuntu-ports"
|
|
|
|
;;
|
|
|
|
powerpc)
|
|
|
|
if [ "$RELEASE" != "dapper" ]; then
|
|
|
|
DEBOOTSTRAP_MIRROR="http://ports.ubuntu.com/ubuntu-ports"
|
|
|
|
else
|
|
|
|
DEBOOTSTRAP_MIRROR="http://archive.ubuntu.com/ubuntu"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2009-03-30 12:40:15 -07:00
|
|
|
fi
|
|
|
|
if [ -z "$COMPONENTS" ]; then
|
|
|
|
COMPONENTS="main restricted universe multiverse"
|
|
|
|
fi
|
|
|
|
if [ -z "$SOURCES_SECURITY_SUITE" ]; then
|
2009-12-15 09:59:51 +09: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"
|
|
|
|
;;
|
|
|
|
armel | hppa | ia64 | lpia | sparc)
|
|
|
|
SOURCES_SECURITY_URL="http://ports.ubuntu.com/ubuntu-ports"
|
|
|
|
;;
|
|
|
|
powerpc)
|
|
|
|
if [ "$RELEASE" != "dapper" ]; then
|
|
|
|
SOURCES_SECURITY_URL="http://ports.ubuntu.com/ubuntu-ports"
|
|
|
|
else
|
|
|
|
SOURCES_SECURITY_URL="http://security.ubuntu.com/ubuntu"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2009-03-30 12:40:15 -07:00
|
|
|
fi
|
2009-03-30 12:49:05 -07:00
|
|
|
# Add edgy+ buildd tools
|
|
|
|
if [ "$RELEASE" != "breezy" ] && [ "$RELEASE" != "dapper" ]; then
|
|
|
|
# Disable recommends for a smaller chroot (gutsy and later only)
|
|
|
|
BUILD_PKGS="--no-install-recommends $BUILD_PKGS"
|
|
|
|
# Add buildd tools
|
|
|
|
BUILD_PKGS="$BUILD_PKGS pkg-create-dbgsym pkgbinarymangler"
|
|
|
|
fi
|
2009-03-30 12:40:15 -07:00
|
|
|
;;
|
|
|
|
debian)
|
|
|
|
if [ -z "$DEBOOTSTRAP_MIRROR" ]; then
|
|
|
|
DEBOOTSTRAP_MIRROR="http://ftp.debian.org/debian"
|
|
|
|
fi
|
|
|
|
if [ -z "$COMPONENTS" ]; then
|
|
|
|
COMPONENTS="main non-free contrib"
|
|
|
|
fi
|
|
|
|
# Debian only performs security updates
|
|
|
|
SKIP_UPDATES=1
|
|
|
|
if [ -z "$SOURCES_SECURITY_SUITE" ]; then
|
|
|
|
SOURCES_SECURITY_SUITE="RELEASE/updates"
|
|
|
|
fi
|
|
|
|
if [ -z "$SOURCES_SECURITY_URL" ]; then
|
|
|
|
SOURCES_SECURITY_URL="http://security.debian.org/"
|
|
|
|
fi
|
2009-05-04 09:16:24 -07:00
|
|
|
# Unstable (aka "sid") does not have a security repository
|
|
|
|
if [ "$RELEASE" = 'unstable' ] || [ "$RELEASE" = 'sid' ]; then
|
|
|
|
SKIP_SECURITY=1
|
|
|
|
fi
|
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
|
|
|
|
2010-02-03 11:46:08 -08:00
|
|
|
DEBOOTSTRAP_COMMAND=debootstrap
|
|
|
|
# Use qemu-arm-static / build-arm-chroot for foreign armel chroots
|
|
|
|
if [ "$CHROOT_ARCH" = 'armel' ] && [ ! "$HOST_ARCH" = 'armel' ] ; then
|
|
|
|
if [ -f "/usr/bin/build-arm-chroot" ]; then
|
2010-02-09 00:22:06 -08:00
|
|
|
DEBOOTSTRAP_COMMAND=build-arm-chroot
|
2010-02-03 11:46:08 -08:00
|
|
|
else
|
2010-02-09 00:22:06 -08:00
|
|
|
echo 'Please install qemu-arm-static to use foreign armel chroots' >&2
|
|
|
|
exit 1
|
2010-02-03 11:46:08 -08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-02-08 20:04:33 -05:00
|
|
|
case "$SRC_TYPE" in
|
|
|
|
"lvm")
|
|
|
|
# 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"
|
|
|
|
;;
|
|
|
|
"union")
|
|
|
|
CHROOT_PATH="${SOURCE_CHROOTS_DIR}/${CHROOT_NAME}"
|
|
|
|
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}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# debootstrap the chroot
|
2010-02-03 11:46:08 -08:00
|
|
|
sudo $DEBOOTSTRAP_COMMAND $arch_opt $variant_opt "$RELEASE" "$MNT" "${DEBOOTSTRAP_MIRROR:-http://archive.ubuntu.com/ubuntu}"
|
|
|
|
|
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
|
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
|
2009-03-30 12:40:15 -07:00
|
|
|
deb ${DEBOOTSTRAP_MIRROR} RELEASE ${COMPONENTS}
|
|
|
|
deb-src ${DEBOOTSTRAP_MIRROR} RELEASE ${COMPONENTS}
|
2009-01-03 10:50:53 -08:00
|
|
|
EOM
|
2009-03-30 12:06:04 -07:00
|
|
|
if [ -z "$SKIP_UPDATES" ]; then
|
|
|
|
cat >> "$TEMP_SOURCES" <<EOM
|
2009-03-30 12:40:15 -07:00
|
|
|
deb ${DEBOOTSTRAP_MIRROR} RELEASE-updates ${COMPONENTS}
|
|
|
|
deb-src ${DEBOOTSTRAP_MIRROR} RELEASE-updates ${COMPONENTS}
|
2009-01-03 10:50:53 -08:00
|
|
|
EOM
|
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
|
2009-03-30 12:40:15 -07:00
|
|
|
deb ${SOURCES_SECURITY_URL} ${SOURCES_SECURITY_SUITE} ${COMPONENTS}
|
|
|
|
deb-src ${SOURCES_SECURITY_URL} ${SOURCES_SECURITY_SUITE} ${COMPONENTS}
|
2007-06-14 12:29:32 -07:00
|
|
|
EOM
|
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"
|
|
|
|
# Copy the timezone (comment this out if you want to leave the chroot at UTC)
|
|
|
|
sudo cp /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
|
|
|
|
TYPED_TEMPLATE_SCHROOTCONF="${TEMPLATE_SCHROOTCONF}.${SCHROOT_CONF_TYPE}"
|
|
|
|
|
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"
|
2010-02-09 00:22:06 -08:00
|
|
|
elif [ -r "${TEMPLATE_SCHROOT}" ]; then
|
2007-06-14 12:29:32 -07:00
|
|
|
cat "$TEMPLATE_SCHROOTCONF" > "$TEMP_SCHROOTCONF"
|
|
|
|
else
|
2010-02-08 20:04:33 -05:00
|
|
|
cat > "$TEMP_SCHROOTCONF" <<EOM
|
2007-06-14 12:29:32 -07:00
|
|
|
|
|
|
|
[CHROOT_NAME]
|
|
|
|
description=CHROOT_NAME
|
|
|
|
priority=3
|
|
|
|
groups=sbuild,root,admin
|
|
|
|
root-groups=root,sbuild,admin
|
2010-01-18 16:14:20 -08:00
|
|
|
# Uncomment these lines to allow "sbuild" and "admin" users to access
|
|
|
|
# the -source chroots directly (useful for automated updates, etc).
|
|
|
|
#source-root-users=root,sbuild,admin
|
|
|
|
#source-root-groups=root,sbuild,admin
|
2010-02-09 00:22:06 -08:00
|
|
|
type=SCHROOT_CONF_TYPE
|
|
|
|
EOM
|
|
|
|
if [ "${SRC_TYPE}" = "lvm" ]; then
|
|
|
|
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-08 20:04:33 -05:00
|
|
|
elif [ "${SRC_TYPE}" = "union" ]; then
|
2010-02-09 00:22:06 -08:00
|
|
|
cat >> "${TEMP_SCHROOTCONF}" <<EOM
|
2010-02-08 20:04:33 -05:00
|
|
|
union-type=aufs
|
|
|
|
directory=CHROOT_PATH
|
2007-06-14 12:29:32 -07:00
|
|
|
EOM
|
2010-02-08 20:04:33 -05:00
|
|
|
fi
|
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
|
2008-06-13 10:53:59 -07:00
|
|
|
if [ ! -z "$SCHROOT_CONF_SUFFIX" ]; then
|
|
|
|
echo "$SCHROOT_CONF_SUFFIX" >> "$TEMP_SCHROOTCONF"
|
|
|
|
fi
|
2007-06-14 12:29:32 -07:00
|
|
|
cat "$TEMP_SCHROOTCONF" | sed \
|
|
|
|
-e "s|CHROOT_NAME|$CHROOT_NAME|g" \
|
|
|
|
-e "s|CHROOT_PATH|$CHROOT_PATH|g" \
|
2008-06-13 10:53:59 -07:00
|
|
|
-e "s|SNAPSHOT_SIZE|$SNAPSHOT_SIZE|g" \
|
2010-02-09 00:22:06 -08:00
|
|
|
-e "s|SCHROOT_CONF_TYPE|$SCHROOT_CONF_TYPE|g" \
|
2007-06-14 12:29:32 -07:00
|
|
|
| \
|
|
|
|
sudo bash -c "cat >> /etc/schroot/schroot.conf"
|
|
|
|
rm -f "$TEMP_SCHROOTCONF"
|
|
|
|
# Create image finalization script
|
|
|
|
sudo bash -c "cat >> $MNT/finish.sh" <<EOM
|
|
|
|
#!/bin/bash
|
|
|
|
#set -x
|
|
|
|
set -e
|
2009-09-10 10:22:23 -07:00
|
|
|
export http_proxy=${http_proxy}
|
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
|
|
|
|
apt-get clean
|
|
|
|
rm /finish.sh
|
|
|
|
EOM
|
2010-02-09 00:22:06 -08:00
|
|
|
sudo chmod a+x "$MNT"/finish.sh
|
2010-02-08 20:04:33 -05:00
|
|
|
|
|
|
|
if [ "$SRC_TYPE" = "lvm" ]; then
|
|
|
|
sudo umount "$MNT"
|
|
|
|
rmdir "$MNT"
|
|
|
|
fi
|
2007-06-14 12:29:32 -07:00
|
|
|
# Run finalization script on the "golden" copy via schroot.
|
2010-01-17 11:12:05 +09:00
|
|
|
sudo schroot -c "$CHROOT_NAME"-source -u root /finish.sh
|
2007-06-14 12:29:32 -07:00
|
|
|
|
|
|
|
# Finished
|
|
|
|
echo ""
|
|
|
|
echo "Done building $CHROOT_NAME."
|
|
|
|
echo ""
|
2010-01-17 11:12:05 +09:00
|
|
|
echo " To CHANGE the golden image: sudo schroot -c ${CHROOT_NAME}-source -u root"
|
2007-06-14 12:29:32 -07:00
|
|
|
echo " To ENTER an image snapshot: schroot -c ${CHROOT_NAME}"
|
|
|
|
echo " To BUILD within a snapshot: sbuild -d ${CHROOT_NAME} PACKAGE*.dsc"
|
|
|
|
echo ""
|