[Frugalware-darcs] pacman: makepkg: chroot support
VMiklos
vmiklos at frugalware.org
Mon Dec 26 09:04:29 CET 2005
[makepkg: chroot support
VMiklos <vmiklos at frugalware.org>**20051211004427
Date: 2005-08-11
Initial Package Version: 2.9.6
Upstream Status: Not yet submitted
Origin: Miklos Vajna <vmiklos at frugalware.org>
Description: Adds support for building the package in a chroot.
doc/makepkg.8.in | 55 ++++++++++++++++
etc/makepkg.conf | 5 +
scripts/makepkg | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 237 insertions(+), 1 deletion(-)
] {
hunk ./doc/makepkg.8.in 351
+.SH What is the process of chrooted build ?
+
+First, what is chroot? We currently use fakeroot to prevent build() from
+modifying the host system, and we use a prefix or DESTDIR directive to install
+everything to a directory and not under to the host system. This is good, but
+not enough.
+
+This system lacks of the ability to control the list of installed packages
+during the build on the system of a packager, the given compiled package maybe
+linked itself to an extra installed library. This way we can't really control
+the list of real dependencies. For example if libquicktime is installed from
+source on my system, then mplayer or any other program can link itself to that,
+and so that depends() will be incorrect. Or if I have the closed source binary
+NVidia drivers installed, some programs link tho NVidia's libraries.
+
+Of course there is a sollution to avoid this, to use a real chroot instead of a
+simple fakeroot. What is this means? The followings:
+
+When starting the build, a core chroot system is installed under /var/chroot.
+(Of course you can change this value under /etc/makepkg.conf.) The core system
+contains ~60 packages which are must installed to build any package in
+a chrooted environment. These packages (for example gcc, kernel-headers, make)
+should not be mentioned in makedepends(). 'pacman -Sg core chroot-core
+devel-core' should show you the actial list. (We try to change this list rarely
+of course.)
+
+When you start building with makepkg -R, pacman will install these packages to
+/var/chroot if necessary. This will produce a fully "clean" Frugalware system,
+that consits of base packages only. This /var/chroot is fully separated from
+the host system so that this will solve the problems mentioned above.
+(Linking to a library installed from source, etc.)
+
+Here comes the fun part. The packages listed in depends() and makedepends() are
+installed to this clean (/var/chroot) system. From this point, this chroot is
+capable to build the specified package in it without any unnecessary package
+installed, fully separated from the host system.
+
+After this the chroot should be cleaned up which means the removal of the
+installed depends() and makedepends(). This ensures us not to build from
+scratch the core chroot.
+
+This way we can prevent lots of dependency problems and it is even possible to
+build packages for a different Frugalware version. This is quite efficent when
+building security updates or fixing critical bugs in the -stable tree.
+
+If the build is failed, the working directory will not be deleted, you can find
+it under /var/chroot/var/tmp/fst. Later if you want to clean your chroot
+(delete the working directory and remove unnecessary packages) you can use 'makepkg -CR'.
+
+To activate building in a chroot, you should run makepkg as root at least with
+the -R option.
+
hunk ./doc/makepkg.8.in 470
+.B "\-R, \-\-chroot"
+Build the package in a chroot environment.
+.TP
hunk ./etc/makepkg.conf 27
+
+# Specify a directory for the chroot environment.
+export CHROOTDIR="/var/chroot"
+# Core package list to be installed in the chroot.
+export COREPKGS="core chroot-core devel-core"
hunk ./scripts/makepkg 43
+INCHROOT=
+if [ "$1" = "--inchroot" ]; then
+ INCHROOT=1
+ shift
+fi
+
hunk ./scripts/makepkg 192
+ # rerun any additional sh scripts found in /etc/profile.d/
+ for i in /etc/profile.d/*.sh
+ do
+ if [ -x $i ]; then
+ . $i &>/dev/null
+ fi
+ done
hunk ./scripts/makepkg 233
+ echo " -R, --chroot Build the package in a chroot environment"
hunk ./scripts/makepkg 245
+chroot_umount() {
+ msg "Attempting to umount chroot directories..."
+ umount $CHROOTDIR/proc >/dev/null
+ umount $CHROOTDIR/sys >/dev/null
+ umount $CHROOTDIR/dev >/dev/null
+ umount $CHROOTDIR/var/cache/pacman >/dev/null
+ umount $CHROOTDIR/var/cache/ccache/$pkgname >/dev/null
+ if [ "$?" != "0" ]; then
+ error "An error occurred while attempting to umount chroot directories."
+ exit 1
+ fi
+ msg "Successfully umounted chroot directories."
+}
+
+chroot_mount() {
+ msg "Attempting to mount chroot directories..."
+ mount -t proc none $CHROOTDIR/proc >/dev/null &
+ mount -t sysfs none $CHROOTDIR/sys >/dev/null &
+ mount -o bind /dev $CHROOTDIR/dev >/dev/null &
+ mount -o bind /var/cache/pacman $CHROOTDIR/var/cache/pacman >/dev/null &
+ mount -o bind /var/cache/ccache/$pkgname \
+ $CHROOTDIR/var/cache/ccache/$pkgname >/dev/null &
+ if [ "$?" != "0" ]; then
+ error "An error occurred while attempting to mount chroot directories."
+ exit 1
+ fi
+ msg "Successfully mounted chroot directories."
+}
+
+chroot_clean()
+{
+ if [ "$CHROOT" = "1" ]; then
+ msg "Cleaning chroot."
+ rm -rf $CHROOTDIR/var/tmp/fst/*
+ msg "Removing unnecessary packages."
+ for i in "$COREPKGS"
+ do
+ corelist="$corelist `pacman -r $CHROOTDIR -Sg $i|grep -v '^\w'`"
+ done
+ for i in `pacman -r $CHROOTDIR -Q|sed 's/\([^ ]*\) .*/\1/'`
+ do
+ if ! echo $corelist |grep -q $i; then
+ removelist="$removelist $i"
+ fi
+ done
+ if [ ! -z "$removelist" ]; then
+ pacman -r $CHROOTDIR -Rcn $removelist --noconfirm
+ if [ "$?" != "0" ]; then
+ error "Failed to remove packages."
+ exit 1
+ fi
+ fi
+ fi
+}
hunk ./scripts/makepkg 318
+CHROOT=0
hunk ./scripts/makepkg 344
+ --chroot) CHROOT=1 ;;
hunk ./scripts/makepkg 357
- while getopts "abBcCdefghij:kl:Lmnop:ursSw:-" opt; do
+ while getopts "abBcCdefghij:kl:Lmnop:urRsSw:-" opt; do
hunk ./scripts/makepkg 382
+ R) CHROOT=1 ;;
hunk ./scripts/makepkg 424
+ chroot_clean
hunk ./scripts/makepkg 523
+# Build chroot environment if necessary.
+if [ "$CHROOT" = "1" -a "$INCHROOT" != "1" ]; then
+ if [ "`id -u`" != 0 ]; then
+ error "Building in a chroot as an unprivileged user is not possible."
+ exit 1
+ fi
+ if [ "$CHROOTDIR" = "" ]; then
+ error "The CHROOTDIR environment variable is not defined."
+ exit 1
+ fi
+
+ mkdir -p $CHROOTDIR/{dev,etc,proc,sys,var/cache/pacman,var/tmp/fst}
+
+ if [ -e $CHROOTDIR/var/tmp/fst/lock ]; then
+ error "Somebody already building in this chroot."
+ plain "If you're sure makepkg is not already running, you"
+ plain "can remove $CHROOTDIR/var/tmp/fst/lock."
+ exit 1
+ else
+ touch $CHROOTDIR/var/tmp/fst/lock
+ fi
+
+ install -d -m 2775 {,$CHROOTDIR}/var/cache/ccache/$pkgname
+
+ chroot_mount
+
+ if [ ! -d "$CHROOTDIR/usr" ]; then
+ msg "Building chroot environment"
+ pacman -Syf $COREPKGS -r "$CHROOTDIR" --noconfirm
+ if [ "$?" != "0" ]; then
+ error "Failed to build chroot environment."
+ chroot_umount
+ msg "Removing lock file..."
+ rm -f $CHROOTDIR/var/tmp/fst/lock
+ exit 1
+ fi
+ else
+ msg "Updating the chroot environment"
+ # run pacman -Su twice in case pacman updated
+ pacman -Syu -r "$CHROOTDIR" --noconfirm && \
+ pacman -Su -r "$CHROOTDIR" --noconfirm
+ if [ "$?" != "0" ]; then
+ error "Failed to update chroot environment."
+ chroot_umount
+ msg "Removing lock file..."
+ rm -f $CHROOTDIR/var/tmp/fst/lock
+ exit 1
+ fi
+ fi
+ # why is this necessary?
+ chmod 1777 $CHROOTDIR/tmp
+
+ msg "Copying config files to chroot"
+ cp -pf /etc/makepkg.conf $CHROOTDIR/etc >/dev/null &
+ cp -pf /etc/resolv.conf $CHROOTDIR/etc >/dev/null &
+ cp -pf /etc/passwd $CHROOTDIR/etc >/dev/null &
+ cp -pf /etc/shadow $CHROOTDIR/etc >/dev/null &
+ cp -pf /etc/group $CHROOTDIR/etc >/dev/null &
+ cp -pf /etc/ld.so.conf $CHROOTDIR/etc >/dev/null &
+ cp -pf /etc/hosts $CHROOTDIR/etc > /dev/null &
+ echo "fst ALL=(ALL) NOPASSWD: ALL" >$CHROOTDIR/etc/sudoers
+ cp -Ppf /etc/localtime $CHROOTDIR/etc >/dev/null &
+ cp -pf /etc/services $CHROOTDIR/etc > /dev/null &
+ if [ "$?" != "0" ]; then
+ error "An error occurred while attempting to copy config files to chroot."
+ chroot_umount
+ exit 1
+ fi
+ # to make Finclude work
+ if darcs --commands 2>&1|grep -q add; then
+ [ -d $CHROOTDIR/var/tmp/fst/include/ ] || mkdir -p $CHROOTDIR/var/tmp/fst/include/
+ if [ -d `darcs add . 2>&1|sed -n 's/[^/]*/../g; 4 p'`/source/include ]; then
+ cp `darcs add . 2>&1|sed -n 's/[^/]*/../g; 4 p'`/source/include/* $CHROOTDIR/var/tmp/fst/include/
+ elif [ -d $fst_root/$reponame/source/include ]; then
+ cp $fst_root/$reponame/source/include/* $CHROOTDIR/var/tmp/fst/include/
+ fi
+ fi
+
+ msg "Copying $pkgname's buildscript to chroot"
+ cp -a * $CHROOTDIR/var/tmp/fst/
+ chown -R fst:users $CHROOTDIR/var/tmp/fst
+
+ if [ ! -x /usr/sbin/chroot ]; then
+ error "chroot was not found."
+ else
+ msg "Entering chroot environment"
+ /usr/sbin/chroot $CHROOTDIR \
+ /bin/su - fst -c "$0 --inchroot -S $ARGLIST"
+ fi
+
+ if [ -f $CHROOTDIR/var/tmp/fst/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.fpm ]; then
+ mv $CHROOTDIR/var/tmp/fst/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.fpm $PKGDEST
+ if [ "`id -u`" = "0" ]; then
+ chown `stat -c %U:%G FrugalBuild` \
+ ${pkgname}-${pkgver}-${pkgrel}-${CARCH}.fpm
+ fi
+ # copy back the buildscript, maybe modified
+ cp $CHROOTDIR/var/tmp/fst/FrugalBuild ./
+ # save the build log if necessary
+ if [ -f $CHROOTDIR/var/tmp/fst/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log ]; then
+ mv $CHROOTDIR/var/tmp/fst/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log ./
+ fi
+ rm -rf $CHROOTDIR/var/tmp/fst/*
+ chroot_clean
+ fi
+
+ chroot_umount
+ rm -f $CHROOTDIR/var/tmp/fst/lock
+ exit 0
+fi
+
hunk ./scripts/makepkg 640
- fakeroot -- $0 -F $ARGLIST
+ if [ "$INCHROOT" != "1" ]; then
+ fakeroot -- $0 -F $ARGLIST
+ else
+ fakeroot -- $0 -F --inchroot $ARGLIST
+ fi
hunk ./scripts/makepkg 883
+ install -d -m 2775 /var/cache/ccache/$pkgname
+ export CCACHE_DIR=/var/cache/ccache/$pkgname
+ export CCACHE_NOLINK=1
+ export CCACHE_UMASK=002
hunk ./scripts/makepkg 1062
+if [ "$INCHROOT" != "1" ]; then
hunk ./scripts/makepkg 1065
+else
+ tar czvf ../$pkgname-$pkgver-$pkgrel-$CARCH.fpm .PKGINFO .FILELIST \
+ $extra * | sort >../filelist
+fi
}
More information about the Frugalware-darcs
mailing list