You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.4 KiB

#!/usr/bin/env sh
# Use this script to copy shared (libs) files to a chroot/jail.
# ----------------------------------------------------------------------------
# Written by BrainwreckedTech <http://www.brainwrecked.us>
# (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 <http://www.cyberciti.biz/tips/>
# (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}"