Last active
February 26, 2019 12:51
-
-
Save FredNandrin/2aa12c1d03d51dd5bcf9ae90dd61fa8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# copy necessary lib for system command from root to chrooted directory | |
# | |
# Frédéric Nandrin - NanIT 2019 - fred@nanit.be | |
# Tested on Debian 9 | |
# | |
# USAGE : chrootcmd <chrooted dir> <cmd> | |
# ex : chrootcmd /home/fred /bin/ls | |
# | |
CHROOT=$1 | |
mkdir $CHROOT -p | |
cp $2 $1$2 | |
for i in $( ldd $2 | grep -v dynamic | cut -d " " -f 3 | sed 's/://' | sort | uniq ) | |
do | |
cp --parents $i $CHROOT | |
done | |
# ARCH amd64 | |
if [ -f /lib64/ld-linux-x86-64.so.2 ]; then | |
cp --parents /lib64/ld-linux-x86-64.so.2 /$CHROOT | |
fi | |
# ARCH i386 | |
if [ -f /lib/ld-linux.so.2 ]; then | |
cp --parents /lib/ld-linux.so.2 /$CHROOT | |
fi | |
echo "Command $2 has been prepared in chrooted dir $1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment