chrootDir="/home"
copyToJail="/bin/ls /bin/ping /bin/time /bin/alias /usr/bin/which /bin/top /bin/ps /bin/vi /bin/vim /bin/nano /bin/openssl /etc/bashrc /etc/hostname /etc/profile.d /etc/profile /bin/bash /bin/env /bin/tail /bin/cat /bin/tail /bin/more"
copyToJail="$copyToJail /bin/head"
for eachCommand in $(echo $copyToJail); do
execDir=$(echo $eachCommand |xargs dirname)
if [ ! -d "$chrootDir$execDir" ]; then
mkdir -p $chrootDir$execDir
fi
#eachCommand has a / at the beggining
if [ ! -e "$chrootDir$eachCommand" ]; then
cp -r --preserve=all $eachCommand $chrootDir$execDir
fi
ldd $eachCommand 1>>/dev/null 2>>/dev/null
if [ $? -eq 0 ]; then
for depFile in $(ldd $eachCommand 2>>/dev/null | cut -d '>' -f2 | cut -d '(' -f1 | grep -v -e '^[[:space:]]*$'); do
fileDir=$(echo $depFile |xargs dirname)
if [ ! -d "$chrootDir$fileDir" ]; then
mkdir -p $chrootDir$fileDir
fi
#fileDir has a / at the beggining
if [ ! -e "$chrootDir$depFile" ]; then
cp --preserve=all $depFile $chrootDir$fileDir/
fi
done
fi
done