#!/bin/bash set -eo pipefail [ $# -lt 2 ] && { echo "usage: $0 [ADDITIONAL_LIBS ...]" exit 1 } src="$1" dst="$2" shift shift libs="$(ldd "$src" | grep -F '/' | sed -E 's|[^/]*/([^ ]+).*?|/\1|')" ld_so="$(echo "$libs" | grep -F '/ld-linux-')" ld_so="$(basename "$ld_so")" program="$(basename "$src")" cat >"$dst" <>"$dst" 2> >(grep -v 'Removing leading' >&2) chmod +x "$dst"