-
-
Save jlu5/40388c1ed08bc04c12d7b7be50215dd4 to your computer and use it in GitHub Desktop.
extract and dump the changelog of a Debian package
This file contains hidden or 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 | |
| # Adapted from https://gist.github.com/thepaul/1002763 | |
| changelog_from_deb () { | |
| # won't work when packages symlink their docs from another package from the same source; | |
| # you'll get "No changelog found." | |
| if [[ -z "$2" || -e "$2" ]]; then | |
| echo "Target file \"$2\" exists or is empty; skipping" >&2 | |
| return 0 | |
| fi | |
| t="$(mktemp -d)" | |
| p="$(dpkg-deb -f "$1" Package)" | |
| echo "Package name found as $p" >&2 | |
| 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 | |
| target="$2" | |
| echo "Writing changelog to $target" >&2 | |
| gzip -dc < "$t/usr/share/doc/$p/$f" | tee "$target" | |
| fail=0 | |
| break | |
| fi | |
| done | |
| rm -rf $t | |
| [ $fail -eq 0 ] || echo "No changelog found." >&2 | |
| return $fail | |
| } | |
| if [[ -z "$1" ]]; then | |
| echo "Missing command line argument (path of .deb's)" >&2 | |
| exit 1 | |
| fi | |
| for deb in $(find "$1" | grep ".deb$"); do | |
| echo "Processing $deb..." >&2 | |
| # This format creates changelogs for synaptic - pkgname_version_arch.changelog (reference: https://github.com/smira/aptly/issues/170) | |
| target="${deb%.deb}.changelog" | |
| changelog_from_deb "$deb" "$target" | |
| # Symlink that to the format apt uses - pkgname_version.changelog | |
| #apt_target="$(cut -d '_' -f 1-2 <<< $target).changelog" | |
| #echo "Symlinking $target to $apt_target" >&2 | |
| #ln -s "$target" "$apt_target" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment