2009-10-18 09:17:26 +00:00
|
|
|
#-
|
2011-02-11 13:19:34 +00:00
|
|
|
# Copyright (c) 2008-2011 Juan Romero Pardines.
|
2009-10-18 09:17:26 +00:00
|
|
|
# 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.
|
|
|
|
#-
|
|
|
|
|
|
|
|
#
|
|
|
|
# Script to install packages into a sandbox in masterdir.
|
|
|
|
# Actually this needs the xbps-base-chroot package installed.
|
|
|
|
#
|
2011-02-11 13:19:34 +00:00
|
|
|
trap "_umount && return $?" 0 INT QUIT TERM
|
2010-05-17 10:09:44 +00:00
|
|
|
|
2011-02-26 16:56:23 +00:00
|
|
|
_mount()
|
|
|
|
{
|
2011-06-25 23:45:12 +00:00
|
|
|
MASTERDIR="${XBPS_MASTERDIR}" CACHEDIR="${XBPS_CACHEDIR}" \
|
|
|
|
${sudo_cmd} \
|
2011-02-26 16:56:23 +00:00
|
|
|
@@XBPS_INSTALL_LIBEXECDIR@@/xbps-src-chroot-helper mount
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
_umount()
|
|
|
|
{
|
2011-06-25 23:45:12 +00:00
|
|
|
MASTERDIR="${XBPS_MASTERDIR}" CACHEDIR="${XBPS_CACHEDIR}" \
|
|
|
|
${sudo_cmd} \
|
2011-02-26 16:56:23 +00:00
|
|
|
@@XBPS_INSTALL_LIBEXECDIR@@/xbps-src-chroot-helper umount
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2010-01-14 16:45:41 +00:00
|
|
|
[ -n "$base_chroot" ] && return 0
|
|
|
|
|
2010-01-16 01:11:44 +00:00
|
|
|
if [ "${chroot_cmd}" = "chroot" ]; then
|
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
|
|
echo "Root permissions are required for the chroot, try again."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-01-14 16:45:41 +00:00
|
|
|
. $XBPS_SHUTILSDIR/builddep_funcs.sh
|
2011-06-23 01:21:50 +00:00
|
|
|
check_installed_pkg base-chroot-0.11
|
2010-01-14 16:45:41 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2011-02-26 16:56:23 +00:00
|
|
|
echo "${XBPS_MASTERDIR} has not been prepared for chroot operations."
|
2011-06-23 01:21:50 +00:00
|
|
|
echo "Please install 'base-chroot>=0.11' and try again."
|
2010-01-14 16:45:41 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-12-19 23:22:12 +00:00
|
|
|
msg_normal "Entering into the chroot on $XBPS_MASTERDIR.\n"
|
2010-01-14 16:45:41 +00:00
|
|
|
|
2010-01-16 01:11:44 +00:00
|
|
|
if [ ! -d $XBPS_MASTERDIR/usr/local/etc ]; then
|
|
|
|
mkdir -p $XBPS_MASTERDIR/usr/local/etc
|
|
|
|
fi
|
2010-01-14 16:45:41 +00:00
|
|
|
|
|
|
|
XBPSSRC_CF=$XBPS_MASTERDIR/usr/local/etc/xbps-src.conf
|
|
|
|
|
2010-05-13 23:12:53 +00:00
|
|
|
cat > $XBPSSRC_CF <<_EOF
|
|
|
|
# Generated configuration file by xbps-src, DO NOT EDIT!
|
|
|
|
XBPS_DISTRIBUTIONDIR=/xbps
|
|
|
|
XBPS_MASTERDIR=/
|
|
|
|
XBPS_CFLAGS="$XBPS_CFLAGS"
|
|
|
|
XBPS_CXXFLAGS="$XBPS_CFLAGS"
|
2010-10-29 08:23:25 +00:00
|
|
|
XBPS_LDFLAGS="$XBPS_LDFLAGS"
|
2010-05-13 23:12:53 +00:00
|
|
|
XBPS_FETCH_CMD="xbps-uhelper.static fetch"
|
|
|
|
XBPS_COMPRESS_CMD="$XBPS_COMPRESS_CMD"
|
|
|
|
_EOF
|
|
|
|
|
2010-01-14 16:45:41 +00:00
|
|
|
if [ -n "$XBPS_MAKEJOBS" ]; then
|
|
|
|
echo "XBPS_MAKEJOBS=$XBPS_MAKEJOBS" >> $XBPSSRC_CF
|
|
|
|
fi
|
|
|
|
if [ -n "$XBPS_PREFER_BINPKG_DEPS" ]; then
|
|
|
|
echo "XBPS_PREFER_BINPKG_DEPS=$XBPS_PREFER_BINPKG_DEPS" >> $XBPSSRC_CF
|
|
|
|
fi
|
2010-01-16 01:11:44 +00:00
|
|
|
if [ -n "$XBPS_COMPRESS_LEVEL" ]; then
|
|
|
|
echo "XBPS_COMPRESS_LEVEL=$XBPS_COMPRESS_LEVEL" >> $XBPSSRC_CF
|
|
|
|
fi
|
2011-06-29 07:35:36 +00:00
|
|
|
if [ -n "$XBPS_CACHEDIR" ]; then
|
|
|
|
echo "XBPS_CACHEDIR=/cachedir" >> $XBPSSRC_CF
|
|
|
|
fi
|
2011-06-28 15:18:48 +00:00
|
|
|
|
2010-05-13 23:12:53 +00:00
|
|
|
echo "# End of configuration file." >> $XBPSSRC_CF
|
2010-01-14 16:45:41 +00:00
|
|
|
|
2010-12-18 13:33:30 +00:00
|
|
|
if [ -d $XBPS_MASTERDIR/tmp ]; then
|
2011-05-02 19:35:41 +00:00
|
|
|
if [ ! -f $XBPS_MASTERDIR/.xbps_mount_bind_done ]; then
|
|
|
|
msg_normal "Cleaning up /tmp...\n"
|
2011-06-20 16:32:43 +00:00
|
|
|
[ -h ${XBPS_MASTERDIR}/tmp ] || rm -rf $XBPS_MASTERDIR/tmp/*
|
2011-05-02 19:35:41 +00:00
|
|
|
fi
|
2010-12-18 13:33:30 +00:00
|
|
|
fi
|
|
|
|
|
2009-10-18 09:17:26 +00:00
|
|
|
prepare_chroot()
|
|
|
|
{
|
|
|
|
local f=
|
|
|
|
|
2011-06-20 16:32:43 +00:00
|
|
|
if [ -h ${XBPS_MASTERDIR}/tmp ]; then
|
|
|
|
rm -f ${XBPS_MASTERDIR}/tmp
|
|
|
|
mkdir ${XBPS_MASTERDIR}/tmp
|
|
|
|
fi
|
|
|
|
if [ -h ${XBPS_MASTERDIR}/var/run ]; then
|
|
|
|
rm -f ${XBPS_MASTERDIR}/var/run
|
|
|
|
mkdir -p ${XBPS_MASTERDIR}/var/run
|
|
|
|
fi
|
2009-10-18 09:17:26 +00:00
|
|
|
# Create some required files.
|
2010-01-16 01:11:44 +00:00
|
|
|
cp -f /etc/mtab $XBPS_MASTERDIR/etc
|
|
|
|
cp -f /etc/resolv.conf $XBPS_MASTERDIR/etc
|
|
|
|
[ -f /etc/localtime ] && cp -f /etc/localtime $XBPS_MASTERDIR/etc
|
|
|
|
|
2009-10-18 09:17:26 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
cat > $XBPS_MASTERDIR/etc/passwd <<_EOF
|
|
|
|
root:x:0:0:root:/root:/bin/bash
|
|
|
|
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
|
2010-01-16 01:11:44 +00:00
|
|
|
$(whoami):x:$(id -u):$(id -g):$(whoami) user:/dev/null:/bin/bash
|
2009-10-18 09:17:26 +00:00
|
|
|
_EOF
|
|
|
|
|
|
|
|
# Default group list as specified by LFS.
|
|
|
|
cat > $XBPS_MASTERDIR/etc/group <<_EOF
|
|
|
|
root:x:0:
|
|
|
|
bin:x:1:
|
|
|
|
sys:x:2:
|
|
|
|
kmem:x:3:
|
2010-01-14 17:52:14 +00:00
|
|
|
wheel:x:4:
|
|
|
|
tty:x:5:
|
|
|
|
tape:x:6:
|
|
|
|
daemon:x:7:
|
|
|
|
floppy:x:8:
|
|
|
|
disk:x:9:
|
|
|
|
lp:x:10:
|
|
|
|
dialout:x:11:
|
|
|
|
audio:x:12:
|
|
|
|
video:x:13:
|
|
|
|
utmp:x:14:
|
|
|
|
usb:x:15:
|
|
|
|
cdrom:x:16:
|
|
|
|
optical:x:17:
|
|
|
|
mail:x:18:
|
|
|
|
storage:x:19:
|
|
|
|
scanner:x:20:
|
2009-10-18 09:17:26 +00:00
|
|
|
nogroup:x:99:
|
|
|
|
users:x:1000:
|
2010-01-16 01:11:44 +00:00
|
|
|
$(whoami):x:$(id -g):
|
2009-10-18 09:17:26 +00:00
|
|
|
_EOF
|
|
|
|
|
|
|
|
# Default file as in Ubuntu.
|
|
|
|
cat > $XBPS_MASTERDIR/etc/hosts <<_EOF
|
|
|
|
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
|
|
|
|
|
2010-04-26 00:51:48 +00:00
|
|
|
create_binsh_symlink
|
2009-10-30 21:14:09 +00:00
|
|
|
|
2009-10-18 09:17:26 +00:00
|
|
|
touch $XBPS_MASTERDIR/.xbps_perms_done
|
|
|
|
}
|
|
|
|
|
2010-04-26 00:51:48 +00:00
|
|
|
create_binsh_symlink()
|
|
|
|
{
|
|
|
|
if [ ! -h $XBPS_MASTERDIR/bin/sh ]; then
|
2011-06-30 22:29:11 +00:00
|
|
|
cd $XBPS_MASTERDIR/bin
|
|
|
|
if [ -x bash ]; then
|
|
|
|
ln -sf bash sh
|
|
|
|
elif [ -x dash ]; then
|
|
|
|
ln -sf dash sh
|
|
|
|
elif [ -x busybox ]; then
|
|
|
|
ln -sf busybox sh
|
|
|
|
else
|
|
|
|
msg_error "cannot find a suitable shell for chroot!\n"
|
|
|
|
fi
|
|
|
|
|
2010-04-26 00:51:48 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-01-14 16:45:41 +00:00
|
|
|
prepare_binpkg_repos()
|
|
|
|
{
|
2011-06-22 10:33:18 +00:00
|
|
|
local repo xver
|
|
|
|
|
2011-06-24 20:00:47 +00:00
|
|
|
# Copy xbps-conf.plist for XBPS utils >= 0.9.0.
|
2011-06-22 10:33:18 +00:00
|
|
|
xver=$($XBPS_PKGDB_CMD -V|awk '{print $2}')
|
2011-06-24 20:00:47 +00:00
|
|
|
if [ -n "$xver" ]; then
|
|
|
|
for f in /etc /usr/local/etc; do
|
|
|
|
if [ -f $f/xbps-conf.plist ]; then
|
|
|
|
cp -f $f/xbps-conf.plist \
|
|
|
|
${XBPS_MASTERDIR}/usr/local/etc
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# XBPS utils >= 0.9.0.
|
|
|
|
msg_normal "Synchronizing index for remote repositories...\n"
|
2011-07-01 15:48:29 +00:00
|
|
|
${XBPS_REPO_CMD} sync
|
2011-06-24 20:00:47 +00:00
|
|
|
else
|
|
|
|
for repo in ${XBPS_REPO_LIST}; do
|
2011-07-01 15:48:29 +00:00
|
|
|
${XBPS_REPO_CMD} add ${repo} 2>/dev/null
|
2011-06-22 10:33:18 +00:00
|
|
|
[ $? -ne 0 ] && \
|
|
|
|
msg_warn "Failed to sync pkg-index from ${repo}\n"
|
2011-06-24 20:00:47 +00:00
|
|
|
done
|
|
|
|
fi
|
2010-01-14 16:45:41 +00:00
|
|
|
}
|
|
|
|
|
2009-10-30 21:14:09 +00:00
|
|
|
create_busybox_links()
|
|
|
|
{
|
|
|
|
local lbindir=$XBPS_MASTERDIR/usr/local/bin
|
|
|
|
|
|
|
|
[ -f $XBPS_MASTERDIR/.busybox_done ] && return 0
|
|
|
|
|
|
|
|
[ ! -d ${lbindir} ] && mkdir -p ${lbindir}
|
|
|
|
|
|
|
|
# Create other symlinks in /usr/local/bin
|
2011-02-11 15:29:02 +00:00
|
|
|
cd ${lbindir} || return 1
|
|
|
|
|
|
|
|
for f in $(${XBPS_MASTERDIR}/bin/busybox --list); do
|
2011-06-30 23:43:19 +00:00
|
|
|
if [ "$f" = "tar" -o "$f" = "xz" -o \
|
|
|
|
"$f" = "bzip2" -o "$f" = "gzip" -o "$f" = "sh" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2011-02-11 15:29:02 +00:00
|
|
|
ln -s ../../../bin/busybox $f
|
2009-10-30 21:14:09 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
touch -f $XBPS_MASTERDIR/.busybox_done
|
|
|
|
}
|
|
|
|
|
2009-10-18 09:17:26 +00:00
|
|
|
install_xbps_utils()
|
|
|
|
{
|
2009-11-24 12:21:49 +00:00
|
|
|
local needed _cmd
|
2009-10-18 09:17:26 +00:00
|
|
|
local xbps_prefix=$XBPS_MASTERDIR/usr/local
|
|
|
|
|
2009-11-24 12:21:49 +00:00
|
|
|
for f in bin repo uhelper; do
|
2009-10-30 21:14:09 +00:00
|
|
|
if [ ! -x $xbps_prefix/sbin/xbps-${f}.static ]; then
|
2009-10-18 09:17:26 +00:00
|
|
|
needed=yes
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -n "$needed" ]; then
|
2010-04-27 21:09:08 +00:00
|
|
|
echo "=> Installing static XBPS utils into masterdir."
|
2009-11-24 12:21:49 +00:00
|
|
|
for f in bin repo uhelper; do
|
|
|
|
_cmd=$(which xbps-${f}.static 2>/dev/null)
|
|
|
|
if [ -z "${_cmd}" ]; then
|
|
|
|
echo "Unexistent xbps-uhelper.static file!"
|
|
|
|
exit 1
|
2009-11-22 07:31:44 +00:00
|
|
|
fi
|
|
|
|
cp -f ${_cmd} $xbps_prefix/sbin
|
2009-10-18 09:17:26 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
xbps_chroot_handler()
|
|
|
|
{
|
2010-05-15 15:28:18 +00:00
|
|
|
local action="$1" pkg="$2" norm_builddir="$3" rv=0
|
2010-04-26 00:51:48 +00:00
|
|
|
local path="/tools/bin:/usr/local/sbin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin"
|
2010-05-07 10:25:24 +00:00
|
|
|
|
2009-10-18 09:17:26 +00:00
|
|
|
[ -z "$action" -o -z "$pkg" ] && return 1
|
|
|
|
|
|
|
|
[ "$action" != "configure" -a "$action" != "build" -a \
|
2010-05-07 10:25:24 +00:00
|
|
|
"$action" != "install" -a "$action" != "chroot" -a \
|
2011-06-16 10:21:12 +00:00
|
|
|
"$action" != "install-destdir" -a "$action" != "remove" ] && return 1
|
2009-10-18 09:17:26 +00:00
|
|
|
|
|
|
|
if [ ! -f $XBPS_MASTERDIR/.xbps_perms_done ]; then
|
|
|
|
echo -n "==> Preparing chroot on $XBPS_MASTERDIR... "
|
|
|
|
prepare_chroot
|
|
|
|
echo "done."
|
|
|
|
fi
|
|
|
|
|
2011-04-29 20:40:32 +00:00
|
|
|
if [ ! -d "$XBPS_MASTERDIR/tmp" ]; then
|
|
|
|
mkdir -p "$XBPS_MASTERDIR/tmp"
|
|
|
|
fi
|
|
|
|
|
2010-04-26 00:51:48 +00:00
|
|
|
create_binsh_symlink
|
2009-11-23 06:32:42 +00:00
|
|
|
create_busybox_links
|
|
|
|
install_xbps_utils
|
2010-04-27 19:52:36 +00:00
|
|
|
|
2010-05-09 17:46:28 +00:00
|
|
|
_mount || return $?
|
2010-04-27 19:52:36 +00:00
|
|
|
|
2010-04-26 00:51:48 +00:00
|
|
|
if [ -n "$XBPS_PREFER_BINPKG_DEPS" ]; then
|
|
|
|
prepare_binpkg_repos
|
|
|
|
fi
|
2009-11-23 06:32:42 +00:00
|
|
|
|
2009-11-22 07:31:44 +00:00
|
|
|
# Reinstall xbps-src in the chroot
|
2010-12-19 23:22:12 +00:00
|
|
|
msg_normal "Installing xbps-src in the masterdir...\n"
|
2010-05-13 22:16:37 +00:00
|
|
|
env in_chroot=yes LANG=C PATH=$path \
|
|
|
|
${chroot_cmd} $XBPS_MASTERDIR sh -c \
|
|
|
|
"cd /xbps/xbps-src && make IN_CHROOT=1 install clean" \
|
|
|
|
2>&1 >/dev/null || return $?
|
2009-11-22 07:31:44 +00:00
|
|
|
|
2011-05-26 08:14:39 +00:00
|
|
|
# Update ld.so(8) cache
|
|
|
|
msg_normal "Updating ld.so(8) cache...\n"
|
|
|
|
${chroot_cmd} $XBPS_MASTERDIR sh -c "ldconfig" || return $?
|
|
|
|
|
2009-10-18 09:17:26 +00:00
|
|
|
if [ "$action" = "chroot" ]; then
|
2010-05-09 17:46:28 +00:00
|
|
|
env in_chroot=yes IN_CHROOT=1 LANG=C PATH=$path \
|
2010-05-17 10:09:44 +00:00
|
|
|
${chroot_cmd} $XBPS_MASTERDIR /bin/sh || \
|
|
|
|
rv=$?
|
2009-10-18 09:17:26 +00:00
|
|
|
else
|
2010-05-07 10:25:24 +00:00
|
|
|
[ "$norm_builddir" = "yes" ] && \
|
2010-01-09 14:49:36 +00:00
|
|
|
action="-C $action"
|
2010-05-13 22:07:47 +00:00
|
|
|
env in_chroot=yes LANG=C PATH=$path _ORIGINPKG="$pkg" \
|
2010-05-07 10:25:24 +00:00
|
|
|
${chroot_cmd} $XBPS_MASTERDIR sh -c \
|
2010-05-17 10:09:44 +00:00
|
|
|
"cd /xbps/srcpkgs/$pkg && xbps-src $action" || \
|
|
|
|
rv=$?
|
2009-10-18 09:17:26 +00:00
|
|
|
fi
|
2010-04-27 21:09:08 +00:00
|
|
|
|
2010-12-19 23:22:12 +00:00
|
|
|
msg_normal "Exiting from the chroot on $XBPS_MASTERDIR.\n"
|
2010-04-27 19:52:36 +00:00
|
|
|
|
2010-05-15 15:28:18 +00:00
|
|
|
return $rv
|
2009-10-18 09:17:26 +00:00
|
|
|
}
|