I'm about to introduce tests that need to run as root (like mount.tests),
meaning we want to run them in a chroot environment. To help with this, I worked out a utility function that makes it really easy to set up a chroot environment.
This commit is contained in:
parent
31e3610c4b
commit
3a324754f8
@ -58,7 +58,7 @@ testing ()
|
|||||||
{
|
{
|
||||||
if [ $# -ne 5 ]
|
if [ $# -ne 5 ]
|
||||||
then
|
then
|
||||||
echo "Test $1 has the wrong number of arguments" >&2
|
echo "Test $1 has the wrong number of arguments ($# $*)" >&2
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ testing ()
|
|||||||
|
|
||||||
echo -ne "$3" > expected
|
echo -ne "$3" > expected
|
||||||
echo -ne "$4" > input
|
echo -ne "$4" > input
|
||||||
echo -n -e "$5" | eval "$COMMAND $2" > actual
|
echo -ne "$5" | eval "$COMMAND $2" > actual
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
|
|
||||||
cmp expected actual > /dev/null
|
cmp expected actual > /dev/null
|
||||||
@ -98,3 +98,30 @@ testing ()
|
|||||||
|
|
||||||
return $RETVAL
|
return $RETVAL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Recursively grab an executable and all the libraries needed to run it.
|
||||||
|
# Source paths beginning with / will be copied into destpath, otherwise
|
||||||
|
# the file is assumed to already be there and only its library dependencies
|
||||||
|
# are copied.
|
||||||
|
|
||||||
|
function mkchroot
|
||||||
|
{
|
||||||
|
[ $# -lt 2 ] && return
|
||||||
|
|
||||||
|
dest=$1
|
||||||
|
shift
|
||||||
|
for i in "$@"
|
||||||
|
do
|
||||||
|
if [ "${i:0:1}" == "/" ]
|
||||||
|
then
|
||||||
|
[ -f "$dest/$i" ] && continue
|
||||||
|
d=`echo "$i" | grep -o '.*/'` &&
|
||||||
|
mkdir -p "$dest/$d" &&
|
||||||
|
cat "$i" > "$dest/$i" &&
|
||||||
|
chmod +x "$dest/$i"
|
||||||
|
else
|
||||||
|
i="$dest/$i"
|
||||||
|
fi
|
||||||
|
mkchroot "$dest" $(ldd "$i" | egrep -o '/.* ')
|
||||||
|
done
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user