<commit_before>#-
# Copyright (c) 2008-2010 <NAME>.
# 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.
#

# Umount stuff if SIGINT or SIGQUIT was caught
trap umount_chroot_fs INT QUIT

[ -n "$base_chroot" ] && return 0

. $XBPS_SHUTILSDIR/builddep_funcs.sh
check_installed_pkg xbps-base-chroot-0.11
if [ $? -ne 0 ]; then
	echo "The '$pkgname' package requires to be installed in a chroot."
	echo "Please install 'xbps-base-chroot>=0.11' and try again."
	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

XBPSSRC_CF=$XBPS_MASTERDIR/usr/local/etc/xbps-src.conf

echo "XBPS_DISTRIBUTIONDIR=/xbps" > $XBPSSRC_CF
echo "XBPS_MASTERDIR=/" >> $XBPSSRC_CF
echo "XBPS_PACKAGESDIR=/xbps_packagesdir" >> $XBPSSRC_CF
echo "XBPS_BUILDDIR=/xbps_builddir" >> $XBPSSRC_CF
echo "XBPS_SRCDISTDIR=/xbps_srcdistdir" >> $XBPSSRC_CF
echo "XBPS_CFLAGS=\"$XBPS_CFLAGS\"" >> $XBPSSRC_CF
echo "XBPS_CXXFLAGS=\"\$XBPS_CFLAGS\"" >> $XBPSSRC_CF
echo "XBPS_FETCH_CMD='xbps-uhelper.static fetch'" >> $XBPSSRC_CF
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

prepare_chroot()
{
	local f=

	# Create some required files.
	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

	cat > $XBPS_MASTERDIR/etc/passwd <<_EOF
root:x:0:0:root:/root:/bin/bash
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
_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:
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:
users:x:1000:
_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
fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b ip6-localnet
fdf8:f53e:61e4::18 ip6-mcastprefix
fc00:db20:35b:7399::5 ip6-allnodes
fc00:db20:35b:7399::5 ip6-allrouters
fdf8:f53e:61e4::18 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<commit_msg>shutils/chroot: sync groups list with shadow pkg.<commit_after>#-
# Copyright (c) 2008-2010 <NAME>.
# 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.
#

# Umount stuff if SIGINT or SIGQUIT was caught
trap umount_chroot_fs INT QUIT

[ -n "$base_chroot" ] && return 0

. $XBPS_SHUTILSDIR/builddep_funcs.sh
check_installed_pkg xbps-base-chroot-0.11
if [ $? -ne 0 ]; then
	echo "The '$pkgname' package requires to be installed in a chroot."
	echo "Please install 'xbps-base-chroot>=0.11' and try again."
	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

XBPSSRC_CF=$XBPS_MASTERDIR/usr/local/etc/xbps-src.conf

echo "XBPS_DISTRIBUTIONDIR=/xbps" > $XBPSSRC_CF
echo "XBPS_MASTERDIR=/" >> $XBPSSRC_CF
echo "XBPS_PACKAGESDIR=/xbps_packagesdir" >> $XBPSSRC_CF
echo "XBPS_BUILDDIR=/xbps_builddir" >> $XBPSSRC_CF
echo "XBPS_SRCDISTDIR=/xbps_srcdistdir" >> $XBPSSRC_CF
echo "XBPS_CFLAGS=\"$XBPS_CFLAGS\"" >> $XBPSSRC_CF
echo "XBPS_CXXFLAGS=\"\$XBPS_CFLAGS\"" >> $XBPSSRC_CF
echo "XBPS_FETCH_CMD='xbps-uhelper.static fetch'" >> $XBPSSRC_CF
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

prepare_chroot()
{
	local f=

	# Create some required files.
	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

	cat > $XBPS_MASTERDIR/etc/passwd <<_EOF
root:x:0:0:root:/root:/bin/bash
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
_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:
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:
nogroup:x:99:
users:x:1000:
_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
fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b ip6-localnet
fdf8:f53e:61e4::18 ip6-mcastprefix
fc00:db20:35b:7399::5 ip6-allnodes
fc00:db20:35b:7399::5 ip6-allrouters
fdf8:f53e:61e4::18 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
{'fraction_non_alphanumeric': 0.10973181871413515, 'fraction_numerical': 0.03325916383651482, 'mean_word_length': 4.877494838265657, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2854721', 'n_tokens_mistral': 3583, 'n_tokens_neox': 3295, 'n_words': 961}