testing: Run commands in chroot in a login shell

Similar to the previous commit, this ensures we have the same environment
we do later on the system.
This commit is contained in:
Tobias Brunner 2025-08-15 14:36:45 +02:00
parent 870aa75eed
commit ddeb3c463e

View File

@ -48,9 +48,23 @@ execute()
# execute command in chroot
# $1 - command to execute
# $2 - whether or not to log command exit status
# (0 -> disable exit status logging)
execute_chroot()
{
execute "chroot $LOOPDIR env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin $@"
cmd=${1}
echo chroot $LOOPDIR $cmd >>$LOGFILE 2>&1
chroot $LOOPDIR /bin/bash -l <<-EOF >>$LOGFILE 2>&1
$cmd
EOF
status=$?
[ "$2" != 0 ] && log_status $status
if [ $status != 0 ]; then
echo
echo "! Command chroot $LOOPDIR $cmd failed, exiting (status $status)"
echo "! Check why here $LOGFILE"
exit 1
fi
}
# write green status message to console