* mk-sbuild: automatically install qemu-kvm-extras-static if requested

* mk-sbuild: conditionally install lvm2 only for lv-snapshot schroots
* mk-sbuild: rationalise architecture variables
* mk-sbuild: Generalise --type support and add "file" SCHROOT_TYPE
* mk-sbuild.1: Document the --type argument
This commit is contained in:
Emmet Hikory 2010-02-09 22:36:18 +09:00
commit 47be819276
3 changed files with 96 additions and 48 deletions

7
debian/changelog vendored
View File

@ -5,6 +5,11 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low
[ Emmet Hikory ] [ Emmet Hikory ]
* Support qemu-arm-static -> qemu-kvm-extras-static transition * Support qemu-arm-static -> qemu-kvm-extras-static transition
* mk-sbuild: automatically install qemu-kvm-extras-static if requested
* mk-sbuild: conditionally install lvm2 only for lv-snapshot schroots
* mk-sbuild: rationalise architecture variables
* mk-sbuild: Generalise --type support and add "file" SCHROOT_TYPE
* mk-sbuild.1: Document the --type argument
[ Loïc Minier ] [ Loïc Minier ]
* Demote qemu-kvm-extras-static to a Suggests since most people don't build * Demote qemu-kvm-extras-static to a Suggests since most people don't build
@ -17,7 +22,7 @@ ubuntu-dev-tools (0.93) UNRELEASED; urgency=low
* mk-sbuild.1: update documentation to reflect alternative config file * mk-sbuild.1: update documentation to reflect alternative config file
names for distro and schroot type overrides. names for distro and schroot type overrides.
-- Kees Cook <kees@ubuntu.com> Tue, 09 Feb 2010 00:14:26 -0800 -- Emmet Hikory <persia@ubuntu.com> Tue, 09 Feb 2010 22:08:56 +0900
ubuntu-dev-tools (0.92) lucid; urgency=low ubuntu-dev-tools (0.92) lucid; urgency=low

View File

@ -41,8 +41,11 @@ Enable distro-specific logic. Currently known distros: "ubuntu" (default)
and "debian". and "debian".
.TP .TP
.B \-\-vg .B \-\-vg
Specify a volume group, and subsequently use SCHROOT_TYPE of "lvm-snapshot" Specify a volume group, and subsequently use a default SCHROOT_TYPE of
rather than "directory" (via aufs) mounts. "lvm-snapshot" rather than "directory" (via aufs) mounts.
.TP
.B \-\-type
Specify a SCHROOT_TYPE. Supported values are "directory" (default if --vg not specified), "lvm-snapshot" (default if --vg specified), and "file".
.SH ENVIRONMENT VARIABLES .SH ENVIRONMENT VARIABLES
.TP .TP
@ -61,6 +64,10 @@ Do not include the \-updates pocket in the installed sources.list.
.B SOURCE_CHROOTS_DIR .B SOURCE_CHROOTS_DIR
use SOURCE_CHROOTS_DIR as home of schroot source directories. (default use SOURCE_CHROOTS_DIR as home of schroot source directories. (default
/var/lib/schroot/chroots) /var/lib/schroot/chroots)
.TP
.B SOURCE_CHROOTS_TGZ
use SOURCE_CHROOTS_TGZ as home of schroot source tarballs. (default
/var/lib/schroot/tarballs)
.SH FILES .SH FILES
.TP .TP
@ -77,8 +84,8 @@ See sources.list(5) for more details on the format.
.B $HOME/.mk\-sbuild.schroot.conf[.$SCHROOT_TYPE] .B $HOME/.mk\-sbuild.schroot.conf[.$SCHROOT_TYPE]
Can contain a customized configuration section to be inserted into Can contain a customized configuration section to be inserted into
/etc/schroot/schroot.conf. /etc/schroot/schroot.conf.
If a file with ".lvm-snapshot" or ".directory" is found (based on the presence If a file with ".lvm-snapshot", ".directory", or ".file" is found (based on the
of the \-\-vg argument) that file will use used instead. values of the \-\-vg and \-\-type arguments) that file will use used instead.
See schroot.conf(5) for more details on the format. See schroot.conf(5) for more details on the format.
.SH USING THE CHROOTS .SH USING THE CHROOTS
.TP .TP

120
mk-sbuild
View File

@ -1,4 +1,4 @@
#!/bin/bash # !/bin/bash
# #
# Copyright 2006-2010 (C) Canonical Ltd. # Copyright 2006-2010 (C) Canonical Ltd.
# Author: Kees Cook <kees@ubuntu.com> # Author: Kees Cook <kees@ubuntu.com>
@ -37,10 +37,10 @@ if [ -w /etc/passwd ]; then
exit 1 exit 1
fi fi
# Perform once-only things to initially set up for using sbuild+schroot+lvm # Perform once-only things to initially set up for using sbuild+schroot
if [ ! -w /var/lib/sbuild ]; then if [ ! -w /var/lib/sbuild ]; then
# Load all the packages you'll need to do work # Load all the packages you'll need to do work
sudo apt-get install sbuild schroot debootstrap lvm2 sudo apt-get install sbuild schroot debootstrap
# Add self to the sbuild group # Add self to the sbuild group
sudo adduser "$USER" sbuild sudo adduser "$USER" sbuild
@ -95,6 +95,7 @@ fi
LV_SIZE="5G" LV_SIZE="5G"
SNAPSHOT_SIZE="4G" SNAPSHOT_SIZE="4G"
SOURCE_CHROOTS_DIR="/var/lib/schroot/chroots" SOURCE_CHROOTS_DIR="/var/lib/schroot/chroots"
SOURCE_CHROOTS_TGZ="/var/lib/schroot/tarballs"
function usage() function usage()
{ {
@ -110,11 +111,13 @@ function usage()
echo " --debootstrap-mirror=URL Use URL as the debootstrap source" echo " --debootstrap-mirror=URL Use URL as the debootstrap source"
echo " --distro=DISTRO Install specific distro:" echo " --distro=DISTRO Install specific distro:"
echo " 'ubuntu'(default), or 'debian'" echo " 'ubuntu'(default), or 'debian'"
echo " --type=SCHROOT_TYPE Define the schroot type"
echo "" echo ""
echo "Configuration (via ~/.mk-sbuild.rc)" echo "Configuration (via ~/.mk-sbuild.rc)"
echo " LV_SIZE Size of source LVs (default ${LV_SIZE})" echo " LV_SIZE Size of source LVs (default ${LV_SIZE})"
echo " SNAPSHOT_SIZE Size of snapshot LVs (default ${SNAPSHOT_SIZE})" echo " SNAPSHOT_SIZE Size of snapshot LVs (default ${SNAPSHOT_SIZE})"
echo " SOURCE_CHROOTS_DIR Directory to put aufs source chroots into" echo " SOURCE_CHROOTS_DIR Directory to store directory source chroots"
echo " SOURCE_CHROOTS_TGZ Directory to store file source chroots"
echo " SCHROOT_CONF_SUFFIX Lines to append to schroot.conf entries" echo " SCHROOT_CONF_SUFFIX Lines to append to schroot.conf entries"
echo " SKIP_UPDATES Enable --skip-updates" echo " SKIP_UPDATES Enable --skip-updates"
echo " TEMPLATE_SOURCES A template for sources.list" echo " TEMPLATE_SOURCES A template for sources.list"
@ -126,7 +129,7 @@ function usage()
if [ -z "$1" ]; then if [ -z "$1" ]; then
usage usage
fi fi
OPTS=`getopt -o '' --long "help,debug,skip-updates,arch:,name:,source-template:,debootstrap-mirror:,personality:,distro:,volume-group:,vg:" -- "$@"` OPTS=`getopt -o '' --long "help,debug,skip-updates,arch:,name:,source-template:,debootstrap-mirror:,personality:,distro:,volume-group:,vg:,type:" -- "$@"`
eval set -- "$OPTS" eval set -- "$OPTS"
VG="" VG=""
@ -139,9 +142,6 @@ while :; do
shift shift
;; ;;
--arch) --arch)
# By default, use the native architecture.
arch_opt="--arch=$2"
arch_suffix="-$2"
CHROOT_ARCH="$2" CHROOT_ARCH="$2"
if [ "$2" = "i386" ] || [ "$2" = "lpia" ] && [ -z "$personality" ]; if [ "$2" = "i386" ] || [ "$2" = "lpia" ] && [ -z "$personality" ];
then then
@ -181,6 +181,10 @@ while :; do
VG="$2" VG="$2"
shift 2 shift 2
;; ;;
--type)
SCHROOT_TYPE="$2"
shift 2
;;
--) --)
shift shift
break break
@ -191,7 +195,7 @@ while :; do
esac esac
done done
# We need to know the release to debootstrap # To build the chroot, we need to know which release of Ubuntu to debootstrap
RELEASE="$1" RELEASE="$1"
if [ -z "$RELEASE" ]; then if [ -z "$RELEASE" ]; then
usage usage
@ -202,28 +206,30 @@ if [ -z "$name" ]; then
name="$RELEASE" name="$RELEASE"
fi fi
CHROOT_NAME="${name}${arch_suffix}" # By default, use the native architecture.
HOST_ARCH=$(dpkg --print-architecture) HOST_ARCH=$(dpkg --print-architecture)
if [ -z "$CHROOT_ARCH" ]; then if [ -z "$CHROOT_ARCH" ]; then
CHROOT_ARCH=$HOST_ARCH CHROOT_ARCH="$HOST_ARCH"
fi fi
CHROOT_NAME="${name}-${CHROOT_ARCH}"
# Load customizations # Load customizations
if [ -r ~/.mk-sbuild.rc ]; then if [ -r ~/.mk-sbuild.rc ]; then
. ~/.mk-sbuild.rc . ~/.mk-sbuild.rc
fi fi
SRC_TYPE="union" if [ -z "$SCHROOT_TYPE" ]; then
SCHROOT_CONF_TYPE="directory" # To build the LV, we need to know which volume group to use
# To build the LV, we need to know which volume group to use if [ -n "$VG" ]; then
if [ -n "${VG}" ]; then SCHROOT_TYPE=lvm-snapshot
SRC_TYPE="lvm" else
SCHROOT_CONF_TYPE="lvm-snapshot" SCHROOT_TYPE=directory
fi
fi fi
case "$SRC_TYPE" in case "$SCHROOT_TYPE" in
"lvm") "lvm-snapshot")
# Make sure LVM tools that operate on the snapshots have needed module # Make sure LVM tools that operate on the snapshots have needed module
if ! sudo dmsetup targets | grep -q ^snapshot; then if ! sudo dmsetup targets | grep -q ^snapshot; then
sudo modprobe dm_snapshot sudo modprobe dm_snapshot
@ -231,17 +237,28 @@ case "$SRC_TYPE" in
fi fi
# Set up some variables for use in the paths and names # Set up some variables for use in the paths and names
CHROOT_LV="${name}_chroot${arch_suffix}" CHROOT_LV="${name}_chroot-${CHROOT_ARCH}"
CHROOT_PATH="/dev/$VG/$CHROOT_LV" CHROOT_PATH="/dev/$VG/$CHROOT_LV"
# Does the specified VG exist? (vgdisplay doesn't set error codes...) # Does the specified VG exist? (vgdisplay doesn't set error codes...)
if [ `sudo vgdisplay -c "$VG" | wc -l` -eq 0 ]; then if [ `sudo vgdisplay -c "$VG" | wc -l` -eq 0 ]; then
echo "Volume group ${VG} does not appear to exist" >&2
exit 1 exit 1
fi fi
;; ;;
"union") "directory")
if [ ! -d "${SOURCE_CHROOTS_DIR}" ]; then if [ ! -d "${SOURCE_CHROOTS_DIR}" ]; then
sudo mkdir -p "${SOURCE_CHROOTS_DIR}" sudo mkdir -p "${SOURCE_CHROOTS_DIR}"
fi fi
# Set up some variables for use in the paths and names
CHROOT_PATH="${SOURCE_CHROOTS_DIR}/${CHROOT_NAME}"
;;
"file")
if [ ! -d "$SOURCE_CHROOTS_TGZ" ]; then
sudo mkdir -p "$SOURCE_CHROOTS_TGZ"
fi
# Set up some variables for use in the paths and names
CHROOT_PATH="${SOURCE_CHROOTS_TGZ}/${CHROOT_NAME}.tgz"
;; ;;
*) *)
echo 'unknown source type!?' >&2 echo 'unknown source type!?' >&2
@ -335,18 +352,19 @@ debian)
esac esac
DEBOOTSTRAP_COMMAND=debootstrap DEBOOTSTRAP_COMMAND=debootstrap
# Use qemu-arm-static / build-arm-chroot for foreign armel chroots # Use qemu-kvm-extras-static / build-arm-chroot for foreign armel chroots
if [ "$CHROOT_ARCH" = 'armel' ] && [ ! "$HOST_ARCH" = 'armel' ] ; then if [ "$CHROOT_ARCH" = 'armel' ] && [ ! "$HOST_ARCH" = 'armel' ] ; then
if [ -f "/usr/bin/build-arm-chroot" ]; then if [ ! -f "/usr/bin/build-arm-chroot" ]; then
DEBOOTSTRAP_COMMAND=build-arm-chroot sudo apt-get install qemu-kvm-extras-static
else
echo 'Please install qemu-arm-static to use foreign armel chroots' >&2
exit 1
fi fi
DEBOOTSTRAP_COMMAND=build-arm-chroot
fi fi
case "$SRC_TYPE" in case "$SCHROOT_TYPE" in
"lvm") "lvm-snapshot")
# Install lvm2 if missing
dpkg -l lvm2 > /dev/null || sudo apt-get install lvm2
# Allocate the "golden" chroot LV # Allocate the "golden" chroot LV
sudo lvcreate -n "$CHROOT_LV" -L "$LV_SIZE" "$VG" sudo lvcreate -n "$CHROOT_LV" -L "$LV_SIZE" "$VG"
sudo mkfs -t ext4 "$CHROOT_PATH" sudo mkfs -t ext4 "$CHROOT_PATH"
@ -355,8 +373,7 @@ case "$SRC_TYPE" in
MNT=`mktemp -d -t schroot-XXXXXX` MNT=`mktemp -d -t schroot-XXXXXX`
sudo mount "$CHROOT_PATH" "$MNT" sudo mount "$CHROOT_PATH" "$MNT"
;; ;;
"union") "directory")
CHROOT_PATH="${SOURCE_CHROOTS_DIR}/${CHROOT_NAME}"
MNT="${CHROOT_PATH}" MNT="${CHROOT_PATH}"
if [ -d "${MNT}" ]; then if [ -d "${MNT}" ]; then
echo "E: ${MNT} already exists; aborting" >&2 echo "E: ${MNT} already exists; aborting" >&2
@ -364,10 +381,12 @@ case "$SRC_TYPE" in
fi fi
sudo mkdir -p "${MNT}" sudo mkdir -p "${MNT}"
;; ;;
"file")
MNT=`mktemp -d -t schroot-XXXXXX`
esac esac
# debootstrap the chroot # debootstrap the chroot
sudo $DEBOOTSTRAP_COMMAND $arch_opt $variant_opt "$RELEASE" "$MNT" "${DEBOOTSTRAP_MIRROR:-http://archive.ubuntu.com/ubuntu}" sudo "$DEBOOTSTRAP_COMMAND" --arch="$CHROOT_ARCH" $variant_opt "$RELEASE" "$MNT" "${DEBOOTSTRAP_MIRROR:-http://archive.ubuntu.com/ubuntu}"
# Update the package sources # Update the package sources
TEMP_SOURCES=`mktemp -t sources-XXXXXX` TEMP_SOURCES=`mktemp -t sources-XXXXXX`
@ -402,7 +421,7 @@ sudo cp /etc/localtime /etc/timezone "$MNT"/etc/
# Create a schroot entry for this chroot # Create a schroot entry for this chroot
TEMP_SCHROOTCONF=`mktemp -t schrootconf-XXXXXX` TEMP_SCHROOTCONF=`mktemp -t schrootconf-XXXXXX`
TEMPLATE_SCHROOTCONF=~/.mk-sbuild.schroot.conf TEMPLATE_SCHROOTCONF=~/.mk-sbuild.schroot.conf
TYPED_TEMPLATE_SCHROOTCONF="${TEMPLATE_SCHROOTCONF}.${SCHROOT_CONF_TYPE}" TYPED_TEMPLATE_SCHROOTCONF="${TEMPLATE_SCHROOTCONF}.${SCHROOT_TYPE}"
if [ -r "${TYPED_TEMPLATE_SCHROOTCONF}" ]; then if [ -r "${TYPED_TEMPLATE_SCHROOTCONF}" ]; then
cat "${TYPED_TEMPLATE_SCHROOTCONF}" > "$TEMP_SCHROOTCONF" cat "${TYPED_TEMPLATE_SCHROOTCONF}" > "$TEMP_SCHROOTCONF"
@ -410,7 +429,6 @@ elif [ -r "${TEMPLATE_SCHROOT}" ]; then
cat "$TEMPLATE_SCHROOTCONF" > "$TEMP_SCHROOTCONF" cat "$TEMPLATE_SCHROOTCONF" > "$TEMP_SCHROOTCONF"
else else
cat > "$TEMP_SCHROOTCONF" <<EOM cat > "$TEMP_SCHROOTCONF" <<EOM
[CHROOT_NAME] [CHROOT_NAME]
description=CHROOT_NAME description=CHROOT_NAME
priority=3 priority=3
@ -420,20 +438,29 @@ root-groups=root,sbuild,admin
# the -source chroots directly (useful for automated updates, etc). # the -source chroots directly (useful for automated updates, etc).
#source-root-users=root,sbuild,admin #source-root-users=root,sbuild,admin
#source-root-groups=root,sbuild,admin #source-root-groups=root,sbuild,admin
type=SCHROOT_CONF_TYPE type=SCHROOT_TYPE
EOM EOM
if [ "${SRC_TYPE}" = "lvm" ]; then case "$SCHROOT_TYPE" in
"lvm-snapshot")
cat >> "$TEMP_SCHROOTCONF" <<EOM cat >> "$TEMP_SCHROOTCONF" <<EOM
device=CHROOT_PATH device=CHROOT_PATH
mount-options=-o noatime mount-options=-o noatime
lvm-snapshot-options=--size SNAPSHOT_SIZE lvm-snapshot-options=--size SNAPSHOT_SIZE
EOM EOM
elif [ "${SRC_TYPE}" = "union" ]; then ;;
"directory")
cat >> "${TEMP_SCHROOTCONF}" <<EOM cat >> "${TEMP_SCHROOTCONF}" <<EOM
union-type=aufs union-type=aufs
directory=CHROOT_PATH directory=CHROOT_PATH
EOM EOM
fi ;;
"file")
cat >> "$TEMP_SCHROOTCONF" << EOM
union-type=aufs
file=CHROOT_PATH
EOM
;;
esac
fi fi
if [ ! -z "$personality" ]; then if [ ! -z "$personality" ]; then
echo "personality=$personality" >> "$TEMP_SCHROOTCONF" echo "personality=$personality" >> "$TEMP_SCHROOTCONF"
@ -445,7 +472,7 @@ cat "$TEMP_SCHROOTCONF" | sed \
-e "s|CHROOT_NAME|$CHROOT_NAME|g" \ -e "s|CHROOT_NAME|$CHROOT_NAME|g" \
-e "s|CHROOT_PATH|$CHROOT_PATH|g" \ -e "s|CHROOT_PATH|$CHROOT_PATH|g" \
-e "s|SNAPSHOT_SIZE|$SNAPSHOT_SIZE|g" \ -e "s|SNAPSHOT_SIZE|$SNAPSHOT_SIZE|g" \
-e "s|SCHROOT_CONF_TYPE|$SCHROOT_CONF_TYPE|g" \ -e "s|SCHROOT_TYPE|$SCHROOT_TYPE|g" \
| \ | \
sudo bash -c "cat >> /etc/schroot/schroot.conf" sudo bash -c "cat >> /etc/schroot/schroot.conf"
rm -f "$TEMP_SCHROOTCONF" rm -f "$TEMP_SCHROOTCONF"
@ -476,10 +503,19 @@ rm /finish.sh
EOM EOM
sudo chmod a+x "$MNT"/finish.sh sudo chmod a+x "$MNT"/finish.sh
if [ "$SRC_TYPE" = "lvm" ]; then case "$SCHROOT_TYPE" in
"lvm-snapshot")
sudo umount "$MNT" sudo umount "$MNT"
rmdir "$MNT" rmdir "$MNT"
fi ;;
"directory")
;;
"file")
(cd "$MNT" && sudo tar czf "$CHROOT_PATH" .)
sudo rm -r "$MNT"
;;
esac
# Run finalization script on the "golden" copy via schroot. # Run finalization script on the "golden" copy via schroot.
sudo schroot -c "$CHROOT_NAME"-source -u root /finish.sh sudo schroot -c "$CHROOT_NAME"-source -u root /finish.sh