Skip to content

Instantly share code, notes, and snippets.

@popey
Created December 14, 2017 18:45
Show Gist options
  • Save popey/d4fab06244eba035892d490b90a7f8d2 to your computer and use it in GitHub Desktop.
Save popey/d4fab06244eba035892d490b90a7f8d2 to your computer and use it in GitHub Desktop.
Turn the output of ldd into something you can put in a snapcraft.yaml stage-packages section
#!/bin/bash
#
# lddtostage
#
# usage:
# lddtostage somebinary
#
# This will run through each linked library and figure out which deb
# it came from and print the list for pasting into a snapcraft.yaml
# in a 'stage-packages' section.
# Not perfect, and may include things like libc6 and nvidia-* which
# you likely don't want in your snap, but it's a good head start.
TMPDIR=$(mktemp -d)
LDD=$TMPDIR/LDD
PACKAGES=$TMPDIR/PACKAGES
ldd $1 | awk -F ' ' '{print $3}' | sed '/^$/d' | sed '/^(/d' > $LDD
while read p; do
echo -n .
dpkg -S $p | awk -F ' ' '{ print $1 }' | sed 's/:$//' >> $PACKAGES
done < $LDD
echo " "
sort $PACKAGES | uniq
rm -rf $TMPDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment