2008-10-23 17:14:00 +02:00
|
|
|
#
|
|
|
|
# Helper to install packages into a sandbox in masterdir.
|
|
|
|
# Actually this needs the xbps-base-chroot package installed.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Umount stuff if SIGINT or SIGQUIT was caught
|
|
|
|
trap umount_chroot_fs INT QUIT
|
|
|
|
|
2008-10-27 10:29:21 +01:00
|
|
|
[ -n "$base_chroot" ] && return 0
|
|
|
|
|
2008-10-23 17:14:00 +02:00
|
|
|
check_installed_pkg xbps-base-chroot 0.1
|
2008-10-29 23:34:05 +01:00
|
|
|
[ $? -ne 0 ] && msg_error "xbps-base-chroot pkg not installed."
|
2008-10-23 17:14:00 +02:00
|
|
|
|
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
2008-10-30 00:51:48 +01:00
|
|
|
if [ -n "$origin_tmpl" ]; then
|
|
|
|
reset_tmpl_vars
|
|
|
|
run_file $XBPS_TEMPLATESDIR/$origin_tmpl.tmpl
|
|
|
|
fi
|
2008-10-27 08:35:40 +01:00
|
|
|
if [ -z "$base_chroot" ]; then
|
2008-10-29 03:20:14 +01:00
|
|
|
msg_error "this package must be built inside of the chroot."
|
2008-10-29 23:34:05 +01:00
|
|
|
else
|
|
|
|
msg_error "you must be root to use this target."
|
2008-10-27 08:35:40 +01:00
|
|
|
fi
|
2008-10-23 17:14:00 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $XBPS_MASTERDIR/.xbps_perms_done ]; then
|
2008-10-27 07:42:40 +01:00
|
|
|
echo -n "==> Preparing chroot on $XBPS_MASTERDIR... "
|
2008-10-23 17:14:00 +02:00
|
|
|
chown -R root:root $XBPS_MASTERDIR/*
|
|
|
|
chmod +s $XBPS_MASTERDIR/usr/libexec/pt_chown
|
2008-10-29 23:34:05 +01:00
|
|
|
cp -af /etc/passwd /etc/shadow /etc/group /etc/hosts \
|
|
|
|
/etc/resolv.conf $XBPS_MASTERDIR/etc
|
2008-10-23 17:14:00 +02:00
|
|
|
touch $XBPS_MASTERDIR/.xbps_perms_done
|
2008-10-27 07:42:40 +01:00
|
|
|
echo "done."
|
2008-10-24 04:48:57 +02:00
|
|
|
else
|
2008-10-29 03:20:14 +01:00
|
|
|
msg_normal "Entering into the chroot on $XBPS_MASTERDIR."
|
2008-10-23 17:14:00 +02:00
|
|
|
fi
|
|
|
|
|
2008-10-28 07:17:35 +01:00
|
|
|
REQDIRS="bin sbin tmp var sys proc dev xbps xbps_builddir \
|
|
|
|
xbps_destdir xbps_srcdistdir"
|
|
|
|
for f in ${REQDIRS}; do
|
2008-10-23 17:14:00 +02:00
|
|
|
[ ! -d $XBPS_MASTERDIR/$f ] && mkdir -p $XBPS_MASTERDIR/$f
|
|
|
|
done
|
2008-10-28 07:17:35 +01:00
|
|
|
unset f REQDIRS
|
2008-10-23 17:14:00 +02:00
|
|
|
|
|
|
|
echo "XBPS_DISTRIBUTIONDIR=/xbps" > $XBPS_MASTERDIR/etc/xbps.conf
|
|
|
|
echo "XBPS_MASTERDIR=/" >> $XBPS_MASTERDIR/etc/xbps.conf
|
2008-10-24 04:25:31 +02:00
|
|
|
echo "XBPS_DESTDIR=/xbps_destdir" >> $XBPS_MASTERDIR/etc/xbps.conf
|
|
|
|
echo "XBPS_BUILDDIR=/xbps_builddir" >> $XBPS_MASTERDIR/etc/xbps.conf
|
2008-10-28 07:17:35 +01:00
|
|
|
echo "XBPS_SRCDISTDIR=/xbps_srcdistdir" >> $XBPS_MASTERDIR/etc/xbps.conf
|
2008-10-23 17:14:00 +02:00
|
|
|
echo "XBPS_CFLAGS=\"$XBPS_CFLAGS\"" >> $XBPS_MASTERDIR/etc/xbps.conf
|
|
|
|
echo "XBPS_CXXFLAGS=\"\$XBPS_CFLAGS\"" >> $XBPS_MASTERDIR/etc/xbps.conf
|
2008-10-24 05:51:51 +02:00
|
|
|
if [ -n "$XBPS_MAKEJOBS" ]; then
|
|
|
|
echo "XBPS_MAKEJOBS=$XBPS_MAKEJOBS" >> $XBPS_MASTERDIR/etc/xbps.conf
|
|
|
|
fi
|
2008-10-23 17:14:00 +02:00
|
|
|
|
2008-10-26 04:16:41 +01:00
|
|
|
rebuild_ldso_cache()
|
2008-10-23 17:14:00 +02:00
|
|
|
{
|
2008-10-24 02:05:48 +02:00
|
|
|
echo -n "==> Rebuilding chroot's dynamic linker cache..."
|
2008-10-23 17:14:00 +02:00
|
|
|
chroot $XBPS_MASTERDIR /sbin/ldconfig -c /etc/ld.so.conf
|
|
|
|
chroot $XBPS_MASTERDIR /sbin/ldconfig -C /etc/ld.so.cache
|
|
|
|
echo " done."
|
2008-10-26 04:16:41 +01:00
|
|
|
}
|
|
|
|
|
2008-10-28 07:17:35 +01:00
|
|
|
chroot_pkg_handler()
|
2008-10-27 07:42:40 +01:00
|
|
|
{
|
2008-10-28 07:17:35 +01:00
|
|
|
local action="$1"
|
|
|
|
local pkg="$2"
|
2008-10-27 07:42:40 +01:00
|
|
|
|
2008-10-28 07:17:35 +01:00
|
|
|
[ -z "$action" -o -z "$pkg" ] && return 1
|
2008-10-27 07:42:40 +01:00
|
|
|
|
2008-10-28 07:17:35 +01:00
|
|
|
[ "$action" != "configure" -a "$action" != "build" -a \
|
|
|
|
"$action" != "install" -a "$action" != "chroot" ] && return 1
|
2008-10-27 07:42:40 +01:00
|
|
|
|
|
|
|
rebuild_ldso_cache
|
2008-10-30 00:51:48 +01:00
|
|
|
mount_chroot_fs
|
2008-10-28 07:17:35 +01:00
|
|
|
if [ "$action" = "chroot" ]; then
|
|
|
|
env in_chroot=yes chroot $XBPS_MASTERDIR /bin/bash
|
|
|
|
else
|
|
|
|
env in_chroot=yes chroot $XBPS_MASTERDIR /xbps/xbps.sh \
|
|
|
|
$action $pkg
|
|
|
|
fi
|
2008-10-29 03:20:14 +01:00
|
|
|
msg_normal "Exiting from the chroot on $XBPS_MASTERDIR."
|
2008-10-24 09:44:51 +02:00
|
|
|
umount_chroot_fs
|
|
|
|
}
|
|
|
|
|
2008-10-30 00:51:48 +01:00
|
|
|
mount_chroot_fs()
|
|
|
|
{
|
|
|
|
local cnt=
|
|
|
|
|
|
|
|
REQFS="sys proc dev xbps xbps_builddir xbps_destdir xbps_srcdistdir"
|
|
|
|
for f in ${REQFS}; do
|
|
|
|
if [ ! -f $XBPS_MASTERDIR/.${f}_mount_bind_done ]; then
|
|
|
|
echo -n "=> Mounting $f in chroot... "
|
|
|
|
local blah=
|
|
|
|
case $f in
|
|
|
|
xbps) blah=$XBPS_DISTRIBUTIONDIR;;
|
|
|
|
xbps_builddir) blah=$XBPS_BUILDDIR;;
|
|
|
|
xbps_destdir) blah=$XBPS_DESTDIR;;
|
|
|
|
xbps_srcdistdir) blah=$XBPS_SRCDISTDIR;;
|
|
|
|
*) blah=/$f;;
|
|
|
|
esac
|
|
|
|
mount --bind $blah $XBPS_MASTERDIR/$f
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo 1 > $XBPS_MASTERDIR/.${f}_mount_bind_done
|
|
|
|
echo "done."
|
|
|
|
else
|
|
|
|
echo "failed."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
cnt=$(cat $XBPS_MASTERDIR/.${f}_mount_bind_done)
|
|
|
|
cnt=$(($cnt + 1))
|
|
|
|
echo $cnt > $XBPS_MASTERDIR/.${f}_mount_bind_done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
unset f
|
|
|
|
}
|
|
|
|
|
2008-10-23 17:14:00 +02:00
|
|
|
umount_chroot_fs()
|
|
|
|
{
|
2008-10-24 04:48:57 +02:00
|
|
|
local fs=
|
2008-10-24 05:03:29 +02:00
|
|
|
local dir=
|
2008-10-30 00:51:48 +01:00
|
|
|
local cnt=
|
2008-10-24 04:48:57 +02:00
|
|
|
|
2008-10-28 07:17:35 +01:00
|
|
|
for fs in ${REQFS}; do
|
2008-10-24 04:48:57 +02:00
|
|
|
[ ! -f $XBPS_MASTERDIR/.${fs}_mount_bind_done ] && continue
|
2008-10-30 00:51:48 +01:00
|
|
|
cnt=$(cat $XBPS_MASTERDIR/.${fs}_mount_bind_done)
|
|
|
|
if [ $cnt -gt 1 ]; then
|
|
|
|
cnt=$(($cnt - 1))
|
|
|
|
echo $cnt > $XBPS_MASTERDIR/.${fs}_mount_bind_done
|
2008-10-24 02:05:48 +02:00
|
|
|
else
|
2008-10-30 00:51:48 +01:00
|
|
|
echo -n "=> Unmounting $fs from chroot... "
|
|
|
|
umount -f $XBPS_MASTERDIR/$fs
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
rm -f $XBPS_MASTERDIR/.${fs}_mount_bind_done
|
|
|
|
echo "done."
|
|
|
|
else
|
|
|
|
echo "failed."
|
|
|
|
fi
|
2008-10-24 02:05:48 +02:00
|
|
|
fi
|
2008-10-24 04:48:57 +02:00
|
|
|
unset fs
|
2008-10-23 17:14:00 +02:00
|
|
|
done
|
2008-10-24 05:03:29 +02:00
|
|
|
|
2008-10-28 07:17:35 +01:00
|
|
|
for dir in xbps xbps_builddir xbps_destdir xbps_srcdistdir; do
|
2008-10-30 00:51:48 +01:00
|
|
|
[ -f $XBPS_MASTERDIR/.${dir}_mount_bind_done ] && continue
|
2008-10-24 05:03:29 +02:00
|
|
|
[ -d $XBPS_MASTERDIR/$dir ] && rmdir $XBPS_MASTERDIR/$dir
|
|
|
|
done
|
2008-10-23 17:14:00 +02:00
|
|
|
}
|