#!/bin/bash test $# -eq 2 || { echo "Usage: $0 "; exit 1; } # No provision for spaces or other weird characters in pathnames. So sue me. CHROOT=$1 INSTDIR=$2 POCODIR=/usr/local/lib test -d "$INSTDIR" || { echo "No such directory: $INSTDIR"; exit 1; } mkdir $CHROOT || exit 1 CHROOT=`cd $CHROOT && /bin/pwd` INSTDIR=`cd $INSTDIR && /bin/pwd` cd / || exit 1 ( # Produce a list of file names, one per line, that will be copied # into the template tree of system files for the chroot jails. if [ `uname -s` = Linux ]; then # First essential files and shared objects find etc/passwd etc/group etc/hosts \ etc/resolv.conf \ lib/ld-* lib64/ld-* \ etc/ld.so.* \ lib/libnss_* lib64/libnss_* \ var/cache/fontconfig \ etc/fonts \ etc/localtime \ usr/lib/locale/en_US.utf8 \ usr/lib/locale/C.UTF-8 \ usr/lib/locale/locale_archive \ usr/share/zoneinfo/* \ usr/share/liblangtag \ lib/*-linux-gnu/libnss* \ -type f find etc/fonts \ lib/libnss_* \ lib64/libnss_* \ lib/*-linux-gnu/libnss* \ -type l find lib/libnss_* lib64/libnss_* -type l find lib/*-linux-gnu/libnss* -type l # Go through the LO shared objects and check what system libraries # they link to. find $INSTDIR -name '*.so' -o -name '*.so.[0-9]*' | while read file; do ldd $file 2>/dev/null done | grep -v dynamic | cut -d " " -f 3 | grep -E '^(/lib|/usr)' | sort -u | sed -e 's,^/,,' # Go through the loolkit find $POCODIR -name '*Poco*.so' -o -name '*.so.[0-9]*' | while read file; do ldd $file 2>/dev/null done | grep -v dynamic | cut -d " " -f 3 | grep -E '^(/lib|/usr)' | sort -u | sed -e 's,^/,,' else find usr/lib/dyld \ usr/lib/*.dylib \ usr/lib/system/*.dylib \ System/Library/Frameworks/Accelerate.framework \ System/Library/Frameworks/ApplicationServices.framework \ System/Library/Frameworks/CFNetwork.framework \ System/Library/Frameworks/Carbon.framework \ System/Library/Frameworks/CoreFoundation.framework \ System/Library/Frameworks/CoreGraphics.framework \ System/Library/Frameworks/CoreServices.framework \ System/Library/Frameworks/CoreText.framework \ System/Library/Frameworks/DiskArbitration.framework \ System/Library/Frameworks/Foundation.framework \ System/Library/Frameworks/ImageIO.framework \ System/Library/Frameworks/IOKit.framework \ System/Library/Frameworks/IOSurface.framework \ System/Library/Frameworks/NetFS.framework \ System/Library/Frameworks/OpenDirectory.framework \ System/Library/Frameworks/Security.framework \ System/Library/Frameworks/SystemConfiguration.framework \ System/Library/PrivateFrameworks/DataDetectorsCore.framework \ System/Library/PrivateFrameworks/MultitouchSupport.framework \ System/Library/PrivateFrameworks/NetAuth.framework \ System/Library/PrivateFrameworks/login.framework \ -type f find $INSTDIR -name '*.dylib' | while read file; do otool -L $file 2>/dev/null done | sed -e 's/^[ ]//' | grep -E '^/(lib|usr/lib)/' | cut -d' ' -f1 | sort -u | sed -e 's,^/,,' fi ) | # Can't use -l because then symlinks won't be handled well enough. # This will now copy the file a symlink points to, but whatever. cpio -p -d -L $CHROOT mkdir -p $CHROOT/tmp mkdir -p $CHROOT/usr/bin/ dummy=$CHROOT/usr/bin/dummy # checking for library containing Poco::Application cat <<_ACEOF >$dummy.cpp #include #include using Poco::Util::Application; int main () { std::cout << "Poco functionality OK!" << std::endl; return Application::EXIT_OK; } _ACEOF gcc_compile='g++ -o $dummy.o -c $dummy.cpp' (eval "$gcc_compile") 2>$dummy.err if ! test $? = 0; then cat $dummy.err; exit 1; fi gcc_link='g++ -o $dummy -lcap -lpng -ldl -lPocoNet -lPocoUtil -lPocoXML -lPocoJSON -lPocoFoundation $dummy.o' (eval "$gcc_link") 2>$dummy.err if ! test $? = 0; then cat $dummy.err; exit 1; fi lib_poco=$( echo "$dummy" | while read file; do ldd $file 2>/dev/null done | grep -v dynamic | cut -d " " -f 3 | grep -E '^(/lib|/usr)') for lib in $lib_poco do cp --parent -n $lib $CHROOT libs=$( echo $lib | while read file; do ldd $file 2>/dev/null done | grep -v dynamic | cut -d " " -f 3 | grep -E '^(/lib|/usr)') for sofile in $libs do cp --parent -n $sofile $CHROOT done done loaders="$(find /lib/ld-* -type l) $(find /lib32/ld-* -type l) $(find /lib64/ld-* -type l)" for loader in $loaders do cp --parent -n $loader $CHROOT done # /usr/share/fonts needs to be taken care of separately because the # directory time stamps must be preserved are for fontconfig to trust # its cache. cd $CHROOT || exit 1 if [ `uname -s` = Linux ]; then mkdir -p usr/share || exit 1 cp -r -p /usr/share/fonts usr/share if [ -h usr/share/fonts/ghostscript ]; then mkdir usr/share/ghostscript || exit 1 cp -r -p /usr/share/ghostscript/fonts usr/share/ghostscript fi fi echo "testing if Poco libraries were installed properly" sudo chroot $CHROOT /usr/bin/dummy