Ubuntu – PPA spring cleaning — list packages installed from a PPA


This is a Q&A-style thing — hoping to help you in this period of new LTS release(s). There are a lot of links in this post, follow them and upvote them to give the authors the relevant kudos.

It is often suggested to remove or purge all of your PPAs when doing a version upgrade; I often have a lot of troubles remembering which PPA are installed and which packages are "owned" by a particular PPA — you sometime install a PPA but that does not mean that you have installed all packages from it.

For the list of PPA there are quite a lot of good scripts around; and for discovering the packages really installed from a PPA you can use apt-cache policy or similar commands.

But — what about a one-stop script to list all your installed PPAs and all the packages you have installed from them?

Best Answer

The following script will give you a list like the following:

--->  ubuntu-tweak
--->  gimp
--->  gimp-data
--->  gimp-help-common
--->  gimp-help-en
--->  gimp-help-en-gb
--->  gimp-help-es
--->  gimp-help-it
--->  gimp-plugin-registry
--->  libgimp2.0
--->  libopenjpeg-dev
--->  libopenjpeg5

Script following (copy it to a file and make it executable):

#! /bin/bash
list_all_packages_repos() {
apt-cache policy $(dpkg -l | awk 'NR >= 6 { print $2 }') |
  awk '/^[^ ]/    { split($1, a, ":"); pkg = a[1] }
    nextline == 1 { nextline = 0; printf("%-40s %-50s %s\n", pkg, $2, $3) }
    /\*\*\*/      { nextline = 1 }'

list_packages_of() { #1 is the tmpfile, $2 is the ppa regexp
    grep "$2" "$1" | awk '{print "---> ", $1}'

# cache all packages files now 

list_all_packages_repos > $tmpfile

# listppa Script to get all the PPA installed on a system ready to share for reininstall
for APT in $(find /etc/apt/ -name "*.list"); do
    grep -o "^deb http://ppa.launchpad.net/[a-z0-9\-]\+/[a-z0-9\-]\+" "$APT" | while read ENTRY ; do
        USER=$(echo "$ENTRY" | cut -d/ -f4)
        PPA=$(echo "$ENTRY" | cut -d/ -f5)
        echo  PPA:$USER/$PPA
    list_packages_of "$tmpfile" "$USER/$PPA"

rm "$tmpfile"