Ubuntu – How to remove all packages from a certain repository


For a smooth upgrade from 10.04 to 10.10, I would like to remove all packages which are not in the default repositories (e.g. chromium PPA and third-party repositories). What is the easiest way (preferably CLI) to find and remove these packages?

Edit: this question is not restricted to PPA's, I have a x2go repository as well, so I'm looking for a generic command to remove packages belonging to a certain repository. For PPA's, the question How can PPAs be removed has great answers.

Best Answer

This script can list all packages from a particular server/branch (modifying the two declared variables):



apt-cache policy $(dpkg -l | awk 'NR >= 6 { print $2 }') |
  awk -v server="$server" -v branch="$branch" \
    '/^[^ ]/      { split($1, a, ":"); pkg = a[1] }
    nextline == 1 { nextline = 0; if ($2 == server && $3 == branch) print pkg }
    /\*\*\*/      { nextline = 1 }'

if you need to list all packages not coming from a particular server, independently from the branch, replace the next-to-last line with:

nextline == 1 { nextline = 0; if ($2 != server) print pkg }