#!/usr/bin/env sh # Use this script to copy shared (libs) files to a chroot/jail. # ---------------------------------------------------------------------------- # Written by BrainwreckedTech # (c) 2014 BrainwreckedTech under GNU GPL v2.0+ # + Changed script to die if chroot/jail dir doesn't exist # + Changed chroot/jail dir to be specified on command line # + Added copying of binary to chroot/jail # ---------------------------------------------------------------------------- # Orginally written by nixCraft # (c) 2006 nixCraft under GNU GPL v2.0+ # + Added ld-linux support # + Added error checking support # ------------------------------------------------------------------------------- print_help () { echo " Syntax: $0 /path/to/jail /path/to/executable" echo "Example: $0 /srv/jail/backup /usr/bin/rsync" } [ ! -d "${1}" ] && echo "${1} does not exist" && print_help && exit 1 [ ! -f "${2}" ] && echo "${2} does not exist" && print_help && exit 2 cp -v "${2}" "${1}${2}" while read -r FILE; do FDIR="$(dirname "${FILE}")" [ ! -d "${1}${FDIR}" ] && mkdir -p "${1}${FDIR}" cp -v "${FILE}" "${1}${FDIR}" done < "$(ldd "${2}" | awk '{ print $3 }' | egrep -v ^'\(')" SLDL="$(ldd "${2}" | grep 'ld-linux' | awk '{ print $1}')" SDIR="$(dirname "${SLDL}")" [ ! -f "${1}${SLDL}" ] && cp -v "${SLDL}" "${1}${SDIR}"