Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Ubuntu offers an easy GUI interface that allows you to edit, (de-)activate and remove PPAs.

But going through all the GUI dialogs and menus can sometimes be tedious, especially if you have a lot of PPAs added to your system.

That's why I was wondering if there was a way to disable (and enable) a PPA from the command-line.


Note: I am not talking about adding/removing the PPA (that's quite easy to do: sudo add-apt-repository ppa / sudo add-apt-repository --remove ppa). What I am looking for is a way to temporarily disable a PPA and reenable it at will - all from within the CLI.


Edit:

Sushantp606 and Davidson Chua's answers were a good starting point and made me change the scope of my question. It's certainly good to know that repositories can be managed with the sources.list files but this still looks like a very tedious task to me. I would love to know if there is a way to automate this in the same manner the Software Properties window does.

Ideally I would like to find a command that will make it possible to quickly enable and disable a PPA by its PPA address, e.g.:

ppa_activate ppa:synapse-core/ppa

and

ppa_deactivate ppa:synapse-core/ppa
share|improve this question
    
You don't "deactivate" PPA's but simply makes APT to ignoring them, be it removing the line or commenting out. There is no difference at the end of the day. –  Braiam Nov 30 '13 at 17:40
    
@Braiam Well, not exactly. Removed PPAs are completely removed from your system. In order to readd them you will have to either memorize the PPA address, look through your history or find it again on the web. Deactivated PPAs still appear in the GUI dialog and can be quickly activated when necessary. To apt it's all the same, of course, but there certainly is a difference in the user experience. –  Glutanimate Nov 30 '13 at 17:44

4 Answers 4

up vote 3 down vote accepted

Even a simpler script to toggle between activating or deactivating a particular ppa. Save the code given below in a file, for instance toggle_ppa.sh.

#!/bin/bash
#
# toggle_ppa.sh
#
# created by souravc (http://askubuntu.com/users/127327/)
# modified by Glutanimate (http://askubuntu.com/users/81372/)
#
# originally released at http://askubuntu.com/q/383605/81372
#
# DESCRIPTION:  Detects if a PPA is active/inactive and deactivates/activates it
#               on user confirmation.
#
# USAGE:        toggle_ppa.sh ppa:launchpaduser/ppaname

### VARIABLES

SOURCEDIRECTORY=/etc/apt/sources.list.d
PPA="$1"

### USAGE CHECKS

## Arguments

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

Follow the procedure given at the other answer to keep file in PATH and make it executable.

Usage

sudo toggle_ppa.sh <full-ppa-name>

Example

sudo toggle_ppa.sh ppa:webupd8team/java

How it works

The working principle of this code is the same as in my other answer. 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.

share|improve this answer
    
Thank you for your scripts. I really appreciate the work you put into them. The scripts are just about perfect for my purposes aside from one core issue: Your scripts use the initial part of the PPA's name. I am afraid that this won't be accurate enough in some cases. Take the webupd8team/java PPA for instance: The java PPA is only one of more than 20 PPAs maintained by the launchpad user webupd8team (take a look at the Personal package archives list on the user page). I'd gladly accept this answer if you were to find a way to solve this issue. –  Glutanimate Nov 30 '13 at 17:51
    
Yes I know this issue. You will have same for google-chrome and google-talkplugin. I thought about it. But whatever change may be I do, you have to to supply the list name for two or more closely named repos to such extent that one is uniquely chosen. Is it not better than providing a complete name? According to your question you ware agreed to supply the full ppa name as you said in your example. –  souravc Nov 30 '13 at 18:10
    
Hi again. I think I found a solution. Please take a look at this modified script. Would you be fine with me editing your answer to include it/replace the one it features right now? –  Glutanimate Nov 30 '13 at 19:11
1  
You could name it just toggle_ppa to save 3 characters. So long as you have the #!/bin/bash line present at the beginning it will process as a bash script. –  Thomas W. Nov 30 '13 at 19:39
1  
@Glutanimate I really would go with the script above that you accepted if I had to choose one. But just to provide a different approach to solve the "issue with two or more ppa lists having close initial name" I edited the othe script. Take a look at it. If you hit only part of ppa name that is common for two or more ppas, it will provide complete lists of all ppas that starts with your given string. For example you put only the string "webupd8" and you have more than 20 ppa from that user you will be provided a list with full names. –  souravc Dec 1 '13 at 6:24

ppa info is actually saved in separate files in /etc/apt/sources.list. Here is the code which will do the desired action to de-activate or activate desired repo. Save the code given below in a file, say mod-ppa

#!/bin/bash
mydir=/etc/apt/sources.list.d
function getlist(){
    echo -e "\n\tchose one of the following lists"
    echo -e "\t================================"
    for itm in `seq 1 $1`
    do
        echo -e "\t`echo $2 | awk -v x=$itm '{print $x}' | awk -F/ '{print $NF}'`"
    done
}

if [ $# -lt 1 ]
then
    echo "E: mod_ppa: missing operand"
    echo "Try 'mod_ppa --help' for more information."
    exit 0
elif [ $# -lt 2 ]
then
    echo -e "E: syntax error,\nTry 'mod_ppa --help' for more information."
    exit 0
fi

case "$1" in
    -d )
        ppa=`ls $mydir/$2*.list`
        num=`echo $ppa | wc -w`
        if [ `echo $num` -gt 1 ]
        then
            getlist "$num" "$ppa"
        else
            if [ -e $mydir/$2*.list ]
            then
                sed -i "s/^deb\-src/\#deb\-src/" $ppa
                sed -i "s/^deb\ http/\#deb\ http/" $ppa
            else
                echo "E: ppa does not exist/check ppa name"
            fi
        fi
        ;;
    -a )
        ppa=`ls $mydir/$2*.list`
        num=`echo $ppa | wc -w`
        if [ `echo $num` -gt 1 ]
        then
            getlist "$num" "$ppa"
        else
            if [ -e $mydir/$2*.list ]
            then
                sed -i "s/^\#deb\-src/deb\-src/" $ppa
                sed -i "s/^\#deb\ http/deb\ http/" $ppa
            else
                echo "E: ppa does not exist/check ppa name"
            fi
        fi
        ;;
    --help)
        echo "Usage: mod_ppa [OPTION] [PPA NAME'S INITIAL PART]"
        echo "Mandatory argument options."
        echo "-a       Activate certain ppa"
        echo "-d       Deactivate certain ppa"
        ;;
    * ) 
        echo "mod_ppa: invalid option '$1'"
        echo "Try 'mod_ppa --help' for more information."
        ;;
esac

save the script in /home/<username>/bin/, which is in PATH usually. To check write in terminal

echo $PATH

If not, add /home/<username>/bin/ to PATH by adding the following line to .bash_profile or .bashrc whichever is convenient,

export PATH=$PATH:$HOME/bin

Then source the file, write in terminal

source .bash_profile [or source .bashrc]

Give mod_ppa execution permission, write in terminal

chmod +x mod_ppa

Usage

To de-activate a ppa use

sudo mod_ppa -d <ppa_name's_initial_part>

For example, to deactivate ppa:webupd8team/java use

sudo mod_ppa -d webupd8team

To activate a ppa use

sudo mod_ppa -a <ppa_name's_initial_part>

For example, to activate ppa:synapse-core use

sudo mod_ppa -a synapse-core

help

mod_ppa --help

I have assumed you will not be interested in deactivating the basic and default ppa(s) listed in /etc/apt/sources.list. Anyway there is only few, you can deactivate them by hand if you wish to. Sushantp606's answer was quite helpful.

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.

As the script is supposed to deal with some sensitive part of OS, I tried to code it defensively. Kept checks for what arguments are being passed to the script and set some error messages accordingly. Also a small help is added. These part increases the length of code.

share|improve this answer
    
I would modify this to "toggle". I.e. check for # being present and add it/remove it. –  mniess Nov 29 '13 at 14:02
    
that would also be a good idea. –  souravc Nov 29 '13 at 14:16
    
In any case I'd say no script is necessary for something you don't do on a regular basis. I see no usecase of constantly de-/activating repos again and again. If you don't want it, just edit the files. –  mniess Nov 29 '13 at 14:57
    
@mniess I agree with your view. but if anyone has a long list of repos, he might wish to use such a script. Though I don't know what will be a probable reason to (de-)activate some repos constantly. –  souravc Nov 30 '13 at 17:01
    
@guntbert I tried to explain what the script is doing. Please feel free to suggest if any other action is required to improve the answer. –  souravc Nov 30 '13 at 17:08

Take a look at How to disable a particular PPA?. Although the first answer by qeoh uses the GTK frontend, the second answer by minimec suggests commenting out the ppa in /etc/apt/sources.list. I'm not sure if this is what you're looking for, but this is a possible method.

share|improve this answer
    
+1. Thank you, this is certainly a valid answer to my intial question but I have decided to change my initial scope and I am now trying to find a more automated way to manage the PPA state from the CLI. I am sure though that your answer will be a great starting point. –  Glutanimate Nov 29 '13 at 4:24

By editing

/etc/apt/sources.list

file from the command line, we can add, remove, or temporarily disable software repositories.just comment out unwanted repo via terminal .

I cant make the command ,its just an idea . let me know if you could connect it via terminal command like-

The command to comment out the source repositories in /etc/apt/sources.list is:

sudo sed -i 's/^deb\-src/\#deb\-src/' /etc/apt/sources.list

and to un comment it use

sudo sed -i 's/^\#deb\-src/deb\-src/' /etc/apt/sources.list

use repository you want to disable/comment out instead of s/^\#deb\-src/deb\-src/ and before doing any change make a backup source list file as below-

sudo cp -v /etc/apt/sources.list /etc/apt/sources.list.backup
share|improve this answer
    
+1. Thank you for your answer. As I've stated below I decided to change the scope of the question in order to find a more automated solution. But I am sure /etc/apt/sources.list will be a good starting point. –  Glutanimate Nov 29 '13 at 4:26
    
i think the more closest answer you need is mentioned now , just use your repo you want to disable instead of s/^\#deb\-src/deb\-src/ are make sure to use them with "i flag" .' –  Sushantp606 Nov 29 '13 at 4:28
    
mmh, looks as though PPA repo data is actually saved under separate files in /etc/apt/sources.list.d. The naming scheme seems to be: $ppa-$release.list. Slashes in $ppa are replaced by dashes (e.g.: synapse-core/ppa --> synapse-core-ppa). –  Glutanimate Nov 29 '13 at 4:40
    
If you are feeling like it, sure. I mainly posted this for future reference if someone wants to take it up and create a script. But I am sure someone must have faced this problem before (controlling PPAs from the CLI) and I wouldn't be surprised if there was a solution out there already. It's just a question of finding it. –  Glutanimate Nov 29 '13 at 5:07
1  
put the pure answer and get the +1 from me. –  Avinash Raj Nov 29 '13 at 6:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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