books/apitue/sample-code/13/mkchroot

19 lines
505 B
Plaintext
Raw Permalink Normal View History

2024-01-20 14:39:54 +00:00
CHROOT="/var/chroot/apue"
FILES="/bin/sh /bin/ps /usr/bin/id"
rm -fr ${CHROOT}
mkdir -p ${CHROOT}/libexec ${CHROOT}/usr/libexec
cp /libexec/ld.elf_so ${CHROOT}/libexec
ln /libexec/ld.elf_so ${CHROOT}/usr/libexec/ld.elf_so
for f in ${FILES}; do
mkdir -p ${CHROOT}${f%/*}
for lib in $(ldd ${f} | sed -n -e 's/.*> //p'); do
mkdir -p ${CHROOT}${lib%/*}
test -f ${CHROOT}${lib} || cp ${lib} ${CHROOT}${lib}
done
cp "${f}" ${CHROOT}/bin/
done