Skip to content

Instantly share code, notes, and snippets.

@thepaul
Created June 1, 2011 17:01
Show Gist options
  • Save thepaul/1002763 to your computer and use it in GitHub Desktop.
Save thepaul/1002763 to your computer and use it in GitHub Desktop.
extract and output the changelog from a .deb file, when possible
changelog_from_deb () {
# won't work when packages symlink their docs from another package from the same source;
# you'll get "No changelog found."
t="$(mktemp -d)"
p="$(dpkg-deb -f "$1" Package)"
fail=1
dpkg-deb --fsys-tarfile "$1" | \
tar -x --wildcards -C $t ./usr/share/doc/"$p"/changelog\* 2>/dev/null
for f in changelog.Debian.gz changelog.gz; do
if [ -e "$t/usr/share/doc/$p/$f" ]; then
gzip -dc < "$t/usr/share/doc/$p/$f"
fail=0
break
fi
done
rm -rf $t
[ $fail -eq 0 ] || echo "No changelog found." >&2
return $fail
}
@trapier
Copy link

trapier commented Jun 6, 2014

apt-listchanges does something similar

@RedPh0enix
Copy link

RedPh0enix commented Jan 10, 2017

Very handy - thanks Paul.
Quick hack based on the code above, that avoids the temp directory, and writes to stdout.

#!/bin/bash
if [ ! -f $1 ]; then
echo "Package not found." >&2
exit
fi

p="$(dpkg-deb -f "$1" Package)"
dpkg-deb --fsys-tarfile $1 | tar -xf - --to-stdout --wildcards ./usr/share/doc/"$p"/changelog* | gzip -d 2>/dev/null
if [ $? -ne 0 ]; then
echo "Changelog not found." >&2
fi

@noscript
Copy link

For .rpm that would be

rpm -qp --changelog "$1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment