Added support to build pkgs in the chroot as normal user via capchroot.

Please read the comment in xbps-src.conf to use it. Fully tested
and working nicely, probably some pkgs will need minimal changes.

--HG--
extra : convert_revision : 820ad6d48aa74cf5b6db1871adea750acccaa82f
This commit is contained in:
Juan RP 2010-01-16 02:11:44 +01:00
parent 5d6d7b0f4e
commit e57940985e
15 changed files with 406 additions and 242 deletions

View file

@ -1,36 +1,43 @@
include vars.mk
BIN = xbps-src
SUBDIRS = etc common helpers triggers shutils
BINS = xbps-src
SUBDIRS = etc common libexec helpers triggers shutils
.PHONY: all
all:
sed -e "s|@@XBPS_INSTALL_PREFIX@@|$(PREFIX)|g" \
-e "s|@@XBPS_INSTALL_ETCDIR@@|$(ETCDIR)|g" \
-e "s|@@XBPS_INSTALL_SHAREDIR@@|$(SHAREDIR)|g" \
$(BIN).sh.in > $(BIN)
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir || exit 1; \
for bin in $(BINS); do \
sed -e "s|@@XBPS_INSTALL_PREFIX@@|$(PREFIX)|g" \
-e "s|@@XBPS_INSTALL_ETCDIR@@|$(ETCDIR)|g" \
-e "s|@@XBPS_INSTALL_SHAREDIR@@|$(SHAREDIR)|g" \
-e "s|@@XBPS_INSTALL_SBINDIR@@|$(SBINDIR)|g" \
$$bin.sh.in > $$bin; \
done
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir || exit 1; \
done
.PHONY: clean
clean:
-rm -f $(BIN)
for dir in $(SUBDIRS); do \
-rm -f $(BINS)
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir clean || exit 1; \
done
.PHONY: install
install: all
install -d $(SBINDIR)
install -m 755 $(BIN) $(SBINDIR)
for dir in $(SUBDIRS); do \
for bin in $(BINS); do \
install -m 755 $$bin $(SBINDIR); \
done
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir install || exit 1; \
done
.PHONY: uninstall
uninstall:
-rm -f $(SBINDIR)/$(BIN)
for dir in $(SUBDIRS); do \
for bin in $(BINS); do \
rm -f $(SBINDIR)/$$bin; \
done
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir uninstall || exit 1; \
done

View file

@ -4,11 +4,12 @@
#
# Directory where xbps-src has been installed. By default /usr/local.
# Usually you don't have to change this one, it's set by "make install".
#
XBPS_INSTALLDIR=@@XBPS_INSTALL_PREFIX@@
#
# Directory where the xbps-src GIT repository is available. This is
# Directory where the xbps-src GIT repository is stored. This is
# required to be mounted in the chroot.
#
XBPS_DISTRIBUTIONDIR=$HOME/xbps-templates
@ -19,13 +20,14 @@ XBPS_DISTRIBUTIONDIR=$HOME/xbps-templates
XBPS_MASTERDIR=$XBPS_DISTRIBUTIONDIR/masterdir
#
# Binary packages directory: this is where the binary packages will
# be created to.
# Directory where a local binary package repository is available
# (or will be created from). Packages will be stored here.
#
XBPS_PACKAGESDIR=$XBPS_DISTRIBUTIONDIR/packages
#
# Directory where source files will be extracted to.
# Directory where source files will be extracted to and build object
# files will live on.
#
XBPS_BUILDDIR=$XBPS_DISTRIBUTIONDIR/builddir
@ -41,13 +43,13 @@ XBPS_CFLAGS="-O2 -pipe"
XBPS_CXXFLAGS="$XBPS_CFLAGS"
#
# Number of jobs when running GNU or BSD make style packages.
# Number of jobs when running make(1)-alike commands.
#
#XBPS_MAKEJOBS=4
#
# Compression program used to build the binary packages.
# Possible values: gzip, bzip2 or xz. Default xz.
# Possible value: gzip, bzip2 or xz. Default xz.
#
XBPS_COMPRESS_CMD=xz
@ -60,7 +62,24 @@ XBPS_COMPRESS_CMD=xz
#
# Install required build time dependencies from binary packages,
# XBPS_PACKAGESDIR will be used in the chroot to resolve
# builddeps.
# XBPS_PACKAGESDIR will be used in the chroot to resolve builddeps.
#
#XBPS_PREFER_BINPKG_DEPS=yes
#
# Build packages with your unprivileged user in the chroot
# via capchroot. The only required steps with privileges are
# the bind mounts, a helper script (xbps-src-chroot-helper) needs
# to be run with sudo for this task.
#
# fakeroot is only used for the installation stage via the helper
# script xbps-src-doinst-helper.
#
# capchroot allows ordinary users to use the chroot(2) syscall.
# To make this work, uncomment this option and run the following
# commands (as root):
#
# $ setcap cap_sys_chroot=ep /usr/bin/capchroot
# $ echo "/path/to/masterdir $(whoami)" >> /etc/capchroot.allow
#
#XBPS_USE_CAPCHROOT=yes

30
xbps-src/libexec/Makefile Normal file
View file

@ -0,0 +1,30 @@
include ../vars.mk
BINS = xbps-src-chroot-helper xbps-src-doinst-helper
.PHONY: all
all:
for bin in $(BINS); do \
sed -e "s|@@XBPS_INSTALL_PREFIX@@|$(PREFIX)|g" \
-e "s|@@XBPS_INSTALL_ETCDIR@@|$(ETCDIR)|g" \
-e "s|@@XBPS_INSTALL_SHAREDIR@@|$(SHAREDIR)|g" \
-e "s|@@XBPS_INSTALL_SBINDIR@@|$(SBINDIR)|g" \
$$bin.sh.in > $$bin; \
done
.PHONY: clean
clean:
-rm -f $(BINS)
.PHONY: install
install: all
install -d $(DESTDIR)$(LIBEXECDIR)
for bin in $(BINS); do \
install -m 755 $$bin $(DESTDIR)$(LIBEXECDIR); \
done
.PHONY: uninstall
uninstall:
for bin in $(BINS); do \
rm -f $(DESTDIR)$(LIBEXECDIR)/$$bin; \
done

View file

@ -0,0 +1,111 @@
#!/bin/sh
#-
# Copyright (c) 2010 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.
#-
# Umount stuff if SIGINT or SIGQUIT was caught
trap umount_chroot_fs INT QUIT
HANDLER="$1"
. @@XBPS_INSTALL_ETCDIR@@/xbps-src.conf
EXTDIRS="xbps xbps_builddir xbps_packagesdir xbps_srcdistdir"
REQFS="sys proc dev ${EXTDIRS}"
mount_chroot_fs()
{
local cnt f blah
for f in ${REQFS}; do
if [ ! -f ${XBPS_MASTERDIR}/.${f}_mount_bind_done ]; then
echo -n "=> Mounting /${f} in chroot... "
if [ ! -d ${XBPS_MASTERDIR}/${f} ]; then
mkdir -p ${XBPS_MASTERDIR}/${f}
fi
case ${f} in
xbps) blah=${XBPS_DISTRIBUTIONDIR};;
xbps_builddir) blah=${XBPS_BUILDDIR};;
xbps_srcdistdir) blah=${XBPS_SRCDISTDIR};;
xbps_packagesdir) blah=${XBPS_PACKAGESDIR};;
*) blah=/${f};;
esac
[ ! -d ${blah} ] && echo "failed." && continue
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
}
umount_chroot_fs()
{
local fs dir cnt
for fs in ${REQFS}; do
[ ! -f ${XBPS_MASTERDIR}/.${fs}_mount_bind_done ] && continue
cnt=$(cat ${XBPS_MASTERDIR}/.${fs}_mount_bind_done)
if [ ${cnt} -gt 1 ]; then
cnt=$((${cnt} - 1))
echo ${cnt} > ${XBPS_MASTERDIR}/.${fs}_mount_bind_done
else
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
fi
unset fs
done
# Remove created dirs
for dir in ${EXTDIRS}; do
[ -f ${XBPS_MASTERDIR}/.${dir}_mount_bind_done ] && continue
[ -d ${XBPS_MASTERDIR}/${dir} ] && rmdir ${XBPS_MASTERDIR}/${dir}
done
}
if [ $# -ne 1 ]; then
echo "$0: mount || umount"
exit 1
fi
case "${HANDLER}" in
mount) mount_chroot_fs;;
umount) umount_chroot_fs;;
*) echo "$0: invalid target." && exit 1;;
esac
exit 0

View file

@ -1,5 +1,6 @@
#!/bin/sh
#-
# Copyright (c) 2008-2009 Juan Romero Pardines.
# Copyright (c) 2010 Juan Romero Pardines.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -23,10 +24,16 @@
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-
#
# Runs the "install" phase for a pkg. This consists in installing package
# into the destination directory.
#
PKG_TMPLNAME="$1"
. @@XBPS_INSTALL_ETCDIR@@/xbps-src.conf
. @@XBPS_INSTALL_SHAREDIR@@/shutils/init_funcs.sh
set_defvars
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
. $XBPS_SHUTILSDIR/common_funcs.sh
. $XBPS_SHUTILSDIR/builddep_funcs.sh
strip_files()
{
@ -40,10 +47,10 @@ strip_files()
case "$(file -biz $f)" in
application/x-executable*)
/usr/bin/strip $f && \
echo "===> Stripped executable: $(basename $f)";;
echo "=> Stripped executable: $(basename $f)";;
application/x-sharedlib*|application/x-archive*)
/usr/bin/strip -S $f && \
echo "===> Stripped library: $(basename $f)";;
echo "=> Stripped library: $(basename $f)";;
esac
done
}
@ -166,7 +173,7 @@ make_install()
make_install_target="DESTDIR=${DESTDIR} install"
fi
[ -z "$make_cmd" ] && make_cmd=/usr/bin/make
[ -z "$make_cmd" ] && make_cmd=make
. $XBPS_SHUTILSDIR/buildvars_funcs.sh
set_build_vars
@ -174,9 +181,16 @@ make_install()
#
# Install package via make.
#
run_rootcmd no ${make_cmd} ${make_install_target} \
${make_cmd} ${make_install_target} \
${make_install_args} || msg_error "installing $pkgname-$lver"
# Unset build vars.
unset_build_vars
}
[ -z "$PKG_TMPLNAME" ] && exit 1
setup_tmpl $PKG_TMPLNAME
install_src_phase $pkgname
exit $?

View file

@ -1,10 +1,19 @@
include ../vars.mk
SCRIPTS = chroot.sh init_funcs.sh pkgtarget_funcs.sh
.PHONY: all
all:
for f in $(SCRIPTS); do \
sed -e "s|@@XBPS_INSTALL_PREFIX@@|$(PREFIX)|g" \
-e "s|@@XBPS_INSTALL_SHAREDIR@@|$(SHAREDIR)|g" \
-e "s|@@XBPS_INSTALL_LIBEXECDIR@@|$(LIBEXECDIR)|g" \
$$f.in > $$f; \
done
.PHONY: clean
clean:
-rm -f $(SCRIPTS)
.PHONY: install
install:

View file

@ -77,7 +77,18 @@ install_pkg_deps()
prev_pkg="$j"
done
install_pkg $curpkgname
if [ -n "$XBPS_PREFER_BINPKG_DEPS" ]; then
install_pkg_with_binpkg ${curpkg}
if [ $? -eq 255 ]; then
# xbps-bin returned unexpected error
return $?
elif [ $? -eq 1 ]; then
# Package not found, build from source.
install_pkg $curpkgname
fi
else
install_pkg $curpkgname
fi
[ -n "$prev_pkg" ] && unset prev_pkg
}
@ -121,7 +132,13 @@ install_dependencies_pkg()
for i in ${notinstalled_deps}; do
if [ -n "$XBPS_PREFER_BINPKG_DEPS" ]; then
install_pkg_with_binpkg ${i}
[ $? -eq 0 ] && continue
if [ $? -eq 255 ]; then
# xbps-bin returned unexpected error (-1)
return $?
elif [ $? -eq 0 ]; then
# installed successfully
continue
fi
fi
pkgn=$($XBPS_PKGDB_CMD getpkgdepname ${i})
check_pkgdep_matched "${i}"
@ -131,7 +148,21 @@ install_dependencies_pkg()
check_build_depends_pkg
if [ $? -eq 1 ]; then
msg_normal "Installing $lpkgname dependency: $pkgn."
install_pkg $pkgn
if [ -n "$XBPS_PREFER_BINPKG_DEPS" ]; then
install_pkg_with_binpkg ${i}
if [ $? -eq 255 ]; then
# xbps-bin returned unexpected error
return $?
elif [ $? -eq 0 ]; then
# installed successfully
continue
else
# package not found, build source.
install_pkg $pkgn
fi
else
install_pkg $pkgn
fi
else
install_pkg_deps "${i}" $pkg
fi

View file

@ -29,10 +29,19 @@
#
# Umount stuff if SIGINT or SIGQUIT was caught
trap umount_chroot_fs INT QUIT
trap "${sudo_cmd} @@XBPS_INSTALL_LIBEXECDIR@@/xbps-src-chroot-helper umount && exit $?" INT QUIT
[ -n "$base_chroot" ] && return 0
if [ "${chroot_cmd}" = "chroot" ]; then
if [ "$(id -u)" -ne 0 ]; then
echo "Root permissions are required for the chroot, try again."
exit 1
fi
else
chroot_cmd_args="--"
fi
. $XBPS_SHUTILSDIR/builddep_funcs.sh
check_installed_pkg xbps-base-chroot-0.11
if [ $? -ne 0 ]; then
@ -41,21 +50,11 @@ if [ $? -ne 0 ]; then
exit 1
fi
if [ "$(id -u)" -ne 0 ]; then
echo "This package requires to be installed in a chroot."
echo "You cannot do this as normal user, try again being root."
exit 1
fi
msg_normal "Entering into the chroot on $XBPS_MASTERDIR."
EXTDIRS="xbps xbps_builddir xbps_destdir xbps_packagesdir \
xbps_srcdistdir"
REQDIRS="bin sbin tmp var sys proc dev usr/local/etc ${EXTDIRS}"
for f in ${REQDIRS}; do
[ ! -d $XBPS_MASTERDIR/$f ] && mkdir -p $XBPS_MASTERDIR/$f
done
unset f REQDIRS
if [ ! -d $XBPS_MASTERDIR/usr/local/etc ]; then
mkdir -p $XBPS_MASTERDIR/usr/local/etc
fi
XBPSSRC_CF=$XBPS_MASTERDIR/usr/local/etc/xbps-src.conf
@ -73,13 +72,20 @@ fi
if [ -n "$XBPS_PREFER_BINPKG_DEPS" ]; then
echo "XBPS_PREFER_BINPKG_DEPS=$XBPS_PREFER_BINPKG_DEPS" >> $XBPSSRC_CF
fi
echo "XBPS_COMPRESS_CMD=$XBPS_COMPRESS_CMD" >> $XBPSSRC_CF
if [ -n "$XBPS_COMPRESS_LEVEL" ]; then
echo "XBPS_COMPRESS_LEVEL=$XBPS_COMPRESS_LEVEL" >> $XBPSSRC_CF
fi
prepare_chroot()
{
local f=
# Create some required files.
touch $XBPS_MASTERDIR/etc/mtab
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
for f in run/utmp log/btmp log/lastlog log/wtmp; do
touch -f $XBPS_MASTERDIR/var/$f
done
@ -90,6 +96,7 @@ prepare_chroot()
cat > $XBPS_MASTERDIR/etc/passwd <<_EOF
root:x:0:0:root:/root:/bin/bash
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
$(whoami):x:$(id -u):$(id -g):$(whoami) user:/dev/null:/bin/bash
_EOF
# Default group list as specified by LFS.
@ -117,6 +124,7 @@ storage:x:19:
scanner:x:20:
nogroup:x:99:
users:x:1000:
$(whoami):x:$(id -g):
_EOF
# Default file as in Ubuntu.
@ -133,28 +141,18 @@ ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
_EOF
cp -f /etc/resolv.conf $XBPS_MASTERDIR/etc
[ -f /etc/localtime ] && cp -f /etc/localtime $XBPS_MASTERDIR/etc
# Create /bin/sh symlink to bash
cd $XBPS_MASTERDIR/bin && ln -sf bash sh
touch $XBPS_MASTERDIR/.xbps_perms_done
}
rebuild_ldso_cache()
{
echo -n "==> Rebuilding chroot's dynamic linker cache..."
chroot $XBPS_MASTERDIR /sbin/ldconfig -c /etc/ld.so.conf
chroot $XBPS_MASTERDIR /sbin/ldconfig -C /etc/ld.so.cache
echo " done."
}
prepare_binpkg_repos()
{
if [ ! -f "$XBPS_MASTERDIR/.xbps_added_local_repo" ]; then
msg_normal "Registering local binpkg repo..."
chroot $XBPS_MASTERDIR xbps-repo.static add /xbps_packagesdir
${chroot_cmd} $XBPS_MASTERDIR ${chroot_cmd_args} \
xbps-repo.static add /xbps_packagesdir
[ $? -eq 0 ] && touch -f $XBPS_MASTERDIR/.xbps_added_local_repo
fi
}
@ -191,8 +189,6 @@ install_xbps_utils()
if [ -n "$needed" ]; then
echo "=> Installing the required XBPS utils."
chroot $XBPS_MASTERDIR sh -c \
"echo /usr/local/lib > /etc/ld.so.conf"
for f in bin repo uhelper; do
_cmd=$(which xbps-${f}.static 2>/dev/null)
if [ -z "${_cmd}" ]; then
@ -201,7 +197,6 @@ install_xbps_utils()
fi
cp -f ${_cmd} $xbps_prefix/sbin
done
rebuild_ldso_cache
fi
}
@ -225,19 +220,20 @@ xbps_chroot_handler()
create_busybox_links
install_xbps_utils
mount_chroot_fs
${sudo_cmd} @@XBPS_INSTALL_LIBEXECDIR@@/xbps-src-chroot-helper mount
[ $? -ne 0 ] && return $?
prepare_binpkg_repos
# Reinstall xbps-src in the chroot
if [ ! -f $XBPS_MASTERDIR/usr/local/sbin/xbps-src ]; then
env in_chroot=yes LANG=C PATH=$path \
chroot $XBPS_MASTERDIR sh -c \
${chroot_cmd} $XBPS_MASTERDIR ${chroot_cmd_args} sh -c \
"cd /xbps/xbps-src && make install clean"
fi
if [ "$action" = "chroot" ]; then
env in_chroot=yes LANG=C PATH=$path \
chroot $XBPS_MASTERDIR /bin/sh
${chroot_cmd} $XBPS_MASTERDIR /bin/sh
else
local lenv
[ -n "$only_destdir" ] && \
@ -245,75 +241,11 @@ xbps_chroot_handler()
[ -n "$norm_builddir" ] && \
action="-C $action"
env in_chroot=yes LANG=C PATH=$path \
${lenv} chroot $XBPS_MASTERDIR sh -c \
${lenv} ${chroot_cmd} $XBPS_MASTERDIR \
${chroot_cmd_args} sh -c \
"cd /xbps/srcpkgs/$pkg && xbps-src $action"
fi
msg_normal "Exiting from the chroot on $XBPS_MASTERDIR."
umount_chroot_fs
}
mount_chroot_fs()
{
local cnt=
REQFS="sys proc dev xbps xbps_builddir \
xbps_packagesdir 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_srcdistdir) blah=$XBPS_SRCDISTDIR;;
xbps_packagesdir) blah=$XBPS_PACKAGESDIR;;
*) blah=/$f;;
esac
[ ! -d $blah ] && echo "failed." && continue
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
}
umount_chroot_fs()
{
local fs=
local dir=
local cnt=
for fs in ${REQFS}; do
[ ! -f $XBPS_MASTERDIR/.${fs}_mount_bind_done ] && continue
cnt=$(cat $XBPS_MASTERDIR/.${fs}_mount_bind_done)
if [ $cnt -gt 1 ]; then
cnt=$(($cnt - 1))
echo $cnt > $XBPS_MASTERDIR/.${fs}_mount_bind_done
else
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
fi
unset fs
done
for dir in ${EXTDIRS}; do
[ -f $XBPS_MASTERDIR/.${dir}_mount_bind_done ] && continue
[ -d $XBPS_MASTERDIR/$dir ] && rmdir $XBPS_MASTERDIR/$dir
done
${sudo_cmd} @@XBPS_INSTALL_LIBEXECDIR@@/xbps-src-chroot-helper umount
return $?
}

View file

@ -39,23 +39,6 @@ run_func()
fi
}
run_rootcmd()
{
local lenv=
local usesudo="$1"
[ -n "$in_chroot" ] && unset fakeroot_cmd
lenv="XBPS_DISTRIBUTIONDIR=$XBPS_DISTRIBUTIONDIR"
shift
if [ "$usesudo" = "yes" -a -z "$in_chroot" ]; then
sudo env ${lenv} $@
else
env ${lenv} ${fakeroot_cmd} $@
fi
}
msg_error()
{
[ -z "$1" ] && return 1

View file

@ -0,0 +1,70 @@
#-
# Copyright (c) 2008-2010 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.
#-
set_defvars()
{
local DDIRS i instver instsharedir
instsharedir=@@XBPS_INSTALL_SHAREDIR@@
: ${XBPS_TRIGGERSDIR:=$instsharedir/triggers}
: ${XBPS_HELPERSDIR:=$instsharedir/helpers}
: ${XBPS_SHUTILSDIR:=$instsharedir/shutils}
: ${XBPS_COMMONVARSDIR:=$instsharedir/common}
: ${XBPS_DBDIR:=$XBPS_MASTERDIR/var/db/xbps}
: ${XBPS_META_PATH:=$XBPS_DBDIR/}
: ${XBPS_PKGMETADIR:=$XBPS_DBDIR/metadata}
: ${XBPS_SRCPKGDIR:=$XBPS_DISTRIBUTIONDIR/srcpkgs}
if [ -n "$in_chroot" ]; then
: ${XBPS_DESTDIR:=/pkg-destdir}
else
: ${XBPS_DESTDIR:=$XBPS_MASTERDIR/pkg-destdir}
fi
DDIRS="XBPS_TRIGGERSDIR XBPS_HELPERSDIR"
DDIRS="$DDIRS XBPS_COMMONVARSDIR XBPS_SHUTILSDIR"
for i in ${DDIRS}; do
eval val="\$$i"
[ ! -d "$val" ] && msg_error "cannot find $i, aborting."
done
export XBPS_PKGDB_CMD="xbps-uhelper.static -r $XBPS_MASTERDIR"
export XBPS_BIN_CMD="xbps-bin.static -r $XBPS_MASTERDIR"
export XBPS_DIGEST_CMD="xbps-uhelper.static digest"
export XBPS_CMPVER_CMD="xbps-uhelper.static cmpver"
export XBPS_FETCH_CMD="xbps-uhelper.static fetch"
#
# Check that installed xbps utils version is recent enough.
#
instver=$(${XBPS_PKGDB_CMD} -V)
${XBPS_CMPVER_CMD} "${instver}" "${XBPS_UTILS_REQVER}"
if [ $? -eq 255 ]; then
echo -n "Your xbps utilities are too old, "
echo "required version: ${XBPS_UTILS_REQVER}"
exit 1
fi
}

View file

@ -56,7 +56,7 @@ binpkg_cleanup()
#
xbps_make_binpkg_real()
{
local mfiles binpkg pkgdir arch use_sudo lver dirs _dirs d clevel
local mfiles binpkg pkgdir arch lver dirs _dirs d clevel
if [ ! -d "${DESTDIR}" ]; then
msg_warn "cannot find destdir for $pkgname... skipping!"
@ -69,11 +69,6 @@ xbps_make_binpkg_real()
else
arch=$xbps_machine
fi
if [ -n "$base_chroot" ]; then
use_sudo=no
else
use_sudo=yes
fi
if [ -n "$revision" ]; then
lver="${version}_${revision}"
else
@ -116,8 +111,9 @@ xbps_make_binpkg_real()
trap "binpkg_cleanup" INT
echo -n "=> Building $binpkg... "
run_rootcmd $use_sudo tar --exclude "var/db/xbps/metadata/*/flist" \
-cpf - ${mfiles} ${dirs} | \
${fakeroot_cmd} ${fakeroot_cmd_args} \
tar --exclude "var/db/xbps/metadata/*/flist" \
-cpf - ${mfiles} ${dirs} | \
$XBPS_COMPRESS_CMD ${clevel} -qf > $pkgdir/$binpkg
if [ $? -eq 0 ]; then
echo "done."

View file

@ -42,7 +42,6 @@ install_pkg()
fi
pkg="$curpkgn-$version"
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
if [ -n "$doing_deps" ]; then
reset_tmpl_vars
setup_tmpl $curpkgn
@ -61,21 +60,10 @@ install_pkg()
fi
fi
#
# Execute command in chroot if necessary.
#
if [ -z "$base_chroot" -a -z "$in_chroot" ]; then
. $XBPS_SHUTILSDIR/chroot.sh
[ -n "$install_destdir_target" ] && cdestdir=yes
xbps_chroot_handler install $curpkgn $cdestdir $dontrm_builddir
return $?
fi
#
# Install dependencies required by this package.
#
if [ -z "$doing_deps" ]; then
. $XBPS_SHUTILSDIR/builddep_funcs.sh
install_dependencies_pkg $pkg
#
# At this point all required deps are installed, and
@ -106,8 +94,11 @@ install_pkg()
build_src_phase
fi
. $XBPS_SHUTILSDIR/install_funcs.sh
install_src_phase
# Install pkg into destdir.
env xbps_machine=${xbps_machine} \
${fakeroot_cmd} ${fakeroot_cmd_args} \
@@XBPS_INSTALL_LIBEXECDIR@@/xbps-src-doinst-helper \
${curpkgn} || return $?
# Always write metadata to package's destdir.
. $XBPS_SHUTILSDIR/metadata.sh
@ -142,7 +133,8 @@ install_pkg_with_binpkg()
fi
msg_normal "Installing binary pkg: $pkgpattern"
$XBPS_BIN_CMD -y install "$pkgpattern"
${fakeroot_cmd} ${fakeroot_cmd_args} ${XBPS_BIN_CMD} \
-y install "$pkgpattern"
return $?
}

View file

@ -97,7 +97,9 @@ setup_tmpl()
local pkg="$1"
[ -z "$pkg" ] && return 1
[ "$pkgname" = "$pkg" ] && return 0
if [ "$pkgname" = "$pkg" ]; then
[ -n "$DESTDIR" ] && return 0
fi
for f in $(echo $XBPS_COMMONVARSDIR/*.sh); do
[ -r ${f} ] && . ${f}

View file

@ -3,7 +3,8 @@
PREFIX ?= /usr/local
SBINDIR ?= $(DESTDIR)$(PREFIX)/sbin
#
# The following two vars shouldn't be specified with DESTDIR!
# The following vars shouldn't be specified with DESTDIR!
#
SHAREDIR ?= $(PREFIX)/share/xbps-src
LIBEXECDIR ?= $(PREFIX)/libexec
ETCDIR ?= $(PREFIX)/etc

View file

@ -29,6 +29,9 @@ trap "echo && exit 1" INT QUIT
: ${progname:=$(basename $0)}
: ${fakeroot_cmd:=fakeroot}
: ${fakeroot_cmd_args:=--}
: ${sudo_cmd:=sudo}
: ${chroot_cmd:=chroot}
: ${xbps_machine:=$(uname -m)}
: ${XBPS_UTILS_REQVER:=20091124-1}
@ -52,7 +55,6 @@ Targets:
install install-destdir + stow.
list List installed packages in masterdir.
listfiles List installed files from <pkg>.
reinstall remove + install.
remove Remove package completely (destdir + masterdir).
stow Copy <pkg> files from destdir into masterdir and
register package in database.
@ -93,56 +95,6 @@ run_file()
. $path_fixed
}
set_defvars()
{
local DDIRS i instver instsharedir
instsharedir=@@XBPS_INSTALL_SHAREDIR@@
: ${XBPS_TRIGGERSDIR:=$instsharedir/triggers}
: ${XBPS_HELPERSDIR:=$instsharedir/helpers}
: ${XBPS_SHUTILSDIR:=$instsharedir/shutils}
: ${XBPS_COMMONVARSDIR:=$instsharedir/common}
: ${XBPS_DBDIR:=$XBPS_MASTERDIR/var/db/xbps}
: ${XBPS_META_PATH:=$XBPS_DBDIR/}
: ${XBPS_PKGMETADIR:=$XBPS_DBDIR/metadata}
: ${XBPS_SRCPKGDIR:=$XBPS_DISTRIBUTIONDIR/srcpkgs}
if [ -n "$in_chroot" ]; then
: ${XBPS_DESTDIR:=/pkg-destdir}
else
: ${XBPS_DESTDIR:=$XBPS_MASTERDIR/pkg-destdir}
fi
DDIRS="XBPS_TRIGGERSDIR XBPS_HELPERSDIR"
DDIRS="$DDIRS XBPS_COMMONVARSDIR XBPS_SHUTILSDIR"
for i in ${DDIRS}; do
eval val="\$$i"
[ ! -d "$val" ] && msg_error "cannot find $i, aborting."
done
export XBPS_PKGDB_CMD="xbps-uhelper.static -r $XBPS_MASTERDIR"
export XBPS_BIN_CMD="xbps-bin.static -r $XBPS_MASTERDIR"
export XBPS_DIGEST_CMD="xbps-uhelper.static digest"
export XBPS_CMPVER_CMD="xbps-uhelper.static cmpver"
export XBPS_FETCH_CMD="xbps-uhelper.static fetch"
#
# Check that installed xbps utils version is recent enough.
#
instver=$(${XBPS_PKGDB_CMD} -V)
${XBPS_CMPVER_CMD} "${instver}" "${XBPS_UTILS_REQVER}"
if [ $? -eq 255 ]; then
echo -n "Your xbps utilities are too old, "
echo "required version: ${XBPS_UTILS_REQVER}"
exit 1
fi
}
#
# Checks that all required variables specified in the configuration
# file are properly working.
#
check_config_vars()
{
local cffound f
@ -201,9 +153,24 @@ fi
# Check configuration vars before anyting else, and set defaults vars.
#
check_config_vars
. @@XBPS_INSTALL_SHAREDIR@@/shutils/init_funcs.sh
set_defvars
. $XBPS_SHUTILSDIR/common_funcs.sh
if [ "$(id -u)" -eq 0 ]; then
# disable sudo and fakeroot if uid==0
unset sudo_cmd
if [ -n "$in_chroot" ]; then
unset fakeroot_cmd
unset fakeroot_cmd_args
fi
fi
if [ -n "$XBPS_USE_CAPCHROOT" ]; then
chroot_cmd="capchroot"
fi
# Main switch
case "$target" in
build|configure)
@ -212,11 +179,7 @@ build|configure)
if [ -z "$base_chroot" -a -z "$in_chroot" ]; then
. $XBPS_SHUTILSDIR/chroot.sh
if [ "$target" = "build" ]; then
xbps_chroot_handler build $pkgname
else
xbps_chroot_handler configure $pkgname
fi
xbps_chroot_handler $target $pkgname
else
. $XBPS_SHUTILSDIR/fetch_funcs.sh
fetch_distfiles
@ -274,10 +237,20 @@ extract|fetch|info)
extract_distfiles
;;
install|install-destdir)
. $XBPS_SHUTILSDIR/tmpl_funcs.sh
[ ! -r ./template ] && msg_error "missing build template file."
. ./template
[ "$target" = "install-destdir" ] && install_destdir_target=yes
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
setup_tmpl $(basename_cwd)
install_pkg $pkgname
if [ -z "$in_chroot" -a -z "$base_chroot" ]; then
. $XBPS_SHUTILSDIR/chroot.sh
xbps_chroot_handler install $(basename_cwd) \
$install_destdir_target $dontrm_builddir
else
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
setup_tmpl $(basename_cwd)
install_pkg $pkgname
fi
;;
list|listfiles)
if [ "$target" = "list" ]; then
@ -287,12 +260,6 @@ list|listfiles)
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
list_pkg_files $2
;;
reinstall)
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
setup_tmpl $(basename_cwd)
remove_pkg
install_pkg $pkgname
;;
remove)
. $XBPS_SHUTILSDIR/pkgtarget_funcs.sh
setup_tmpl $(basename_cwd)