I am back with some more scripting fun.
I have been working on configuring my new debian machine and found one utility very lacking in debian and that was add-apt-repository.
So i set down and took my time out and finally i am able to mix match this simple script.
Disclaimer: I know adding ppa can have adverse effects on debian machines
At this point the work that this script performs is
- add the repository of the ppa. (here i am using lucid as the distribution of choice, coz i am using squeeze as my debian version)
- add the gpg key to the keyring.
Disclaimer
- This script is at this pointed tested only on one machine. debian Squeeze (mint Flavoured.)
Steps to install this.
- Download file
$ wget http://blog.anantshri.info/content/uploads/2010/09/add-apt-repository.sh.txt
2. Save this file in /usr/sbin/
$ cp add-apt-repository.sh.txt /usr/sbin/add-apt-repository
3. Change permissions to execute
$ chmod o+x /usr/sbin/add-apt-repository
4. Change ownership to root
$chown root:root /usr/sbin/add-apt-repository
5. Now when ever you need to execute command type
$ sudo add-apt-repository ppa:ppa-name
Opening this script to larger audience so that we can crowdsource efforts if someone likes it.
hope this can help someone
Change Log
7 – Jan – 2011 : Updated the tutorial to place the file @ /usr/sbin as suggested at various during comments.
6 – Aug – 2011 : Updated the script to deal with the security hole (although not easily exploitable) as suggested by 7eggert at comment no 23
10 Sep – 2011 : bin corrected to sbin in step 3 and 4.. : thanks to Craig for pointing that out

















January 1st, 2011 at 10:03 pm
great job, may be useful
January 1st, 2011 at 10:10 pm
[...] command not found, quindi non è possibile aggiungerli…..anzi è possibile, anche se sconsigliato. Comunque per chi vuole avere anche questa possibilità sulla propria [...]
January 2nd, 2011 at 10:22 am
@edmond.
Thanks for the link back.
sharing and helping is the only reason of putting this on blog.
January 2nd, 2011 at 6:24 pm
Here you can find the script to remove repository and gpg key:
http://www.sourceslist.eu/guide/script-remove-apt-repository/
January 4th, 2011 at 9:44 am
Muchas gracias. Había intentado instalado el paquete “python-software-properties” de Maverick, no el de Squeeze. Es donde está el comando “apt-add-repository”, pero no funciona.
Una sugerencia: El script estaría mejor situado en /usr/sbin y he cambiado Lucid por Maverick.
Gracias otra vez.
Thank you very much. I had tried installing the package “python-software-properties” from Maverick, not the Squeeze package. Is where the command “apt-add-repository”, but does not work.
One suggestion: The script would be better placed in /usr/sbin and changed Lucid for Maverick.
Thanks again.
January 4th, 2011 at 4:38 pm
@miguel at this point i am working on 10.04 i.e. lucid so i made this with same in mind.
I might add an optional parameter that could be used to specify distribution code name.
Thanks for the praise.
January 4th, 2011 at 4:39 pm
@Ingalex good one buddy, this would be a good tool
however we can also work on gui version’s of both.
January 6th, 2011 at 1:41 pm
[...] Para añadir y poder trabajar con add-apt-repository vamos a utilizar un script creado por Anant Shrivastava. [...]
January 9th, 2011 at 1:46 am
[...] to set as an argument the Ubuntu version you think your Debian system is closer to. Thanks to Anant Shirvastava, as this function uses the code in his [...]
January 11th, 2011 at 3:50 am
Upon apt-get update I get this error:
GPG error: http://ppa.launchpad.net lucid Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 4EA3A911D48B8E25
January 21st, 2011 at 10:12 pm
now thats what i’m talking bout!
February 16th, 2011 at 4:00 am
great tool – thank you so much!!
February 20th, 2011 at 4:25 am
Why am I getting a 404 error when I attempt to wget-retrieve your script?
February 20th, 2011 at 10:46 am
Wget is now enabled, you can download the file.
March 16th, 2011 at 8:37 pm
works like a charm
March 26th, 2011 at 7:26 pm
It should be:
sudo chmod o+x /usr/sbin/add-apt-repository
(sbin)
and:
sudo chown root:root /usr/sbin/add-apt-repository
April 22nd, 2011 at 1:19 am
Thank you.
May 6th, 2011 at 1:51 am
Hello,
Good job !
June 6th, 2011 at 1:42 am
from my playing around with add-apt-repository I made a few changes so your script will do the same. add-apt-repository adds both deb & deb-src in sources.list.d for the ppa, and also adds deb & deb-src lines in sources.list for other repositories. I also changed so it automatically handles ubuntu versions – need a way to establish non-ubuntu version equivilancies.
#!/bin/bash
add_key ()
{
apt-get update >> /dev/null 2> /tmp/apt_add_key.txt
key=`cat /tmp/apt_add_key.txt | cut -d”:” -f6 | cut -d” ” -f3`
apt-key adv –keyserver keyserver.ubuntu.com –recv-keys $key
rm -rf /tmp/apt_add_key.txt
}
cmd_line=”sudo $0 ppa:/”
# needs to be run with sudo
ROOT_UID=0
if [[ "$UID" -ne "$ROOT_UID" ]];
then
echo “Please run the script with sudo (eg: $cmd_line)”
exit
fi
if [[ $# -eq 1 ]]
then
ppa_name=${1:4}
LINUX_DISTRIBUTION=`lsb_release -is`
LINUX_CODENAME=`lsb_release -cs`
case $LINUX_DISTRIBUTION in
“debian” ) case $LINUX_CODENAME in
squeeze ) LINUX_CODENAME=”lucid”;;
* ) echo “not set up for this version yet”
exit;;
esac
* ) echo “not set up for this distro yet”
exit;;
esac
case “${1:0:4}” in
“deb ” ) echo “deb $ppa_name”
if [[ -f "/etc/apt/sources.list.save" ]]
then
rm -f “/etc/apt/sources.list.save”
fi
cp “/etc/apt/sources.list” “/etc/apt/sources.list.save”
echo “deb $ppa_name” >> /etc/apt/sources.list
echo “deb-src $ppa_name” >> /etc/apt/sources.list
add_key;;
“ppa:” ) echo “$ppa_name”
ppa_list=”$ppa_name`lsb_release -cs`.list”
if [[ -f "$ppa_list" ]]
then
if [[ -f "$ppa_list.save" ]]
then
rm -f “$ppa_list.save”
fi
mv “$ppa_list” “$ppa_list.save”
fi
echo “deb http://ppa.launchpad.net/$ppa_name/ubuntu $LINUX_CODENAME main” >> /etc/apt/sources.list.d/”$ppa_list”
echo “deb-src http://ppa.launchpad.net/$ppa_name/ubuntu $LINUX_CODENAME main” >> /etc/apt/sources.list.d/”$ppa_list”
add_key;;
* ) echo “PPA name not found”
echo “Utility to add PPA repositories in your debian machine”
echo “$cmd_line”;;
esac
else
echo “Utility to add PPA repositories in your debian machine”
echo “$cmd_line”
fi
June 6th, 2011 at 12:47 pm
Good one buddy.
right now at office will update my own script later tonight….
June 7th, 2011 at 6:17 pm
[...] решение. Один добрый человек написал скрипт и выложил статью. В двух словах что надо сделать – для начала [...]
June 26th, 2011 at 3:31 pm
[...] git-ftp. Si installa su Mac,Win e Linux. Per installare il pacchetto su debian, consiglio di aggiungere il ppa ubuntu dello sviluppatore ed importare la chiave in modo da avere sempre il pacchetto [...]
July 13th, 2011 at 11:19 pm
Works great! Thanks a lot
August 6th, 2011 at 5:25 pm
Security flaw: This script will use a fixed name in /tmp, so it may be abused to overwrite any file in the system. Use mktemp.
August 6th, 2011 at 11:33 pm
nice find.
updated the script to create file using a random string. randomization seed taken from machine details uname -a and date which should i think be sufficient for randomization in this case.
August 29th, 2011 at 12:34 am
My friend referred me to your site, so I thought I’d come have a read. Very interesting insights, will be back for more!
September 1st, 2011 at 1:20 am
Wont’ work for me… still have command not found! Can anybody help?
September 2nd, 2011 at 11:53 am
I have sent a mail to you please check and respond back so that we can sort the error out. will post if any update or changes need to be done.
September 3rd, 2011 at 2:07 am
Thanks it worked fine for me.
September 18th, 2011 at 7:01 pm
I had to change the third step to read “/usr/sbin/” rather than “/usr/bin” before this worked for me.
September 19th, 2011 at 5:10 pm
thanks for pointing that out steps corrected.
September 30th, 2011 at 8:12 pm
Works great for adding the bisigi themes in on Debian Squeeze. Thanks for the script!
September 30th, 2011 at 8:33 pm
[...] PPA repositories into your Debian squeeze or wheezy install? Anantshri has you covered with a quick shell script. Note that it may break your installation horribly and kill puppies [...]
October 16th, 2011 at 2:29 pm
[...] install from source or add a PPA repository so you can manage the install with “apt”. The script here will allow you to add a Ubuntu PPA to your Debian install. N.B Debian intentionally runs [...]
November 5th, 2011 at 10:19 pm
worked great on debian squeeze just finally added wine 1.3 Thanks
November 22nd, 2011 at 8:33 am
Worked perfect in Linux Mint Debian 2011. Thanks!
November 28th, 2011 at 5:14 pm
Excelent! works like a charm!
December 12th, 2011 at 8:40 am
Thank You! This solved my problem. I’m using debian squeeze.
January 4th, 2012 at 5:40 am
Thank you so mach for your job!
Now i can use W.I.N.E. on my Wheezy from Ubuntu-PPA!
Russian-Linuxoid´s last [type] ..Re: Первый раз на Debian после Ubuntu
January 13th, 2012 at 2:16 am
Very helpful!!! I’m still Linux newbie with Unix background too many years ago. Started with Ubuntu and working my way up to the mother ship
One thing that confuses me about your great script is comments that say makes too easy to install Ubuntu packages on Debian, which, to paraphrase some posts “would be very very bad, as it will destroy your computer, angry the gods & will join the hordes of Foolish People languishing in Linux Hell.” So, it would seem that those installing Wine from Ubuntu Repositories deserve our sympathies.
January 16th, 2012 at 2:40 pm
as I already said in disclaimer Ubuntu and debian not 100%binary compatible so issues will be there
January 18th, 2012 at 10:58 am
I got this error when I ran “sudo add-apt-repository ppa:chromium-beta” and moved to script to bin instead of sbin and it worked.
Traceback (most recent call last):
File “/usr/bin/add-apt-repository”, line 65, in
if not sp.add_source_from_line(line):
File “/usr/lib/python2.6/dist-packages/softwareproperties/SoftwareProperties.py”, line 630, in add_source_from_line
(deb_line, file) = expand_ppa_line(line.strip(), self.distro.codename)
File “/usr/lib/python2.6/dist-packages/softwareproperties/ppa.py”, line 47, in expand_ppa_line
sourceslistd = apt_pkg.Config.find_dir(“Dir::Etc::sourceparts”)
AttributeError: ‘module’ object has no attribute ‘Config’
January 19th, 2012 at 4:20 pm
[...] an alternative, you can add your own add-apt-repository program following these instructions. This entry was posted in Linux by bhall. Bookmark the [...]
January 22nd, 2012 at 1:58 am
Con este script puede elegir de que distribución de Ubuntu quieres el repositorio
#!/bin/bash
if [ $# -eq 1 ]
NM=`uname -a && date`
NAME=`echo $NM | md5sum | cut -f1 -d” “`
then
PPA_NAME=`echo “$1″ | cut -d”:” -f2 -s`
if [ -z "$PPA_NAME" ]
then
echo “Nombre del PPA no encontrado”
echo “Utilidad para agregar ppa a tu Debian”
echo “$0 ppa:user/ppa-name”
else
echo “Seleccione la versión de ubuntu que quieres:”
select UBUNTU_VERSION in lucid maverick natty oneiric precise
do
case $UBUNTU_VERSION in
“lucid”)
break
;;
“maverick”)
break
;;
“natty”)
break
;;
“oneiric”)
break
;;
“precise”)
break
;;
*)
echo “Elija una versión correcta”
;;
esac
done
echo “Eligió $UBUNTU_VERSION”
echo “Se esta agregando el ppa de $PPA_NAME”
echo “” >> /etc/apt/sources.list
echo “# $PPA_NAME” >> /etc/apt/sources.list
echo “deb http://ppa.launchpad.net/$PPA_NAME/ubuntu $UBUNTU_VERSION main” >> /etc/apt/sources.list
apt-get update >> /dev/null 2> /tmp/${NAME}_apt_add_key.txt
key=`cat /tmp/${NAME}_apt_add_key.txt | cut -d”:” -f6 | cut -d” ” -f3`
apt-key adv –keyserver keyserver.ubuntu.com –recv-keys $key
rm -rf /tmp/${NAME}_apt_add_key.txt
fi
else
echo “Utilidad para agregar ppa a tu Debian”
echo “$0 ppa:user/ppa-name”
fi