#!/bin/sh

# Produces a list of all unique packages needed by a binary file named as 1st parameter
# Takes a while, but worth it when preparing deb file dependency lists.

filelist=`objdump -p $1 | grep 'NEEDED' | tr -s ' ' | cut -d ' ' -f 3`
filename=`basename "$1"`
# echo $filelist
echo "Find all amd64 packages needed by $filename..."

rm -f pkgs.log
for f in $filelist
do
  dpkg -S $f | grep ':amd64' | cut -d ':' -f 1 >> pkgs.log
done
  
sort pkgs.log > pkgs.srt
uniq pkgs.srt > "$filename""_pkgs_amd64.txt"

echo "List is in: ""$filename""_pkgs_amd64.txt"
  
