summaryrefslogtreecommitdiffstats
path: root/Bash
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2016-12-22 11:11:07 +0100
committerThomas Lange <code@nerdmind.de>2016-12-22 11:36:54 +0100
commit7749d85d6396af0e8a825926bcc3d334b640c4ec (patch)
treed693ebc32488737b77d59ae49871a38d2ec177ad /Bash
parent6c3b5af92828255b1f8f906352dc67b0c27fb164 (diff)
downloadsnippets-7749d85d6396af0e8a825926bcc3d334b640c4ec.tar.gz
snippets-7749d85d6396af0e8a825926bcc3d334b640c4ec.tar.xz
snippets-7749d85d6396af0e8a825926bcc3d334b640c4ec.zip
Initial commit
Diffstat (limited to 'Bash')
-rwxr-xr-xBash/ldd-copy-dependencies.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/Bash/ldd-copy-dependencies.sh b/Bash/ldd-copy-dependencies.sh
new file mode 100755
index 0000000..207d1df
--- /dev/null
+++ b/Bash/ldd-copy-dependencies.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# Copy Shared Library Dependencies [Thomas Lange <code@nerdmind.de>] #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+# #
+# This script copies all shared library dependencies from a binary source file #
+# to a desired target directory. The directory structure of the libraries will #
+# be mapped relative to the target directory. The binary file itself will also #
+# be copied to the target directory. #
+# #
+# ARGUMENT [-b]: Full path to the binary whose dependencies shall be copied. #
+# ARGUMENT [-t]: Full path to the target directory for the dependencies. #
+# #
+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
+
+#===============================================================================
+# Parsing command-line arguments with the getopts shell builtin
+#===============================================================================
+while getopts :b:t: opt
+do
+ case $opt in
+ b) ARGUMENT_BINARY="$OPTARG" ;;
+ t) ARGUMENT_TARGET="$OPTARG" ;;
+ esac
+done
+
+#===============================================================================
+# Checking if all required command-line arguments are provided
+#===============================================================================
+[ -z "${ARGUMENT_BINARY}" ] && echo "$0: Missing argument: [-b binary]" >&2
+[ -z "${ARGUMENT_TARGET}" ] && echo "$0: Missing argument: [-t target]" >&2
+
+#===============================================================================
+# Abort execution if required command-line argument is missing
+#===============================================================================
+[ -z "${ARGUMENT_BINARY}" ] || [ -z "${ARGUMENT_TARGET}" ] && exit 1
+
+#===============================================================================
+# Checking if binary or target path does not exists and abort
+#===============================================================================
+[ ! -f "${ARGUMENT_BINARY}" ] && echo "$0: Binary path does not exists." >&2 && exit 1
+[ ! -d "${ARGUMENT_TARGET}" ] && echo "$0: Target path does not exists." >&2 && exit 1
+
+#===============================================================================
+# Copy binary file with its parent directories to the target directory
+#===============================================================================
+cp --verbose --parents "${ARGUMENT_BINARY}" "${ARGUMENT_TARGET}"
+
+#===============================================================================
+# Copy each library with its parent directories to the target directory
+#===============================================================================
+for library in $(ldd "${ARGUMENT_BINARY}" | cut -d '>' -f 2 | awk '{print $1}')
+do
+ [ -f "${library}" ] && cp --verbose --parents "${library}" "${ARGUMENT_TARGET}"
+done \ No newline at end of file