Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CHROOT=/var/www/vhosts/chroot/
- CHROOTMNG=/usr/local/psa/admin/sbin/chrootmng
- # check configuration
- if [ ! -d "${CHROOT}" ]
- then
- echo "Error: chroot does not exist, check configuration."
- exit 1
- fi
- if [ ! -f "${CHROOTMNG}" ]
- then
- echo "Error: chrootmng not found, check configuration."
- exit 1
- fi
- # make sure binary is given
- if [ -z "$1" ]
- then
- echo "usage: $(basename $0) <program> [target]"
- exit 1
- fi
- # check for target specification
- if [ -n "$2" ]
- then
- TARGET=$2
- if [ ! -d "${TARGET}" ]
- then
- echo "Error: not a valid target."
- exit 1
- fi
- else
- TARGET=${CHROOT}
- fi
- # check whether path or name of binary was given
- if [ -f "$1" ]
- then
- BINARY=$1
- else
- BINARY=$(which $1)
- fi
- # make sure binary exists
- if [ ! -f "${BINARY}" ]
- then
- echo "Error: Could not find binary."
- exit 1
- fi
- # status
- echo "Binary: ${BINARY}"
- echo "Target: ${TARGET}"
- # there is no specific target, remove all current chroot environments,
- # modify the skeleton, and recreate them
- if [ -z "$2" ]
- then
- echo "Removing current chroot environments..."
- ${CHROOTMNG} --remove --source=${CHROOT} --target=all
- fi
- # copy the binary
- echo "Adding binary to chroot..."
- echo " ${BINARY}"
- cp -p ${BINARY} ${TARGET}/${BINARY}
- # copy necessary shared libraries
- echo "Adding shared libraries to chroot..."
- ldd ${BINARY} | sed -e "s/\S* => //" | awk '{print $1}' | while read LIB
- do
- if [ -f "${LIB}" ]
- then
- echo " ${LIB}"
- cp -p ${LIB} ${TARGET}/${LIB}
- fi
- done
- # if the target is all, recreate all chroot environments
- if [ -z "$2" ]
- then
- echo "Recreating chroot environments..."
- ${CHROOTMNG} --create --source=${CHROOT} --target=all
- fi
- # binary added
- echo "Done."
Advertisement
Add Comment
Please, Sign In to add comment