Skip to content

Instantly share code, notes, and snippets.

@xmonader
Forked from muhamadazmy/copy-chroot.sh
Created August 6, 2018 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xmonader/5d1fc6134f1f65acd0d10f71453adb27 to your computer and use it in GitHub Desktop.
Save xmonader/5d1fc6134f1f65acd0d10f71453adb27 to your computer and use it in GitHub Desktop.
Copy binaries to a chroot
#!/bin/bash
if [ $# != 2 ] ; then
echo "usage $0 PATH_TO_BINARY TARGET_FOLDER"
exit 1
fi
PATH_TO_BINARY="$1"
TARGET_FOLDER="$2"
# if we cannot find the the binary we have to abort
if [ ! -f "$PATH_TO_BINARY" ] ; then
echo "The file '$PATH_TO_BINARY' was not found. Aborting!"
exit 1
fi
# copy the binary to the target folder
# create directories if required
echo "---> copy binary itself"
cp --parents -v "$PATH_TO_BINARY" "$TARGET_FOLDER"
# copy the required shared libs to the target folder
# create directories if required
echo "---> copy libraries"
for lib in `ldd "$PATH_TO_BINARY" | cut -d'>' -f2 | awk '{print $1}'` ; do
if [ -f "$lib" ] ; then
cp -v --parents "$lib" "$TARGET_FOLDER"
fi
done
# I'm on a 64bit system at home. the following code will be not required on a 32bit system.
# however, I've not tested that yet
# create lib64 - if required and link the content from lib to it
if [ ! -d "$TARGET_FOLDER/lib64" ] ; then
mkdir -v "$TARGET_FOLDER/lib64"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment