chroot: simplify even more and fix a bug.

--HG--
extra : convert_revision : 0bebca889003a6bbafb619607a0b6f294dd25300
This commit is contained in:
Juan RP 2008-10-24 04:48:57 +02:00
parent c2be5ca040
commit e1d3deafe6

View file

@ -17,27 +17,32 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1 exit 1
fi fi
echo "==> Preparing chroot on $XBPS_MASTERDIR... "
if [ ! -f $XBPS_MASTERDIR/.xbps_perms_done ]; then if [ ! -f $XBPS_MASTERDIR/.xbps_perms_done ]; then
echo "==> Preparing chroot on $XBPS_MASTERDIR... "
chown -R root:root $XBPS_MASTERDIR/* chown -R root:root $XBPS_MASTERDIR/*
chmod +s $XBPS_MASTERDIR/usr/libexec/pt_chown chmod +s $XBPS_MASTERDIR/usr/libexec/pt_chown
cp -af /etc/passwd /etc/shadow /etc/group /etc/hosts $XBPS_MASTERDIR/etc cp -af /etc/passwd /etc/shadow /etc/group /etc/hosts $XBPS_MASTERDIR/etc
touch $XBPS_MASTERDIR/.xbps_perms_done touch $XBPS_MASTERDIR/.xbps_perms_done
else
echo "==> Entering into the chroot on $XBPS_MASTERDIR..."
fi fi
for f in bin sbin tmp var sys proc dev xbps; do for f in bin sbin tmp var sys proc dev xbps xbps_builddir xbps_destdir; do
[ ! -d $XBPS_MASTERDIR/$f ] && mkdir -p $XBPS_MASTERDIR/$f [ ! -d $XBPS_MASTERDIR/$f ] && mkdir -p $XBPS_MASTERDIR/$f
done done
unset f
for f in sys proc dev xbps; do for f in sys proc dev xbps xbps_builddir xbps_destdir; do
if [ ! -f $XBPS_MASTERDIR/.${f}_mount_bind_done ]; then if [ ! -f $XBPS_MASTERDIR/.${f}_mount_bind_done ]; then
echo -n "=> Mounting $f in chroot... " echo -n "=> Mounting $f in chroot... "
if [ "$f" = "xbps" ]; then local blah=
mount -o bind $XBPS_DISTRIBUTIONDIR $XBPS_MASTERDIR/$f case $f in
else xbps) blah=$XBPS_DISTRIBUTIONDIR;;
mount -o bind /$f $XBPS_MASTERDIR/$f xbps_builddir) blah=$XBPS_BUILDDIR;;
fi xbps_destdir) blah=$XBPS_DESTDIR;;
*) blah=/$f;;
esac
mount --bind $blah $XBPS_MASTERDIR/$f
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
touch $XBPS_MASTERDIR/.${f}_mount_bind_done touch $XBPS_MASTERDIR/.${f}_mount_bind_done
echo "done." echo "done."
@ -46,32 +51,7 @@ for f in sys proc dev xbps; do
fi fi
fi fi
done done
unset f
if [ ! -f $XBPS_MASTERDIR/.xbps_builddir_mount_bind_done ]; then
[ ! -d $XBPS_MASTERDIR/xbps_builddir ] && mkdir -p \
$XBPS_MASTERDIR/xbps_builddir
echo -n "=> Mounting builddir in chroot... "
mount -o bind $XBPS_BUILDDIR $XBPS_MASTERDIR/xbps_builddir
if [ $? -eq 0 ]; then
touch $XBPS_MASTERDIR/.xbps_builddir_mount_bind_done
echo "done."
else
echo "failed."
fi
fi
if [ ! -f $XBPS_MASTERDIR/.xbps_destdir_mount_bind_done ]; then
[ ! -d $XBPS_MASTERDIR/xbps_destdir ] && mkdir -p \
$XBPS_MASTERDIR/xbps_destdir
echo -n "=> Mounting destdir in chroot... "
mount -o bind $XBPS_DESTDIR $XBPS_MASTERDIR/xbps_destdir
if [ $? -eq 0 ]; then
touch $XPS_MASTERDIR/.xbps_destdir_mount_bind_done
echo "done."
else
echo "failed."
fi
fi
echo "XBPS_DISTRIBUTIONDIR=/xbps" > $XBPS_MASTERDIR/etc/xbps.conf echo "XBPS_DISTRIBUTIONDIR=/xbps" > $XBPS_MASTERDIR/etc/xbps.conf
echo "XBPS_MASTERDIR=/" >> $XBPS_MASTERDIR/etc/xbps.conf echo "XBPS_MASTERDIR=/" >> $XBPS_MASTERDIR/etc/xbps.conf
@ -94,19 +74,23 @@ install_chroot_pkg()
chroot $XBPS_MASTERDIR /xbps/xbps.sh install $pkg chroot $XBPS_MASTERDIR /xbps/xbps.sh install $pkg
umount_chroot_fs umount_chroot_fs
echo "==> Exiting from the chroot on $XBPS_MASTERDIR..."
} }
umount_chroot_fs() umount_chroot_fs()
{ {
for f in sys proc dev xbps xbps_builddir xbps_destdir; do local fs=
[ ! -f $XBPS_MASTERDIR/.${f}_mount_bind_done ] && continue
echo -n "=> Unmounting $f from chroot... " for fs in sys proc dev xbps xbps_builddir xbps_destdir; do
umount -f $XBPS_MASTERDIR/$f [ ! -f $XBPS_MASTERDIR/.${fs}_mount_bind_done ] && continue
echo -n "=> Unmounting $fs from chroot... "
umount -f $XBPS_MASTERDIR/$fs
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
rm -f $XBPS_MASTERDIR/.${f}_mount_bind_done rm -f $XBPS_MASTERDIR/.${fs}_mount_bind_done
echo "done." echo "done."
else else
echo "failed." echo "failed."
fi fi
unset fs
done done
} }