Skip to content

Instantly share code, notes, and snippets.

@afresh1
Last active Jun 7, 2020
Embed
What would you like to do?
fill-chroot - Add files and their needed libs to a chroot directory
#!/bin/sh
chroot=/var/www # ${PWD}
copy_recurse() {
file=$1
[ -e "${chroot}${file}" ] && return
mkdir -p $( dirname "${chroot}${file}" )
cp -p "$file" "${chroot}${file}"
ldd "$file" 2>/dev/null | sed -e 's,^[^/]*,,' | while read f; do
[ -e "$f" ] && copy_recurse "$f"
done
}
for file in "$@"; do
copy_recurse "$file"
done
if [ -e "${chroot}/usr/libexec/ld.so" ]; then
mkdir -p "${chroot}/var/run"
LD_PATH=$( find "${chroot}"/usr -name '*.so.*' | while read f; do
dirname ${f#${chroot}}
done | sort -u )
if [ -n "${LD_PATH}" ]; then
cp /sbin/ldconfig "${chroot}/ldconfig"
chroot "${chroot}" /ldconfig ${LD_PATH}
rm -f "${chroot}/ldconfig"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment