Skip to content

Instantly share code, notes, and snippets.

@afresh1
Last active December 22, 2021 22:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afresh1/daf96f561db05be705ed9a9e2982e4bf to your computer and use it in GitHub Desktop.
Save afresh1/daf96f561db05be705ed9a9e2982e4bf to your computer and use it in GitHub Desktop.
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