5

Is there a way to automatically delete or disable a ppa that does not work anymore?

When I do apt-get update I get a lot of error message regarding some ppas that cant be found.

I have disabled them by hand for now, but is there a way to disable them automatically? Since I have many ppas it is a lot of work to search and disable them by hand.

3 Answers 3

4
+50

You can use a script to disable/enable a ppa very easily. Save the script as toggle_ppa.sh and put it in /usr/local/bin

#!/bin/bash
#
# toggle_ppa.sh
#
# DESCRIPTION:  Detects if a PPA is active/inactive and deactivates/activates it
#               on user confirmation.

SOURCEDIRECTORY=/etc/apt/sources.list.d
PPA="$1"     
if [ -z "$PPA" ]
then
    echo "Error: Please provide a PPA name to toggle between activation/deactivation"
    echo "The PPA name should be formatted as it appears on launchpad, e.g.:
"$0" ppa:webupd8team/y-ppa-manager"
    exit 1
fi

## Root privileges

if [ "$(whoami)" != "root" ]; then
  echo "Error: This script needs root privileges. Restarting..."
  sudo "$0" "$1"
  exit
fi

### MAIN

SOURCELIST_NOPFX="${PPA#*:}" #remove 'ppa:' prefix
SOURCELIST="${SOURCELIST_NOPFX////-}"-$(lsb_release -cs) #replace all slashes with dashes, include release
SOURCEFILE="$SOURCEDIRECTORY"/"$SOURCELIST".list #compose sources list path

if [ -e "$SOURCEFILE" ]
then
    echo "Processing $SOURCEFILE..."
    SOURCE_COMMENTED=$(grep "^\#deb\ " "$SOURCEFILE") #check if sources line is commented
    if [ -z "$SOURCE_COMMENTED" ]
    then
        echo "$PPA is active. Going to deactivate. Proceed? [ y/n ]"
        read ANSWER
        if [ $ANSWER == "y" ]
        then
            sed -i "s/^deb\-src/\#deb\-src/" $SOURCEFILE
            sed -i "s/^deb\ http/\#deb\ http/" $SOURCEFILE
            echo "Updating package index files..."
            sudo apt-get update
            echo "Done."
        else
            echo "Aborted."
            exit 0
        fi
    else
        echo "$PPA is inactive. Going to activate. Proceed? [ y/n ]"
        read ANSWER
        if [ $ANSWER == "y" ]
        then
            sed -i "s/^\#deb\-src/deb\-src/" $SOURCEFILE
            sed -i "s/^\#deb\ http/deb\ http/" $SOURCEFILE
            echo "Updating package index files..."
            sudo apt-get update
            echo "Done."
        else
            echo "Aborted."
            exit 0
        fi
    fi
else
    echo "Error: Source file at $SOURCEFILE for $PPA does not exist. Please check PPA name."
    exit 0
fi

Usage

sudo toggle_ppa.sh <full-ppa-name>

Example

sudo toggle_ppa.sh ppa:webupd8team/java

How it works

When any ppa repo is deactivated using Software center (GUI), it actually puts a # in front of all the lines inside corresponding ppa .list file at /etc/apt/sources.list.d/. Usually most of the .list files contain two lines that begins with deb http and deb-src, a few have only one. The above script is doing the same thing using sed. First it checks the ppa .list (input by user) is present or not. Then put or remove a # in front the lines accordingly.

The code acts in a very interactive manner. When someone runs this along with ppa name as its argument, it will display the PPA's current status and what the code is going to do on successful execution. Then it will ask permission of the user. Only if the user inputs 'y' to confirm the code will change the status of the PPA and activate/deactivate it. It will immediately abort if the user puts an 'n' for no.

Note I proposed this code in this answered. glutanimate helped a lot to improve the code.

3
  • I like this but I think the user is looking for a way to do all of them at once. Feb 24, 2014 at 10:23
  • @belkinsa there is no point in disabling all of them at once. A simple sed statement can do it. besides OP asks in question "Automatically disable a ppa" not all of them at once.
    – sourav c.
    Feb 24, 2014 at 12:52
  • You are right..I can read. ;) Feb 24, 2014 at 14:34
1

Disabling a PPA using the Ubuntu Software Sources is a big hassle, as there is no way to filter or order (in a humanly useful way) the PPAs. Instead you could use y-ppa-manager via its Manage PPAs window, which displays the PPAs in alphabetical order and thus allows for easier/quicker spotting of a given PPA source.

You can install Y PPA Manager from the ppa:webupd8team/y-ppa-manager PPA.

See also:

3
  • This is not an automatic way. It's another way to find and even disable PPA's manually. Feb 24, 2014 at 10:18
  • True. y-ppa-manager also has a way to Fix all GPG Badsig errors. So I guess there is scope to file a feature request with the package author for an automatic disabling of PPAs.
    – landroni
    Feb 24, 2014 at 10:21
  • I believe so and I think they are not around. It's now to my interest to see if there is a solution. Feb 24, 2014 at 10:24
0

You can either comment out the PPAs this way:

# deb http://archive.canonical.com/ubuntu precise partner
# deb-src http://archive.canonical.com/ubuntu precise partner

Or, you can do using Ubuntu Software Sources by selecting all:

Software Sources

5
  • OP want to disable them automatically. This is manual step to disable PPA.
    – penreturns
    Oct 9, 2012 at 5:15
  • 1
    Oh okay, my bad. Will update the answer soon. Oct 9, 2012 at 5:16
  • 1
    Yes, as already mentioned, I am aware of the manual ways, but with the number of ppas I have this comes unhandy, so I am searching for an automatic way. Thank you anyway.
    – NobbZ
    Oct 9, 2012 at 6:41
  • @NobbZ By any chance you wanna do it in a Cron Job? Oct 9, 2012 at 7:02
  • I would prefer to run this "cleanup" by hand, so I can see when ppas went obselet.
    – NobbZ
    Oct 9, 2012 at 12:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .