Created
January 23, 2018 15:31
-
-
Save fbudin69500/1ea0009ab05bfaabc84310420380b72f to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
set -euox pipefail | |
# Update cache just in case. | |
#apt-file update | |
list_packages="" | |
# Find all files in current repository. | |
for i in $(find . ) | |
do | |
# Only process if it is actually a file. | |
if [[ -f $i ]] | |
then | |
# Find if file has dependencies with `ldd`. This could return a failed | |
# return code. The script should continue even if this one file doesn't | |
# have dependencies. | |
EXIT_CODE=0 | |
ldd $i > /dev/null|| EXIT_CODE=$? && true | |
if [[ $EXIT_CODE == 0 ]] | |
then | |
# Read each dependency, and fine the package they belong to. | |
ldd $i | while read f; | |
do | |
f1="$(echo $f | cut -d ' ' -f 3)" | |
if [[ -n $f1 && -z "$(echo $f1 | grep -e '(.*)')" && $f1 != "not" ]] | |
then | |
package=$(apt-file search $f1 |grep -e $f1$ | cut -d : -f 1) | |
# Print `file : package` | |
echo $f1:$package | |
list_packages=($(echo "${list_packages[@]}") ${package}) | |
fi | |
done | |
fi | |
fi | |
done | |
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
# WARNING: Sorting and listing all packages doesn't work. This needs to be debugged!!!!!!!!!!! | |
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
echo "list:${list_packages[@]}" | |
echo "${list_packages[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ' | |
# TODO: Look for Python files (with the command `file`) and assess each Python | |
# file dependency. Try to find `import` statements, and deduce Debian packages | |
# from there. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment