Last active
August 29, 2015 14:27
-
-
Save rjaeckel/3f6bfdfc758a62756bc2 to your computer and use it in GitHub Desktop.
When chroot-ing a program, you have to copy the necessary libraries for it under the chroot-ed directories. It is sometimes a troublesome task as some libraries may have some dependencies on other libraries as the program itself does. This script, lddcopy.sh, is a convenient shell script which copies all the necessary libraries recursively and p…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
######################################################################## | |
# lddcopy - A shell script to copy libraries for chrooted applications # | |
# Yu Yagi ([email protected]) # | |
######################################################################## | |
chroot= | |
opterr= | |
dryrun= | |
silent=false | |
while getopts "c:nq" param; do | |
case $param in | |
c) chroot="$OPTARG" ;; | |
n) dryrun=echo ;; | |
q) silent=true ;; | |
?) opterr=1; break;; | |
esac | |
done | |
shift `expr $OPTIND - 1` | |
program=$1 | |
if [ -z "$program" -o "$opterr" ]; then | |
echo "Usage: `basename $0` -c [chroot-dir] [-n] [-q] [program]" | |
echo "-c [chroot-dir]\tRoot directory of chroot (Default: /)" | |
echo "-n \tDry run (i.e. do nothing actually)" | |
echo "-q \tSuppress message outputs" | |
exit 0 | |
fi | |
if [ ! -d "$chroot/" ]; then | |
echo "chroot directory is not found: $2" >&2 | |
exit 1 | |
fi | |
for i in `ldd $program | awk '$1~/^[0-9]/{print $NF}'`; do | |
# Do nothing for the program itself | |
if [ $program = $i ]; then | |
continue | |
fi | |
# Create a necessary directory | |
if [ ! -d `dirname $chroot/$i` ]; then | |
$dryrun /bin/mkdir -p `dirname $chroot/$i` || exit 1 | |
fi | |
# Copy a library file | |
if [ -f "$chroot/$i" ]; then | |
$silent || echo "SKIP: $i -> $chroot/$i" | |
else | |
$dryrun /bin/cp $i $chroot/$i || exit 1 | |
$silent || echo "COPY: $i -> $chroot/$i" | |
fi | |
# Copy libraries recursively | |
$0 `test "$chroot" && echo "-c $chroot"` `test "$dryrun" && echo "-n"` `$silent && echo "-q"` $i || exit 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment