#!/bin/sh

binary=$1
echo "=== Copying dependencies for binary $binary"

mkdir -p /dependencies/usr/bin
cp "$binary" /dependencies/usr/bin/

ldd "$binary" | grep "=>" | awk '{print $3}' | while read lib; do
    if [ -f "$lib" ]; then
        echo "Copying dependency:  $lib"
        mkdir -p "/dependencies$(dirname "$lib")"
        cp "$lib" "/dependencies$lib"
    fi
done
