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.