18

Since the installation, I have added not too few PPAs to my 15.04 system because I wanted a specific application. But sometimes I have removed that package later again, because it did not work, was not what I really wanted, or just because I don't need it any more. I don't know if that makes a difference, but some repositories were installed with add-apt-repository while others just came by a command that just created the file in /etc/apt/sources.list.d/ manually.

Now how can I check whether I have any packages from a PPA installed and if not, remove it from my software sources? This procedure should automatically work through all PPAs.

  • As standalone script or as an extension for y-ppa-manager? ; ) – A.B. Sep 17 '15 at 5:41
  • @A.B. Standalone, please. I don't use y-ppa-manager. – Byte Commander Sep 17 '15 at 8:11
25

Here is a script. Without a parameter, the script lists some infos. With --delete, the list files will be removed, if no packages are installed.

#!/usr/bin/env bash
for f in /etc/apt/sources.list.d/*.list; do
    grep -Po "(?<=^deb\s).*?(?=#|$)" "$f" | while read -r ENTRY ; do
    echo "ENTRY: $ENTRY"
        HOST=$(cut -d/ -f3 <<< "$ENTRY")

        if [ "ppa.launchpad.net" = "$HOST" ]; then
          USER=$(cut -d/ -f4 <<< "$ENTRY")
          PPA=$(cut -d/ -f5 <<< "$ENTRY")
          packageCount=$(awk '$1=="Package:" {if (a[$2]++ == 0) {system("dpkg -l "$2)}}' /var/lib/apt/lists/*"$USER"*"$PPA"*Packages 2>/dev/null | awk '/^ii/' | wc -l)
          echo "PPA: ppa:$USER/$PPA"
          echo "FILENAME: $f"
          echo "$packageCount package(s) installed"
          if [ "$packageCount" -eq 0 ] && [ "$1" == "--delete" ]; then
            sudo rm "$f" && echo "$f deleted"
          fi
          echo
        else 
          USER=$(cut -d/ -f3 <<< "$ENTRY")
          PPA=$(cut -d/ -f4 <<< "$ENTRY")
          packageCount=$(awk '$1=="Package:" {if (a[$2]++ == 0) {system("dpkg -l "$2)}}' /var/lib/apt/lists/*"$USER"*Packages 2>/dev/null | awk '/^ii/' | wc -l)
          echo "REPOSITORY: $USER/$PPA"
          echo "FILENAME: $f"
          echo "$packageCount package(s) installed"
          if [ "$packageCount" -eq 0 ] && [ "$1" == "--delete" ]; then
            sudo rm "$f" && echo "$f deleted" 
          fi
          echo
        fi
    done
done

Copy the code above in a new file, e.g.:

mkdir -p ~/bin
nano ~/bin/checkPPAs

Make the script executable

chmod +x ~/bin/checkPPAs

And run it with

~/bin/checkPPAs

to list all repositories and the number of installed packages.

Start the script with

~/bin/checkPPAs --delete

to remove the list files.


Sample output on my system

ENTRY: http://ppa.launchpad.net/webupd8team/y-ppa-manager/ubuntu vivid main
PPA: ppa:webupd8team/y-ppa-manager
FILENAME: /etc/apt/sources.list.d/webupd8team-ubuntu-y-ppa-manager-vivid.list
3 package(s) installed

ENTRY: http://ppa.launchpad.net/nilarimogard/webupd8/ubuntu vivid main
PPA: ppa:nilarimogard/webupd8
FILENAME: /etc/apt/sources.list.d/nilarimogard-ubuntu-webupd8-vivid.list
5 package(s) installed

ENTRY: http://ppa.launchpad.net/obsproject/obs-studio/ubuntu vivid main
PPA: ppa:obsproject/obs-studio
FILENAME: /etc/apt/sources.list.d/obsproject-ubuntu-obs-studio-vivid.list
1 package(s) installed

ENTRY: http://archive.getdeb.net/ubuntu vivid-getdeb apps
REPOSITORY: archive.getdeb.net/ubuntu vivid-getdeb apps
FILENAME: /etc/apt/sources.list.d/getdeb.list
7 package(s) installed

ENTRY: http://ppa.launchpad.net/psi-plus/ppa/ubuntu vivid main
PPA: ppa:psi-plus/ppa
FILENAME: /etc/apt/sources.list.d/psi-plus-ubuntu-ppa-vivid.list
15 package(s) installed

ENTRY: http://ppa.launchpad.net/libreoffice/ppa/ubuntu vivid main
PPA: ppa:libreoffice/ppa
FILENAME: /etc/apt/sources.list.d/libreoffice-ubuntu-ppa-vivid.list
24 package(s) installed

ENTRY: https://deb.nodesource.com/node_0.12 vivid main
REPOSITORY: deb.nodesource.com/node_0.12 vivid main
FILENAME: /etc/apt/sources.list.d/nodesource.list
1 package(s) installed

ENTRY: http://dl.google.com/linux/chrome/deb/ stable main
REPOSITORY: dl.google.com/linux
FILENAME: /etc/apt/sources.list.d/google-chrome.list
2 package(s) installed

ENTRY: http://ppa.launchpad.net/gnome3-team/gnome3/ubuntu vivid main
PPA: ppa:gnome3-team/gnome3
FILENAME: /etc/apt/sources.list.d/gnome3-team-ubuntu-gnome3-vivid.list
273 package(s) installed

ENTRY: http://ppa.launchpad.net/noobslab/apps/ubuntu vivid main
PPA: ppa:noobslab/apps
FILENAME: /etc/apt/sources.list.d/noobslab-ubuntu-apps-vivid.list
0 package(s) installed

ENTRY: http://ppa.launchpad.net/ubuntuhandbook1/corebird/ubuntu vivid main
PPA: ppa:ubuntuhandbook1/corebird
FILENAME: /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-corebird-vivid.list
1 package(s) installed

ENTRY: http://ppa.launchpad.net/webupd8team/unstable/ubuntu vivid main
PPA: ppa:webupd8team/unstable
FILENAME: /etc/apt/sources.list.d/webupd8team-ubuntu-unstable-vivid.list
1 package(s) installed

ENTRY: http://download.mono-project.com/repo/debian wheezy main
REPOSITORY: download.mono-project.com/repo
FILENAME: /etc/apt/sources.list.d/mono-xamarin.list
166 package(s) installed

ENTRY: http://ppa.launchpad.net/otto-kesselgulasch/gimp-edge/ubuntu vivid main
PPA: ppa:otto-kesselgulasch/gimp-edge
FILENAME: /etc/apt/sources.list.d/otto-kesselgulasch-ubuntu-gimp-edge-vivid.list
5 package(s) installed

ENTRY: http://ppa.launchpad.net/numix/ppa/ubuntu vivid main
PPA: ppa:numix/ppa
FILENAME: /etc/apt/sources.list.d/numix-ubuntu-ppa-vivid.list
3 package(s) installed

ENTRY: http://ppa.launchpad.net/webupd8team/atom/ubuntu vivid main
PPA: ppa:webupd8team/atom
FILENAME: /etc/apt/sources.list.d/webupd8team-ubuntu-atom-vivid.list
1 package(s) installed

ENTRY: https://packages.graylog2.org/repo/debian/ trusty 1.0
REPOSITORY: packages.graylog2.org/repo
FILENAME: /etc/apt/sources.list.d/graylog.list
3 package(s) installed

ENTRY: http://ppa.launchpad.net/ubuntu-mate-dev/ppa/ubuntu vivid main
PPA: ppa:ubuntu-mate-dev/ppa
FILENAME: /etc/apt/sources.list.d/ubuntu-mate-dev-ubuntu-ppa-vivid.list
0 package(s) installed

ENTRY: http://ppa.launchpad.net/gnome3-team/gnome3-staging/ubuntu vivid main
PPA: ppa:gnome3-team/gnome3-staging
FILENAME: /etc/apt/sources.list.d/gnome3-team-ubuntu-gnome3-staging-vivid.list
268 package(s) installed

ENTRY: http://debian.koha-community.org/koha stable main
REPOSITORY: debian.koha-community.org/koha stable main
FILENAME: /etc/apt/sources.list.d/koha.list
0 package(s) installed

ENTRY: http://ppa.launchpad.net/pgavin/ghdl/ubuntu trusty main
PPA: ppa:pgavin/ghdl
FILENAME: /etc/apt/sources.list.d/pgavin-ubuntu-ghdl-vivid.list
0 package(s) installed

ENTRY: http://ppa.launchpad.net/ubuntu-mate-dev/vivid-mate/ubuntu vivid main
PPA: ppa:ubuntu-mate-dev/vivid-mate
FILENAME: /etc/apt/sources.list.d/ubuntu-mate-dev-ubuntu-vivid-mate-vivid.list
3 package(s) installed

ENTRY: http://ppa.launchpad.net/webupd8team/sublime-text-3/ubuntu vivid main
PPA: ppa:webupd8team/sublime-text-3
FILENAME: /etc/apt/sources.list.d/webupd8team-ubuntu-sublime-text-3-vivid.list
1 package(s) installed

ENTRY: http://ppa.launchpad.net/webupd8team/java/ubuntu vivid main
PPA: ppa:webupd8team/java
FILENAME: /etc/apt/sources.list.d/webupd8team-ubuntu-java-vivid.list
1 package(s) installed

ENTRY: http://dl.google.com/linux/chrome/deb/ stable main
REPOSITORY: dl.google.com/linux
FILENAME: /etc/apt/sources.list.d/google.list
2 package(s) installed

ENTRY: http://dl.google.com/linux/chrome/deb/ stable main
REPOSITORY: dl.google.com/linux
FILENAME: /etc/apt/sources.list.d/google-chrome-beta.list
2 package(s) installed
  • Why do you think removing them is a bad idea? And how would you preferably remove it? add-apt-repository --remove? Or manually rm the ???.list file? What about GPG keys used by this PPA, will they also be removed if I use add-apt-repository --remove? – Byte Commander Sep 17 '15 at 8:19
  • If no package is installed, then the file can be safely deleted. I will be adding. Remove the key is a bit more complicated. – A.B. Sep 17 '15 at 8:42
  • I have updated my script. – A.B. Sep 17 '15 at 8:46
  • Start it again, one rm command had an echo – A.B. Sep 17 '15 at 8:49
  • /home/yoesoff/removeppa.sh: 4: /home/yoesoff/removeppa.sh: Syntax error: redirection unexpected – Yusuf Ibrahim Dec 24 '19 at 6:35
5

I don't know of an automatic way, but this method is fairly quick:

  1. Start synaptic package manager and input your password when prompted

  2. In the left column toward the bottom, click on Origin

All the ppas on your system will now be listed at the top of the left column. You can click down the list and see if any software is installed from each. (if there is, there will be a green box by the package name in the right column). If there are many packages from the ppa (too many to see on the screen at once), you can click on the S at the top of the right column to sort them by status.

NOTE: If you have any unused ppas:

  1. Click Settings in the top menu
  2. Then Repositories
  3. Software and Updates window will be displayed.
  4. From this window you can remove the unused ppas from the Other Software tab.
  • He asked how to detect unused PPAs. There are already a zillion directions about how to delete a PPA via Software Update. – Joe C Sep 3 '19 at 14:18
  • @JoeC I'm not sure what you are complaining about or why you downvoted my answer. It may not be the best way, but I do show how to detect unused PPAs. – Organic Marble Sep 3 '19 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.