Any program to chroot (apache) PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Bart Dorlandt   
Monday, 21 April 2008 17:37

I've written a script to copy any program to the chrooted environment of apache with its libraries. Just load the script and use the full path as the first parameter.

Example. If you call the script program_to_chroot.sh

./program_to_chroot.sh /usr/local/bin/ffmpeg

This will copy any relevant library + the ffmpeg file itself to the correspondig directories in /var/www.

#!/bin/sh
PROGRAM=$1

if [ ! -d /var/www/usr/local/bin ]; then mkdir -p /var/www/usr/local/bin ;fi
if [ ! -d /var/www/usr/local/lib ]; then mkdir -p /var/www/usr/local/lib ;fi
if [ ! -d /var/www/usr/libexec ];   then mkdir -p /var/www/usr/libexec; fi
if [ ! -d /var/www/usr/lib ];       then mkdir -p /var/www/usr/lib ;fi
if [ ! -d /var/www/usr/bin ];       then mkdir -p /var/www/usr/bin ;fi
if [ ! -d /var/www/usr/X11R6/lib ]; then mkdir -p /var/www/usr/X11R6/lib ;fi

LOCALBIN=`ldd $PROGRAM | grep -v : | grep usr | awk '{print $7}' | grep bin | grep local`
BIN=`ldd $PROGRAM | grep -v : | grep usr | awk '{print $7}' | grep bin | grep -v local`
LOCALLIB=`ldd $PROGRAM | grep -v : | grep usr | awk '{print $7}' | grep local | grep -v libexec | grep lib`
LIB=`ldd $PROGRAM | grep -v : | grep usr | awk '{print $7}' | grep -v local | grep -v libexec | grep lib`
LIBEXEC=`ldd $PROGRAM | grep -v : | grep usr | awk '{print $7}' | grep libexec`
X11R6LIB=`ldd $PROGRAM | grep -v : | grep usr | awk '{print $7}' | grep X11R6 | grep lib | grep -v bin`

for x in $LOCALBIN $BIN
do
if [ ! -x /var/www${x} ]; then
cp -p $x /var/www${x}
echo Copied $x
else
echo /var/www$x already executable
fi
done

for x in $LOCALLIB $LIB $LIBEXEC $X11R6LIB
do
if [ ! -r /var/www${x} ]; then
cp -p $x /var/www${x}
echo Copied $x
else
echo /var/www$x already readable
fi
done

Last Updated on Friday, 13 February 2009 15:26
 


Related items: