Merge xbps-src code to make it usable in a standalone mode.

The new xbps-src configuration file is `etc/conf` where you can
add your local overrides from defaults set via `etc/defaults.conf`.

To use this xbps-src, run these steps:

	$ make
	$ sudo make setup (to make chroot helper setgid)
	$ ./xbps-src ...
This commit is contained in:
Juan RP 2014-03-22 12:31:42 +01:00
parent 49e9dc0df8
commit 0b95cb8f5d
20 changed files with 2825 additions and 0 deletions

View file

@ -0,0 +1,273 @@
/*-
* Copyright (c) 2014 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.
*/
/*
* This is based on linux-user-chroot by Colin Walters, but has been adapted
* specifically for xbps-src use:
*
* - This bind mounts exactly what we need, no support for additional mounts.
* - This uses IPC/PID/mount namespaces, nothing more.
* - Disables namespace features if running in OpenVZ containers.
*/
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/prctl.h>
#include <sys/fsuid.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <sched.h>
#include <limits.h> /* PATH_MAX */
#ifndef SECBIT_NOROOT
#define SECBIT_NOROOT (1 << 0)
#endif
#ifndef SECBIT_NOROOT_LOCKED
#define SECBIT_NOROOT_LOCKED (1 << 1)
#endif
#ifndef PR_SET_NO_NEW_PRIVS
#define PR_SET_NO_NEW_PRIVS 38
#endif
static void
die(const char *fmt, ...)
{
va_list ap;
int save_errno = errno;
va_start(ap, fmt);
fprintf(stderr, "ERROR ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, " (%s)\n", strerror(save_errno));
va_end(ap);
exit(EXIT_FAILURE);
}
static void
usage(const char *p)
{
printf("Usage: %s [-D dir] [-H dir] [-S dir] <chrootdir> <command>\n\n"
"-D <distdir> Directory to be bind mounted at <chrootdir>/xbps-packages\n"
"-H <hostdir> Directory to be bind mounted at <chrootdir>/host\n"
"-S <shmdir> Directory to be bind mounted at <chrootdir>/<shmdir>\n", p);
exit(EXIT_FAILURE);
}
static int
fsuid_chdir(uid_t uid, const char *path)
{
int saveerrno, rv;
(void)setfsuid(uid);
rv = chdir(path);
saveerrno = errno;
(void)setfsuid(0);
errno = saveerrno;
return rv;
}
static int
openvz_container(void)
{
if ((!access("/proc/vz/vzaquota", R_OK)) &&
(!access("/proc/user_beancounters", R_OK)))
return 1;
return 0;
}
static void
bindmount(uid_t ruid, const char *chrootdir, const char *dir, const char *dest)
{
char mountdir[PATH_MAX-1];
snprintf(mountdir, sizeof(mountdir), "%s/%s", chrootdir, dest ? dest : dir);
if (fsuid_chdir(ruid, dir) == -1)
die("Couldn't chdir to %s", dir);
if (mount(".", mountdir, NULL, MS_BIND|MS_PRIVATE, NULL) == -1)
die("Failed to bind mount %s at %s", dir, mountdir);
}
int
main(int argc, char **argv)
{
uid_t ruid, euid, suid;
gid_t rgid, egid, sgid;
const char *chrootdir, *distdir, *hostdir, *shmdir, *cmd, *argv0;
char **cmdargs, mountdir[PATH_MAX-1];
int aidx = 0, clone_flags, child_status = 0;
pid_t child;
chrootdir = distdir = hostdir = shmdir = cmd = NULL;
argv0 = argv[0];
argc--;
argv++;
if (argc < 2)
usage(argv0);
while (aidx < argc) {
if (strcmp(argv[aidx], "-D") == 0) {
/* distdir */
distdir = argv[aidx+1];
aidx += 2;
} else if (strcmp(argv[aidx], "-H") == 0) {
/* hostdir */
hostdir = argv[aidx+1];
aidx += 2;
} else if (strcmp(argv[aidx], "-S") == 0) {
/* shmdir */
shmdir = argv[aidx+1];
aidx += 2;
} else {
break;
}
}
if ((argc - aidx) < 2)
usage(argv0);
chrootdir = argv[aidx];
cmd = argv[aidx+1];
cmdargs = argv + aidx + 1;
/* Never allow chrootdir == / */
if (strcmp(chrootdir, "/") == 0)
die("/ is not allowed to be used as chrootdir");
if (getresgid(&rgid, &egid, &sgid) == -1)
die("getresgid");
if (getresuid(&ruid, &euid, &suid) == -1)
die("getresuid");
if (rgid == 0)
rgid = ruid;
clone_flags = (SIGCHLD|CLONE_NEWNS|CLONE_NEWIPC|CLONE_NEWUTS|CLONE_NEWPID);
if (openvz_container()) {
/*
* If running in a OpenVZ container simply disable all namespace
* features.
*/
clone_flags &= ~(CLONE_NEWNS|CLONE_NEWIPC|CLONE_NEWUTS|CLONE_NEWPID);
}
/* Issue the clone(2) syscall with our settings */
if ((child = syscall(__NR_clone, clone_flags, NULL)) == -1)
die("clone");
if (child == 0) {
/*
* Restrict privileges on the child.
*/
if (prctl(PR_SET_NO_NEW_PRIVS, 1) == -1 && errno != EINVAL) {
die("prctl PR_SET_NO_NEW_PRIVS");
} else if (prctl (PR_SET_SECUREBITS,
SECBIT_NOROOT|SECBIT_NOROOT_LOCKED) == -1) {
die("prctl SECBIT_NOROOT");
}
if (!openvz_container()) {
/* Make / a private mount */
if (mount(NULL, "/", "none", MS_PRIVATE|MS_REC, NULL) == -1)
die("mount(/, MS_PRIVATE|MS_REC)");
/* Remount / with nosuid just in case */
if (mount (NULL, "/", "none", MS_PRIVATE|MS_REMOUNT|MS_NOSUID, NULL) == -1)
die("mount(/, MS_PRIVATE|MS_REMOUNT|MS_NOSUID");
}
/* mount /proc */
snprintf(mountdir, sizeof(mountdir), "%s/proc", chrootdir);
if (mount("proc", mountdir, "proc", MS_MGC_VAL|MS_PRIVATE, NULL) == -1)
die("Failed to mount %s", mountdir);
/* bind mount /sys */
bindmount(ruid, chrootdir, "/sys", NULL);
/* bind mount /dev */
bindmount(ruid, chrootdir, "/dev", NULL);
/* bind mount hostdir if set */
if (hostdir)
bindmount(ruid, chrootdir, hostdir, "/host");
/* bind mount distdir (if set) */
if (distdir)
bindmount(ruid, chrootdir, distdir, "/xbps-packages");
/* bind mount shmdir (if set) */
if (shmdir)
bindmount(ruid, chrootdir, shmdir, NULL);
/* move chrootdir to / and chroot to it */
if (fsuid_chdir(ruid, chrootdir) == -1)
die("Failed to chdir to %s", chrootdir);
if (mount(".", ".", NULL, MS_BIND|MS_PRIVATE, NULL) == -1)
die("Failed to bind mount %s", chrootdir);
if (mount(chrootdir, "/", NULL, MS_MOVE, NULL) == -1)
die("Failed to move %s as rootfs", chrootdir);
if (chroot(".") == -1)
die("Failed to chroot to %s", chrootdir);
/* Switch back to the gid/uid of invoking process */
if (setgid(rgid) == -1)
die("setgid child");
if (setuid(ruid) == -1)
die("setuid child");
if (execvp(cmd, cmdargs) == -1)
die("Failed to execute command %s", cmd);
}
/* Switch back to the gid/uid of invoking process also in the parent */
if (setgid(rgid) == -1)
die("setgid child");
if (setuid(ruid) == -1)
die("setuid child");
/* Wait until the child terminates */
while (waitpid(child, &child_status, 0) < 0) {
if (errno != EINTR)
die("waitpid");
}
if (!WIFEXITED(child_status))
return -1;
return WEXITSTATUS(child_status);
}

View file

@ -0,0 +1,89 @@
#!/bin/bash
#
# Passed arguments:
# $1 - pkgname to build [REQUIRED]
# $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]"
exit 1
fi
PKGNAME="$1"
XBPS_CROSS_BUILD="$2"
. $XBPS_SHUTILSDIR/common.sh
for f in $XBPS_COMMONDIR/helpers/*.sh; do
source_file "$f"
done
setup_pkg "$PKGNAME" $XBPS_CROSS_BUILD
for f in $XBPS_COMMONDIR/environment/build/*.sh; do
source_file "$f"
done
if [ -z $pkgname -o -z $version ]; then
msg_error "$1: pkgname/version not set in pkg template!\n"
exit 1
fi
XBPS_BUILD_DONE="$wrksrc/.xbps_${XBPS_CROSS_BUILD}_build_done"
XBPS_PRE_BUILD_DONE="$wrksrc/.xbps_${XBPS_CROSS_BUILD}_pre_build_done"
XBPS_POST_BUILD_DONE="$wrksrc/.xbps_${XBPS_CROSS_BUILD}_post_build_done"
if [ -f "$XBPS_BUILD_DONE" ]; then
exit 0
fi
cd $wrksrc || msg_error "$pkgver: cannot access wrksrc directory [$wrksrc]\n"
if [ -n "$build_wrksrc" ]; then
cd $build_wrksrc || \
msg_error "$pkgver: cannot access build_wrksrc directory [$build_wrksrc]\n"
fi
run_pkg_hooks pre-build
# Run pre_build()
if [ ! -f $XBPS_PRE_BUILD_DONE ]; then
cd $wrksrc
[ -n "$build_wrksrc" ] && cd $build_wrksrc
if declare -f pre_build >/dev/null; then
run_func pre_build
touch -f $XBPS_PRE_BUILD_DONE
fi
fi
# Run do_build()
cd $wrksrc
[ -n "$build_wrksrc" ] && cd $build_wrksrc
if declare -f do_build >/dev/null; then
run_func do_build
else
if [ -n "$build_style" ]; then
if [ ! -r $XBPS_BUILDSTYLEDIR/${build_style}.sh ]; then
msg_error "$pkgver: cannot find build helper $XBPS_BUILDSTYLEDIR/${build_style}.sh!\n"
fi
. $XBPS_BUILDSTYLEDIR/${build_style}.sh
if declare -f do_build >/dev/null; then
run_func do_build
fi
fi
fi
touch -f $XBPS_BUILD_DONE
# Run post_build()
if [ ! -f $XBPS_POST_BUILD_DONE ]; then
cd $wrksrc
[ -n "$build_wrksrc" ] && cd $build_wrksrc
if declare -f post_build >/dev/null; then
run_func post_build
touch -f $XBPS_POST_BUILD_DONE
fi
fi
run_pkg_hooks post-build
exit 0

View file

@ -0,0 +1,90 @@
#!/bin/bash
#
# Passed arguments:
# $1 - pkgname to configure [REQUIRED]
# $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]"
exit 1
fi
PKGNAME="$1"
XBPS_CROSS_BUILD="$2"
. $XBPS_SHUTILSDIR/common.sh
for f in $XBPS_COMMONDIR/helpers/*.sh; do
source_file "$f"
done
setup_pkg "$PKGNAME" $XBPS_CROSS_BUILD
for f in $XBPS_COMMONDIR/environment/configure/*.sh; do
source_file "$f"
done
XBPS_CONFIGURE_DONE="$wrksrc/.xbps_${XBPS_CROSS_BUILD}_configure_done"
XBPS_PRECONFIGURE_DONE="$wrksrc/.xbps_${XBPS_CROSS_BUILD}_pre_configure_done"
XBPS_POSTCONFIGURE_DONE="$wrksrc/.xbps_${XBPS_CROSS_BUILD}_post_configure_done"
if [ -f "$XBPS_CONFIGURE_DONE" ]; then
exit 0
fi
cd $wrksrc || msg_error "$pkgver: cannot access wrksrc directory [$wrksrc].\n"
if [ -n "$build_wrksrc" ]; then
cd $build_wrksrc || \
msg_error "$pkgver: cannot access build_wrksrc directory [$build_wrksrc].\n"
fi
run_pkg_hooks pre-configure
# Run pre_configure()
if [ ! -f $XBPS_PRECONFIGURE_DONE ]; then
cd $wrksrc
if [ -n "$build_wrksrc" ]; then
cd $build_wrksrc
fi
if declare -f pre_configure >/dev/null; then
run_func pre_configure
touch -f $XBPS_PRECONFIGURE_DONE
fi
fi
# Run do_configure()
cd $wrksrc
if [ -n "$build_wrksrc" ]; then
cd $build_wrksrc
fi
if declare -f do_configure >/dev/null; then
run_func do_configure
else
if [ -n "$build_style" ]; then
if [ ! -r $XBPS_BUILDSTYLEDIR/${build_style}.sh ]; then
msg_error "$pkgver: cannot find build helper $XBPS_BUILDSTYLEDIR/${build_style}.sh!\n"
fi
. $XBPS_BUILDSTYLEDIR/${build_style}.sh
if declare -f do_configure >/dev/null; then
run_func do_configure
fi
fi
fi
touch -f $XBPS_CONFIGURE_DONE
# Run post_configure()
if [ ! -f $XBPS_POSTCONFIGURE_DONE ]; then
cd $wrksrc
if [ -n "$build_wrksrc" ]; then
cd $build_wrksrc
fi
if declare -f post_configure >/dev/null; then
run_func post_configure
touch -f $XBPS_POSTCONFIGURE_DONE
fi
fi
run_pkg_hooks post-configure
exit 0

View file

@ -0,0 +1,61 @@
#!/bin/bash
#
# Passed arguments:
# $1 - pkgname [REQUIRED]
# $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]"
exit 1
fi
PKGNAME="$1"
XBPS_CROSS_BUILD="$2"
. $XBPS_SHUTILSDIR/common.sh
for f in $XBPS_COMMONDIR/helpers/*.sh; do
source_file "$f"
done
setup_pkg "$PKGNAME" $XBPS_CROSS_BUILD
for f in $XBPS_COMMONDIR/environment/extract/*.sh; do
source_file "$f"
done
XBPS_EXTRACT_DONE="$wrksrc/.xbps_extract_done"
if [ -f $XBPS_EXTRACT_DONE ]; then
exit 0
fi
# Run pre-extract hooks
run_pkg_hooks pre-extract
# If template defines pre_extract(), use it.
if declare -f pre_extract >/dev/null; then
run_func pre_extract
fi
# If template defines do_extract() use it rather than the hooks.
if declare -f do_extract >/dev/null; then
[ ! -d "$wrksrc" ] && mkdir -p $wrksrc
cd $wrksrc
run_func do_extract
else
# Run do-extract hooks
run_pkg_hooks "do-extract"
fi
touch -f $XBPS_EXTRACT_DONE
# If template defines post_extract(), use it.
if declare -f post_extract >/dev/null; then
run_func post_extract
fi
# Run post-extract hooks
run_pkg_hooks post-extract
exit 0

View file

@ -0,0 +1,60 @@
#!/bin/bash
#
# Passed arguments:
# $1 - pkgname [REQUIRED]
# $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]"
exit 1
fi
PKGNAME="$1"
XBPS_CROSS_BUILD="$2"
. $XBPS_SHUTILSDIR/common.sh
for f in $XBPS_COMMONDIR/helpers/*.sh; do
source_file "$f"
done
setup_pkg "$PKGNAME" $XBPS_CROSS_BUILD
for f in $XBPS_COMMONDIR/environment/fetch/*.sh; do
source_file "$f"
done
XBPS_FETCH_DONE="$wrksrc/.xbps_fetch_done"
if [ -f "$XBPS_FETCH_DONE" ]; then
exit 0
fi
# Run pre-fetch hooks.
run_pkg_hooks pre-fetch
# If template defines pre_fetch(), use it.
if declare -f pre_fetch >/dev/null; then
run_func pre_fetch
fi
# If template defines do_fetch(), use it rather than the hooks.
if declare -f do_fetch >/dev/null; then
cd ${XBPS_BUILDDIR}
[ -n "$build_wrksrc" ] && mkdir -p "$wrksrc"
run_func do_fetch
touch -f $XBPS_FETCH_DONE
else
# Run do-fetch hooks.
run_pkg_hooks "do-fetch"
fi
# if templates defines post_fetch(), use it.
if declare -f post_fetch >/dev/null; then
run_func post_fetch
fi
# Run post-fetch hooks.
run_pkg_hooks post-fetch
exit 0

View file

@ -0,0 +1,79 @@
#!//bin/bash
#
# Passed arguments:
# $1 - pkgname [REQUIRED]
# $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]"
exit 1
fi
PKGNAME="$1"
XBPS_CROSS_BUILD="$2"
. $XBPS_SHUTILSDIR/common.sh
for f in $XBPS_COMMONDIR/helpers/*.sh; do
source_file "$f"
done
setup_pkg "$PKGNAME" $XBPS_CROSS_BUILD
for f in $XBPS_COMMONDIR/environment/install/*.sh; do
source_file "$f"
done
XBPS_INSTALL_DONE="$wrksrc/.xbps_${pkgname}_${XBPS_CROSS_BUILD}_install_done"
XBPS_PRE_INSTALL_DONE="$wrksrc/.xbps_${pkgname}_${XBPS_CROSS_BUILD}_pre_install_done"
XBPS_POST_INSTALL_DONE="$wrksrc/.xbps_${pkgname}_${XBPS_CROSS_BUILD}_post_install_done"
if [ -f $XBPS_INSTALL_DONE ]; then
exit 0
fi
mkdir -p $XBPS_DESTDIR/$XBPS_CROSS_TRIPLET/$pkgname-$version
cd $wrksrc || msg_error "$pkgver: cannot access to wrksrc [$wrksrc]\n"
if [ -n "$build_wrksrc" ]; then
cd $build_wrksrc \
|| msg_error "$pkgver: cannot access to build_wrksrc [$build_wrksrc]\n"
fi
run_pkg_hooks pre-install
# Run pre_install()
if [ ! -f $XBPS_PRE_INSTALL_DONE ]; then
if declare -f pre_install >/dev/null; then
run_func pre_install
touch -f $XBPS_PRE_INSTALL_DONE
fi
fi
# Run do_install()
if [ ! -f $XBPS_INSTALL_DONE ]; then
cd $wrksrc
[ -n "$build_wrksrc" ] && cd $build_wrksrc
if declare -f do_install >/dev/null; then
run_func do_install
else
if [ ! -r $XBPS_BUILDSTYLEDIR/${build_style}.sh ]; then
msg_error "$pkgver: cannot find build helper $XBPS_BUILDSTYLEDIR/${build_style}.sh!\n"
fi
. $XBPS_BUILDSTYLEDIR/${build_style}.sh
run_func do_install
fi
touch -f $XBPS_INSTALL_DONE
fi
# Run post_install()
if [ ! -f $XBPS_POST_INSTALL_DONE ]; then
cd $wrksrc
[ -n "$build_wrksrc" ] && cd $build_wrksrc
if declare -f post_install >/dev/null; then
run_func post_install
touch -f $XBPS_POST_INSTALL_DONE
fi
fi
exit 0

View file

@ -0,0 +1,62 @@
#!//bin/bash
#
# Passed arguments:
# $1 - pkgname [REQUIRED]
# $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then
echo "$(basename $0): invalid number of arguments: pkgname [cross-target]"
exit 1
fi
PKGNAME="$1"
XBPS_CROSS_BUILD="$2"
. $XBPS_SHUTILSDIR/common.sh
for f in $XBPS_COMMONDIR/helpers/*.sh; do
source_file "$f"
done
setup_pkg "$PKGNAME" $XBPS_CROSS_BUILD
for f in $XBPS_COMMONDIR/environment/install/*.sh; do
source_file "$f"
done
XBPS_PKG_DONE="$wrksrc/.xbps_${PKGNAME}_${XBPS_CROSS_BUILD}_pkg_done"
if [ -f $XBPS_PKG_DONE ]; then
exit 0
fi
#
# Always remove metadata files generated in a previous installation.
#
for f in INSTALL REMOVE files.plist props.plist rdeps shlib-provides shlib-requires; do
[ -f ${PKGDESTDIR}/${f} ] && rm -f ${PKGDESTDIR}/${f}
done
# If it's a subpkg execute the pkg_install() function.
if [ "$sourcepkg" != "$PKGNAME" ]; then
# Source all subpkg environment setup snippets.
for f in ${XBPS_COMMONDIR}/environment/setup-subpkg/*.sh; do
source_file "$f"
done
${PKGNAME}_package
pkgname=$PKGNAME
install -d $PKGDESTDIR
if declare -f pkg_install >/dev/null; then
export XBPS_PKGDESTDIR=1
run_func pkg_install
fi
fi
setup_pkg_depends $pkgname
run_pkg_hooks post-install
touch -f $XBPS_PKG_DONE
exit 0

View file

@ -0,0 +1,52 @@
#!/bin/bash
#
# Passed arguments:
# $1 - pkgname [REQUIRED]
# $2 - path to local repository [REQUIRED]
# $3 - cross-target [OPTIONAL]
if [ $# -lt 2 -o $# -gt 3 ]; then
echo "$(basename $0): invalid number of arguments: pkgname repository [cross-target]"
exit 1
fi
PKGNAME="$1"
XBPS_REPOSITORY="$2"
XBPS_CROSS_BUILD="$3"
. $XBPS_SHUTILSDIR/common.sh
for f in $XBPS_COMMONDIR/helpers/*.sh; do
source_file "$f"
done
setup_pkg "$PKGNAME" $XBPS_CROSS_BUILD
for f in $XBPS_COMMONDIR/environment/pkg/*.sh; do
source_file "$f"
done
if [ "$sourcepkg" != "$PKGNAME" ]; then
# Source all subpkg environment setup snippets.
for f in ${XBPS_COMMONDIR}/environment/setup-subpkg/*.sh; do
source_file "$f"
done
${PKGNAME}_package
pkgname=$PKGNAME
fi
if [ -s $XBPS_MASTERDIR/.xbps_chroot_init ]; then
export XBPS_ARCH=$(cat $XBPS_MASTERDIR/.xbps_chroot_init)
fi
# Run pre-pkg hooks.
run_pkg_hooks pre-pkg
# Run do-pkg hooks.
run_pkg_hooks "do-pkg"
# Run post-pkg hooks.
run_pkg_hooks post-pkg
exit 0