2008-12-13 05:23:16 +01:00
|
|
|
#-
|
|
|
|
# Copyright (c) 2008 Juan Romero Pardines.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#-
|
|
|
|
|
2008-10-23 17:14:00 +02:00
|
|
|
#
|
2008-12-13 03:01:24 +01:00
|
|
|
# Script to install packages into a sandbox in masterdir.
|
2008-10-23 17:14:00 +02:00
|
|
|
# Actually this needs the xbps-base-chroot package installed.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Umount stuff if SIGINT or SIGQUIT was caught
|
|
|
|
trap umount_chroot_fs INT QUIT
|
|
|
|
|
2008-12-16 04:43:53 +01:00
|
|
|
prepare_chroot()
|
|
|
|
{
|
|
|
|
local f=
|
2008-10-23 17:14:00 +02:00
|
|
|
|
2008-12-16 04:53:03 +01:00
|
|
|
# Create some required files.
|
2008-12-16 05:07:14 +01:00
|
|
|
touch $XBPS_MASTERDIR/etc/mtab
|
|
|
|
for f in run/utmp log/btmp log/lastlog log/wtmp; do
|
|
|
|
touch -f $XBPS_MASTERDIR/var/$f
|
|
|
|
done
|
|
|
|
for f in run/utmp log/lastlog; do
|
|
|
|
chmod 644 $XBPS_MASTERDIR/var/$f
|
|
|
|
done
|
|
|
|
|
2009-04-07 16:08:52 +02:00
|
|
|
cat > $XBPS_MASTERDIR/etc/passwd <<_EOF
|
2008-12-16 04:53:03 +01:00
|
|
|
root:x:0:0:root:/root:/bin/bash
|
|
|
|
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
|
|
|
|
_EOF
|
2009-02-03 23:54:52 +01:00
|
|
|
|
2008-12-16 04:53:03 +01:00
|
|
|
# Default group list as specified by LFS.
|
2009-04-07 16:08:52 +02:00
|
|
|
cat > $XBPS_MASTERDIR/etc/group <<_EOF
|
2008-12-16 04:53:03 +01:00
|
|
|
root:x:0:
|
|
|
|
bin:x:1:
|
|
|
|
sys:x:2:
|
|
|
|
kmem:x:3:
|
|
|
|
tty:x:4:
|
|
|
|
tape:x:5:
|
|
|
|
daemon:x:6:
|
|
|
|
floppy:x:7:
|
|
|
|
disk:x:8:
|
|
|
|
lp:x:9:
|
|
|
|
uucp:x:10:
|
|
|
|
audio:x:11:
|
|
|
|
video:x:12:
|
|
|
|
utmp:x:13:
|
|
|
|
usb:x:14:
|
|
|
|
cdrom:x:15:
|
|
|
|
mail:x:34:
|
|
|
|
nogroup:x:99:
|
2008-12-16 22:39:41 +01:00
|
|
|
users:x:1000:
|
2008-12-16 04:53:03 +01:00
|
|
|
_EOF
|
2009-02-03 23:54:52 +01:00
|
|
|
|
2008-12-16 04:53:03 +01:00
|
|
|
# Default file as in Ubuntu.
|
2009-04-07 16:08:52 +02:00
|
|
|
cat > $XBPS_MASTERDIR/etc/hosts <<_EOF
|
2008-12-16 04:53:03 +01:00
|
|
|
127.0.0.1 xbps localhost.localdomain localhost
|
|
|
|
127.0.1.1 xbps
|
|
|
|
|
|
|
|
# The following lines are desirable for IPv6 capable hosts
|
|
|
|
::1 ip6-localhost ip6-loopback
|
|
|
|
fe00::0 ip6-localnet
|
|
|
|
ff00::0 ip6-mcastprefix
|
|
|
|
ff02::1 ip6-allnodes
|
|
|
|
ff02::2 ip6-allrouters
|
|
|
|
ff02::3 ip6-allhosts
|
|
|
|
_EOF
|
2009-02-03 23:54:52 +01:00
|
|
|
|
2008-12-16 04:53:03 +01:00
|
|
|
# Use OpenDNS servers.
|
2009-04-07 16:08:52 +02:00
|
|
|
cat > $XBPS_MASTERDIR/etc/resolv.conf <<_EOF
|
2008-12-16 04:53:03 +01:00
|
|
|
nameserver 208.67.222.222
|
|
|
|
nameserver 208.67.220.220
|
|
|
|
_EOF
|
|
|
|
|
2008-10-23 17:14:00 +02:00
|
|
|
touch $XBPS_MASTERDIR/.xbps_perms_done
|
2009-05-06 07:19:32 +02:00
|
|
|
|
2008-12-16 04:43:53 +01:00
|
|
|
}
|
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-12-22 02:14:40 +01:00
|
|
|
install_xbps_utils()
|
|
|
|
{
|
|
|
|
local needed=
|
|
|
|
local xbps_prefix=$XBPS_MASTERDIR/usr/local
|
|
|
|
|
|
|
|
for f in bin cmpver digest pkgdb; do
|
|
|
|
if [ ! -x $xbps_prefix/sbin/xbps-${f} ]; then
|
|
|
|
needed=yes
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -n "$needed" ]; then
|
2009-05-06 07:19:32 +02:00
|
|
|
cd ${XBPS_MASTERDIR}/bin && ln -s dash sh
|
2008-12-22 02:14:40 +01:00
|
|
|
echo "=> Building and installing xbps utils."
|
|
|
|
chroot $XBPS_MASTERDIR sh -c \
|
|
|
|
"echo /usr/local/lib > /etc/ld.so.conf"
|
|
|
|
chroot $XBPS_MASTERDIR make -C /xbps
|
|
|
|
chroot $XBPS_MASTERDIR make -C /xbps install
|
|
|
|
chroot $XBPS_MASTERDIR make -C /xbps clean
|
|
|
|
rebuild_ldso_cache
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-12-13 03:01:24 +01:00
|
|
|
xbps_chroot_handler()
|
2008-10-27 07:42:40 +01:00
|
|
|
{
|
2008-10-28 07:17:35 +01:00
|
|
|
local action="$1"
|
|
|
|
local pkg="$2"
|
2008-12-13 03:01:24 +01:00
|
|
|
local only_destdir="$3"
|
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-12-22 02:14:40 +01:00
|
|
|
install_xbps_utils
|
|
|
|
|
2009-04-07 16:08:52 +02:00
|
|
|
if [ ! -f $XBPS_MASTERDIR/.xbps_perms_done ]; then
|
|
|
|
echo -n "==> Preparing chroot on $XBPS_MASTERDIR... "
|
|
|
|
prepare_chroot
|
|
|
|
echo "done."
|
|
|
|
fi
|
|
|
|
|
2008-10-28 07:17:35 +01:00
|
|
|
if [ "$action" = "chroot" ]; then
|
2009-02-25 07:05:50 +01:00
|
|
|
env in_chroot=yes LANG=C chroot $XBPS_MASTERDIR /bin/bash
|
2008-10-28 07:17:35 +01:00
|
|
|
else
|
2008-12-13 03:01:24 +01:00
|
|
|
[ -n "$only_destdir" ] && \
|
|
|
|
local lenv="install_destdir_target=yes"
|
2009-02-25 07:05:50 +01:00
|
|
|
env in_chroot=yes LANG=C ${lenv} chroot $XBPS_MASTERDIR \
|
2008-12-22 05:29:26 +01:00
|
|
|
xbps-src $action $pkg
|
2008-10-28 07:17:35 +01:00
|
|
|
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=
|
|
|
|
|
2008-12-13 07:04:53 +01:00
|
|
|
REQFS="sys proc dev xbps xbps_builddir xbps_destdir \
|
|
|
|
xbps_packagesdir xbps_srcdistdir"
|
2008-11-03 07:12:53 +01:00
|
|
|
if [ -d "$XBPS_CROSS_DIR" ]; then
|
|
|
|
local cross=yes
|
|
|
|
REQFS="$REQFS xbps_crossdir"
|
|
|
|
fi
|
|
|
|
|
2008-10-30 00:51:48 +01:00
|
|
|
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;;
|
2008-12-13 07:04:53 +01:00
|
|
|
xbps_packagesdir) blah=$XBPS_PACKAGESDIR;;
|
2008-11-03 07:12:53 +01:00
|
|
|
xbps_crossdir)
|
|
|
|
[ -n $cross ] && blah=$XBPS_CROSS_DIR
|
|
|
|
;;
|
2008-10-30 00:51:48 +01:00
|
|
|
*) blah=/$f;;
|
|
|
|
esac
|
2008-12-22 03:16:16 +01:00
|
|
|
[ ! -d $blah ] && continue
|
2008-10-30 00:51:48 +01:00
|
|
|
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-11-03 10:33:54 +01:00
|
|
|
for dir in ${EXTDIRS}; 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
|
|
|
}
|
2008-12-16 04:43:53 +01:00
|
|
|
|
|
|
|
[ -n "$base_chroot" ] && return 0
|
|
|
|
|
|
|
|
. $XBPS_SHUTILSDIR/builddep_funcs.sh
|
2009-02-17 13:58:34 +01:00
|
|
|
check_installed_pkg xbps-base-chroot-0.1
|
2008-12-18 11:40:43 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "The '$pkgname' package requires to be installed in a chroot."
|
|
|
|
echo "Please install the 'xbps-base-chroot' package and try again."
|
|
|
|
exit 1
|
|
|
|
fi
|
2008-12-16 04:43:53 +01:00
|
|
|
|
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
|
|
if [ -n "$origin_tmpl" ]; then
|
|
|
|
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
|
|
|
|
reset_tmpl_vars
|
2009-02-03 21:35:57 +01:00
|
|
|
run_file $XBPS_TEMPLATESDIR/$origin_tmpl/template
|
2008-12-16 04:43:53 +01:00
|
|
|
fi
|
2008-12-18 11:40:43 +01:00
|
|
|
echo "The '$pkgname' package requires to be installed in a chroot."
|
|
|
|
echo "You cannot do this as normal user, try again being root."
|
|
|
|
exit 1
|
2008-12-16 04:43:53 +01:00
|
|
|
fi
|
|
|
|
|
2009-04-07 16:08:52 +02:00
|
|
|
msg_normal "Entering into the chroot on $XBPS_MASTERDIR."
|
2008-12-16 04:43:53 +01:00
|
|
|
|
|
|
|
EXTDIRS="xbps xbps_builddir xbps_destdir xbps_packagesdir \
|
|
|
|
xbps_srcdistdir xbps_crossdir"
|
2009-02-05 17:08:06 +01:00
|
|
|
REQDIRS="bin sbin tmp var sys proc dev usr/local/etc ${EXTDIRS}"
|
2008-12-16 04:43:53 +01:00
|
|
|
for f in ${REQDIRS}; do
|
|
|
|
[ ! -d $XBPS_MASTERDIR/$f ] && mkdir -p $XBPS_MASTERDIR/$f
|
|
|
|
done
|
|
|
|
unset f REQDIRS
|
|
|
|
|
2009-02-05 17:08:06 +01:00
|
|
|
echo "XBPS_DISTRIBUTIONDIR=/xbps" > $XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
|
|
|
echo "XBPS_MASTERDIR=/" >> $XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
|
|
|
echo "XBPS_DESTDIR=/xbps_destdir" >> $XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
|
|
|
echo "XBPS_PACKAGESDIR=/xbps_packagesdir" >> $XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
|
|
|
echo "XBPS_BUILDDIR=/xbps_builddir" >> $XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
|
|
|
echo "XBPS_SRCDISTDIR=/xbps_srcdistdir" >> $XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
|
|
|
echo "XBPS_CFLAGS=\"$XBPS_CFLAGS\"" >> $XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
|
|
|
echo "XBPS_CXXFLAGS=\"\$XBPS_CFLAGS\"" >> $XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
2008-12-16 04:43:53 +01:00
|
|
|
if [ -n "$XBPS_MAKEJOBS" ]; then
|
2009-02-05 17:08:06 +01:00
|
|
|
echo "XBPS_MAKEJOBS=$XBPS_MAKEJOBS" >> $XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
2008-12-16 04:43:53 +01:00
|
|
|
fi
|
|
|
|
if [ -n "$XBPS_CROSS_TARGET" -a -d "$XBPS_CROSS_DIR" ]; then
|
|
|
|
echo "XBPS_CROSS_TARGET=$XBPS_CROSS_TARGET" >> \
|
2009-02-05 17:08:06 +01:00
|
|
|
$XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
|
|
|
echo "XBPS_CROSS_DIR=/xbps_crossdir" >> $XBPS_MASTERDIR/usr/local/etc/xbps.conf
|
2008-12-16 04:43:53 +01:00
|
|
|
fi
|
|
|
|
|
2009-04-07 16:08:52 +02:00
|
|
|
|