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


















edmond says:
great job, may be useful
January 1, 2011, 10:03 pmCome aggiungere PPA in Debian | EDMOND'S WEBLOG says:
[...] command not found, quindi non è possibile aggiungerli…..anzi è possibile, anche se sconsigliato. Comunque per chi vuole avere anche questa possibilità sulla propria [...]
January 1, 2011, 10:10 pmanantshri says:
@edmond.
Thanks for the link back.
sharing and helping is the only reason of putting this on blog.
January 2, 2011, 10:22 amIngalex says:
Here you can find the script to remove repository and gpg key:
January 2, 2011, 6:24 pmhttp://www.sourceslist.eu/guide/script-remove-apt-repository/
Miguel K3b says:
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 4, 2011, 9:44 amanantshri says:
@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 4, 2011, 4:38 pmanantshri says:
@Ingalex good one buddy, this would be a good tool
however we can also work on gui version’s of both.
January 4, 2011, 4:39 pmAñadir add-apt-repository a LMDE y Debian Squeeze « Gnometips says:
[...] Para añadir y poder trabajar con add-apt-repository vamos a utilizar un script creado por Anant Shrivastava. [...]
January 6, 2011, 1:41 pmDebian: script to manipulate apt sources quickly from the command line « Elric's random thoughts in idle times says:
[...] 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 9, 2011, 1:46 amresuni says:
Upon apt-get update I get this error:
January 11, 2011, 3:50 amGPG error: http://ppa.launchpad.net lucid Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 4EA3A911D48B8E25
peter shmied says:
now thats what i’m talking bout!
January 21, 2011, 10:12 pmjohn says:
great tool – thank you so much!!
February 16, 2011, 4:00 amMinus says:
Why am I getting a 404 error when I attempt to wget-retrieve your script?
February 20, 2011, 4:25 amanantshri says:
Wget is now enabled, you can download the file.
February 20, 2011, 10:46 ammitvitaminen says:
works like a charm
March 16, 2011, 8:37 pmMelroy van den Berg says:
It should be:
sudo chmod o+x /usr/sbin/add-apt-repository
(sbin)
and:
March 26, 2011, 7:26 pmsudo chown root:root /usr/sbin/add-apt-repository
liquid says:
Thank you.
April 22, 2011, 1:19 amQuentin THEURET says:
Hello,
Good job !
May 6, 2011, 1:51 amRobert says:
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 ]]
June 6, 2011, 1:42 amthen
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
anantshri says:
Good one buddy.
right now at office will update my own script later tonight….
June 6, 2011, 12:47 pmDebian: добавляем add-apt-repository – Unix4Me says:
[...] решение. Один добрый человек написал скрипт и выложил статью. В двух словах что надо сделать – для начала [...]
June 7, 2011, 6:17 pmgit-ftp e alias « itora web says:
[...] 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 [...]
June 26, 2011, 3:31 pmsuzanne says:
Works great! Thanks a lot :-)
July 13, 2011, 11:19 pm7eggert says:
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 6, 2011, 5:25 pmanantshri says:
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 6, 2011, 11:33 pmEddy Fritz says:
My friend referred me to your site, so I thought I’d come have a read. Very interesting insights, will be back for more!
August 29, 2011, 12:34 ammartin says:
Wont’ work for me… still have command not found! Can anybody help?
September 1, 2011, 1:20 amanantshri says:
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 2, 2011, 11:53 amBox says:
Thanks it worked fine for me.
September 3, 2011, 2:07 amCraig says:
I had to change the third step to read “/usr/sbin/” rather than “/usr/bin” before this worked for me.
September 18, 2011, 7:01 pmanantshri says:
thanks for pointing that out steps corrected.
September 19, 2011, 5:10 pmInhibit says:
Works great for adding the bisigi themes in on Debian Squeeze. Thanks for the script!
September 30, 2011, 8:12 pmDoomBook » Blog Archive » Using PPA Repositories with Debian add-apt-repository Script says:
[...] 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 [...]
September 30, 2011, 8:33 pmAdd a ppa archive to Debian « LAMPish tidbits says:
[...] 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 [...]
October 16, 2011, 2:29 pmTenrousei says:
worked great on debian squeeze just finally added wine 1.3 Thanks
November 5, 2011, 10:19 pmSanbor says:
Worked perfect in Linux Mint Debian 2011. Thanks!
November 22, 2011, 8:33 amMelkor says:
Excelent! works like a charm!
November 28, 2011, 5:14 pmTodd says:
Thank You! This solved my problem. I’m using debian squeeze.
December 12, 2011, 8:40 amRussian-Linuxoid says:
Thank you so mach for your job!
January 4, 2012, 5:40 amNow i can use W.I.N.E. on my Wheezy from Ubuntu-PPA!
Russian-Linuxoid´s last [type] ..Re: Первый раз на Debian после Ubuntu
Ben says:
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 13, 2012, 2:16 amanantshri says:
as I already said in disclaimer Ubuntu and debian not 100%binary compatible so issues will be there
January 16, 2012, 2:40 pmEly says:
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):
January 18, 2012, 10:58 amFile “/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’
Adding Ubuntu PPAs to Debian Squeeze 6.0 | GoSaBe Blog says:
[...] 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 19, 2012, 4:20 pmChristopher says:
Con este script puede elegir de que distribución de Ubuntu quieres el repositorio
#!/bin/bash
January 22, 2012, 1:58 amif [ $# -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
Nicholas says:
I found that this worked flawlessly when I right-clicked and downloaded the file instead of using wget. I also had no luck in updating the script to use oneric instead of lucid. it works great, though! well done!
March 4, 2012, 7:28 amRob says:
Thank you so much for sharing this! You rock.
March 5, 2012, 3:57 pmSander says:
Thank you for sharing this steps. I’ve been figuring out how to install PPA to a debian for the longest time. I tried the steps you suggested and it worked for me. Your article is very helpful.
March 8, 2012, 7:35 amSander´s last [type] ..Making music with the right beat making software
Cara Menambah PPA di Debian says:
[...] to Anant Shrivastava No related content [...]
March 25, 2012, 3:10 pmIndrajit Saha says:
I tried your script in debian squeeze 6.0.3 to install e17 from hannes zanetjeck enlightenment ppa. It hanged the terminal. Ultimately I did it by the method given in http://www.khattam.info/howto-add-launchpad-ubuntu-ppa-in-debian-squeeze-testing-2010-11-13.html … it worked nicely by manually adding the repo key.
March 31, 2012, 8:58 amLorrin Nelson says:
Works great (Debian Squeeze), thanks. Maybe /usr/local/sbin would be a better place for it than /usr/sbin?
April 6, 2012, 11:54 amJohnAdled says:
Excellent post! Really loved it, havent seen an artice this good in a while.
April 21, 2012, 2:29 am