2014-04-09 16:40:27 +02:00
|
|
|
# vim: set ts=4 sw=4 et:
|
2014-03-22 12:31:42 +01:00
|
|
|
|
|
|
|
chroot_init() {
|
2014-04-09 16:40:27 +02:00
|
|
|
XBPSSRC_CF=$XBPS_MASTERDIR/etc/xbps/xbps-src.conf
|
2014-03-22 12:31:42 +01:00
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
cat > $XBPSSRC_CF <<_EOF
|
2014-03-22 12:31:42 +01:00
|
|
|
# Generated configuration file by xbps-src, DO NOT EDIT!
|
2014-07-05 16:12:14 +02:00
|
|
|
_EOF
|
|
|
|
if [ -e "$XBPS_CONFIG_FILE" ]; then
|
|
|
|
grep -E '^XBPS_.*' $XBPS_CONFIG_FILE >> $XBPSSRC_CF
|
|
|
|
fi
|
|
|
|
cat >> $XBPSSRC_CF <<_EOF
|
2014-03-22 12:31:42 +01:00
|
|
|
XBPS_MASTERDIR=/
|
|
|
|
XBPS_CFLAGS="$XBPS_CFLAGS"
|
|
|
|
XBPS_CXXFLAGS="$XBPS_CXXFLAGS"
|
|
|
|
XBPS_CPPFLAGS="$XBPS_CPPFLAGS"
|
|
|
|
XBPS_LDFLAGS="$XBPS_LDFLAGS"
|
2014-06-30 12:03:56 +02:00
|
|
|
XBPS_HOSTDIR=/host
|
2014-03-22 12:31:42 +01:00
|
|
|
_EOF
|
2014-04-09 16:40:27 +02:00
|
|
|
|
|
|
|
echo "# End of configuration file." >> $XBPSSRC_CF
|
|
|
|
|
|
|
|
# Create custom script to start the chroot bash shell.
|
|
|
|
cat > $XBPS_MASTERDIR/bin/xbps-shell <<_EOF
|
2014-03-22 12:31:42 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
XBPS_SRC_VERSION="$XBPS_SRC_VERSION"
|
|
|
|
|
|
|
|
. /etc/xbps/xbps-src.conf
|
|
|
|
|
2014-03-22 13:21:04 +01:00
|
|
|
PATH=/xbps-packages:/usr/bin:/usr/sbin
|
2014-03-22 12:31:42 +01:00
|
|
|
|
|
|
|
exec env -i PATH="\$PATH" DISTCC_HOSTS="\$XBPS_DISTCC_HOSTS" DISTCC_DIR="/distcc" @@XARCH@@ \
|
2014-04-09 16:40:27 +02:00
|
|
|
CCACHE_DIR="/ccache" IN_CHROOT=1 LANG=en_US.UTF-8 TERM=linux HOME="/tmp" \
|
|
|
|
PS1="[\u@$XBPS_MASTERDIR \W]$ " /bin/bash +h
|
2014-03-22 12:31:42 +01:00
|
|
|
_EOF
|
2014-04-09 16:40:27 +02:00
|
|
|
if [ -n "$XBPS_ARCH" ]; then
|
|
|
|
sed -e "s,@@XARCH@@,XBPS_ARCH=${XBPS_ARCH},g" -i $XBPS_MASTERDIR/bin/xbps-shell
|
|
|
|
else
|
|
|
|
sed -e 's,@@XARCH@@,,g' -i $XBPS_MASTERDIR/bin/xbps-shell
|
|
|
|
fi
|
|
|
|
chmod 755 $XBPS_MASTERDIR/bin/xbps-shell
|
|
|
|
|
|
|
|
cp -f /etc/resolv.conf $XBPS_MASTERDIR/etc
|
|
|
|
|
|
|
|
# Update xbps alternative repository if set.
|
2014-06-06 16:10:42 +02:00
|
|
|
mkdir -p $XBPS_MASTERDIR/etc/xbps/repo.d
|
2014-04-09 16:40:27 +02:00
|
|
|
if [ -n "$XBPS_ALT_REPOSITORY" ]; then
|
|
|
|
( \
|
|
|
|
echo "repository=/host/binpkgs/${XBPS_ALT_REPOSITORY}"; \
|
|
|
|
echo "repository=/host/binpkgs/${XBPS_ALT_REPOSITORY}/nonfree"; \
|
2014-06-06 16:10:42 +02:00
|
|
|
) > $XBPS_MASTERDIR/etc/xbps/repo.d/00-alternative.conf
|
2014-04-09 16:40:27 +02:00
|
|
|
else
|
2014-06-06 16:10:42 +02:00
|
|
|
rm -f $XBPS_MASTERDIR/etc/xbps/repo.d/00-alternative.conf
|
2014-04-09 16:40:27 +02:00
|
|
|
fi
|
2014-07-01 15:06:47 +02:00
|
|
|
|
|
|
|
if [ -d $XBPS_MASTERDIR/tmp ]; then
|
|
|
|
rm -rf $XBPS_MASTERDIR/tmp
|
|
|
|
mkdir -p $XBPS_MASTERDIR/tmp
|
|
|
|
fi
|
2014-03-22 12:31:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
chroot_prepare() {
|
2014-04-09 16:40:27 +02:00
|
|
|
local f=
|
2014-03-22 12:31:42 +01:00
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
if [ -f $XBPS_MASTERDIR/.xbps_chroot_init ]; then
|
|
|
|
return 0
|
|
|
|
elif [ ! -f $XBPS_MASTERDIR/bin/bash ]; then
|
|
|
|
msg_error "Bootstrap not installed in $XBPS_MASTERDIR, can't continue.\n"
|
|
|
|
fi
|
2014-03-22 12:31:42 +01:00
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
# Create some required files.
|
|
|
|
cp -f /etc/services $XBPS_MASTERDIR/etc
|
|
|
|
[ -f /etc/localtime ] && cp -f /etc/localtime $XBPS_MASTERDIR/etc
|
2014-03-22 12:31:42 +01:00
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
for f in dev sys proc host boot; do
|
|
|
|
[ ! -d $XBPS_MASTERDIR/$f ] && mkdir -p $XBPS_MASTERDIR/$f
|
|
|
|
done
|
2014-03-22 12:31:42 +01:00
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
# Copy /etc/passwd and /etc/group from base-files.
|
|
|
|
cp -f $XBPS_SRCPKGDIR/base-files/files/passwd $XBPS_MASTERDIR/etc
|
|
|
|
echo "$(whoami):x:$(id -u):$(id -g):$(whoami) user:/tmp:/bin/xbps-shell" \
|
|
|
|
>> $XBPS_MASTERDIR/etc/passwd
|
|
|
|
cp -f $XBPS_SRCPKGDIR/base-files/files/group $XBPS_MASTERDIR/etc
|
|
|
|
echo "$(whoami):x:$(id -g):" >> $XBPS_MASTERDIR/etc/group
|
2014-03-22 12:31:42 +01:00
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
# Copy /etc/hosts from base-files.
|
|
|
|
cp -f $XBPS_SRCPKGDIR/base-files/files/hosts $XBPS_MASTERDIR/etc
|
2014-03-22 12:31:42 +01:00
|
|
|
|
2014-06-06 16:10:42 +02:00
|
|
|
echo "syslog=false" >> $XBPS_MASTERDIR/etc/xbps/xbps.conf
|
2014-06-07 05:52:42 +02:00
|
|
|
echo "cachedir=/host/repocache" >> $XBPS_MASTERDIR/etc/xbps/xbps.conf
|
2014-06-06 16:10:42 +02:00
|
|
|
rm -f $XBPS_MASTERDIR/usr/share/xbps/repo.d/*.conf
|
2014-03-22 12:31:42 +01:00
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
# Prepare default locale: en_US.UTF-8.
|
|
|
|
if [ -s ${XBPS_MASTERDIR}/etc/default/libc-locales ]; then
|
|
|
|
echo 'en_US.UTF-8 UTF-8' >> ${XBPS_MASTERDIR}/etc/default/libc-locales
|
|
|
|
$XBPS_RECONFIGURE_CMD -f glibc-locales
|
|
|
|
fi
|
2014-03-22 12:31:42 +01:00
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
touch -f $XBPS_MASTERDIR/.xbps_chroot_init
|
|
|
|
[ -n "$1" ] && echo $1 >> $XBPS_MASTERDIR/.xbps_chroot_init
|
2014-03-22 12:31:42 +01:00
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
return 0
|
2014-03-22 12:31:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
chroot_sync_repos() {
|
2014-04-09 16:40:27 +02:00
|
|
|
local f=
|
|
|
|
|
|
|
|
# Copy xbps configuration files to the masterdir.
|
2014-05-05 10:56:00 +02:00
|
|
|
install -Dm644 ${XBPS_COMMONDIR}/xbps-src/chroot/repos-local.conf \
|
2014-06-06 16:10:42 +02:00
|
|
|
${XBPS_MASTERDIR}/etc/xbps/repo.d/10-local.conf
|
2014-05-05 10:56:00 +02:00
|
|
|
install -Dm644 ${XBPS_COMMONDIR}/xbps-src/chroot/repos-remote.conf \
|
2014-06-06 16:10:42 +02:00
|
|
|
${XBPS_MASTERDIR}/etc/xbps/repo.d/20-remote.conf
|
2014-04-09 16:40:27 +02:00
|
|
|
|
2014-06-10 09:22:18 +02:00
|
|
|
if [ "$XBPS_MACHINE" = "x86_64" ]; then
|
|
|
|
install -Dm644 ${XBPS_COMMONDIR}/xbps-src/chroot/repos-local-x86_64.conf \
|
|
|
|
${XBPS_MASTERDIR}/etc/xbps/repo.d/12-local-x86_64.conf
|
|
|
|
install -Dm644 ${XBPS_COMMONDIR}/xbps-src/chroot/repos-remote-x86_64.conf \
|
|
|
|
${XBPS_MASTERDIR}/etc/xbps/repo.d/22-remote-x86_64.conf
|
|
|
|
fi
|
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
# if -N is set, comment out remote repositories from xbps.conf.
|
|
|
|
if [ -n "$XBPS_SKIP_REMOTEREPOS" ]; then
|
2014-06-06 16:10:42 +02:00
|
|
|
rm -f ${XBPS_MASTERDIR}/etc/xbps/repo.d/20-remote.conf
|
2014-06-10 09:22:18 +02:00
|
|
|
rm -f ${XBPS_MASTERDIR}/etc/xbps/repo.d/22-remote-x86_64.conf
|
2014-04-09 16:40:27 +02:00
|
|
|
fi
|
|
|
|
|
2014-06-06 16:29:50 +02:00
|
|
|
# Copy host repos to the cross root.
|
|
|
|
if [ -n "$XBPS_CROSS_BUILD" ]; then
|
|
|
|
rm -rf $XBPS_MASTERDIR/usr/$XBPS_CROSS_TRIPLET/etc/xbps/repo.d
|
|
|
|
mkdir -p $XBPS_MASTERDIR/usr/$XBPS_CROSS_TRIPLET/etc/xbps/repo.d
|
|
|
|
cp ${XBPS_MASTERDIR}/etc/xbps/repo.d/*.conf \
|
|
|
|
$XBPS_MASTERDIR/usr/$XBPS_CROSS_TRIPLET/etc/xbps/repo.d
|
2014-06-10 09:36:58 +02:00
|
|
|
rm -f $XBPS_MASTERDIR/usr/$XBPS_CROSS_TRIPLET/etc/xbps/repo.d/*-x86_64.conf
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Make sure to sync index for remote repositories.
|
|
|
|
$CHROOT_CMD $XBPS_MASTERDIR /usr/sbin/xbps-install -S
|
|
|
|
if [ -n "$XBPS_CROSS_BUILD" ]; then
|
|
|
|
# Copy host keys to the target rootdir.
|
|
|
|
if [ ! -d $XBPS_MASTERDIR/usr/$XBPS_CROSS_TRIPLET/var/db/xbps/keys ]; then
|
|
|
|
mkdir -p $XBPS_MASTERDIR/usr/$XBPS_CROSS_TRIPLET/var/db/xbps/keys
|
|
|
|
fi
|
|
|
|
cp -a $XBPS_MASTERDIR/var/db/xbps/keys/*.plist \
|
|
|
|
$XBPS_MASTERDIR/usr/$XBPS_CROSS_TRIPLET/var/db/xbps/keys
|
|
|
|
env XBPS_TARGET_ARCH=$XBPS_TARGET_ARCH \
|
|
|
|
$CHROOT_CMD $XBPS_MASTERDIR /usr/sbin/xbps-install \
|
|
|
|
-r /usr/$XBPS_CROSS_TRIPLET -S
|
2014-06-06 16:29:50 +02:00
|
|
|
fi
|
|
|
|
|
2014-04-09 16:40:27 +02:00
|
|
|
return 0
|
2014-03-22 12:31:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
chroot_handler() {
|
2014-04-09 16:40:27 +02:00
|
|
|
local action="$1" pkg="$2" rv=0 arg= _envargs= _chargs=
|
|
|
|
|
|
|
|
# Debian uses /run/shm instead...
|
|
|
|
if [ -d /run/shm ]; then
|
|
|
|
mkdir -p ${XBPS_MASTERDIR}/run/shm
|
|
|
|
_chargs+=" -S /run/shm"
|
|
|
|
elif [ -d /dev/shm ]; then
|
|
|
|
mkdir -p ${XBPS_MASTERDIR}/dev/shm
|
|
|
|
_chargs+=" -S /dev/shm"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$XBPS_HOSTDIR" ]; then
|
|
|
|
_chargs+=" -H $XBPS_HOSTDIR"
|
|
|
|
fi
|
|
|
|
if [ ! -d $XBPS_MASTERDIR/xbps-packages ]; then
|
|
|
|
mkdir -p $XBPS_MASTERDIR/xbps-packages
|
|
|
|
fi
|
|
|
|
_chargs+=" -D ${XBPS_DISTDIR}"
|
|
|
|
|
|
|
|
[ -z "$action" -a -z "$pkg" ] && return 1
|
|
|
|
|
|
|
|
case "$action" in
|
|
|
|
fetch|extract|build|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
|
|
|
|
chroot_prepare || return $?
|
|
|
|
chroot_init || return $?
|
|
|
|
chroot_sync_repos || return $?
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "$action" = "chroot" ]; then
|
|
|
|
$CHROOT_CMD ${_chargs} $XBPS_MASTERDIR /bin/xbps-shell || rv=$?
|
|
|
|
else
|
2014-07-01 11:04:34 +02:00
|
|
|
[ -n "$XBPS_CROSS_BUILD" ] && arg="$arg -a $XBPS_CROSS_BUILD"
|
|
|
|
[ -n "$XBPS_KEEP_ALL" ] && arg="$arg -C"
|
|
|
|
[ -n "$NOCOLORS" ] && arg="$arg -L"
|
|
|
|
[ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
|
|
|
|
[ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
|
|
|
|
[ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
|
|
|
|
[ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
|
|
|
|
[ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
|
|
|
|
[ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"
|
|
|
|
|
|
|
|
action="$arg $action"
|
2014-04-14 19:58:32 +02:00
|
|
|
env -i PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH HOME=/tmp IN_CHROOT=1 LANG=en_US.UTF-8 \
|
2014-04-09 16:40:27 +02:00
|
|
|
$CHROOT_CMD ${_chargs} $XBPS_MASTERDIR /xbps-packages/xbps-src $action $pkg || rv=$?
|
|
|
|
fi
|
|
|
|
|
|
|
|
return $rv
|
2014-03-22 12:31:42 +01:00
|
|
|
}
|