Howto add PPA in debian

development, GNU / LINUX, scripting Add comments

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

  1. 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)
  2. add the gpg key to the keyring.

Disclaimer

  • This script is at this pointed tested only on one machine. debian Squeeze (mint Flavoured.)

File : add-apt-repository.sh

Steps to install this.

  1. 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

File : add-apt-repository.sh

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

44 Responses to “Howto add PPA in debian”

  1. edmond Says:

    great job, may be useful

  2. Come 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 [...]

  3. anantshri Says:

    @edmond.
    Thanks for the link back.

    sharing and helping is the only reason of putting this on blog.

  4. Ingalex Says:

    Here you can find the script to remove repository and gpg key:
    http://www.sourceslist.eu/guide/script-remove-apt-repository/

  5. 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.

  6. anantshri 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.

  7. anantshri Says:

    @Ingalex good one buddy, this would be a good tool

    however we can also work on gui version’s of both.

  8. Añ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. [...]

  9. Debian: 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 [...]

  10. resuni Says:

    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

  11. peter shmied Says:

    now thats what i’m talking bout!

  12. john Says:

    great tool – thank you so much!!

  13. Minus Says:

    Why am I getting a 404 error when I attempt to wget-retrieve your script?

  14. anantshri Says:

    Wget is now enabled, you can download the file.

  15. mitvitaminen Says:

    works like a charm

  16. Melroy van den Berg Says:

    It should be:
    sudo chmod o+x /usr/sbin/add-apt-repository

    (sbin)

    and:
    sudo chown root:root /usr/sbin/add-apt-repository

  17. liquid Says:

    Thank you.

  18. Quentin THEURET Says:

    Hello,

    Good job !

  19. Robert 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 ]]
    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

  20. anantshri Says:

    Good one buddy.

    right now at office will update my own script later tonight….

  21. Debian: добавляем add-apt-repository – Unix4Me Says:

    [...] решение. Один добрый человек написал скрипт и выложил статью. В двух словах что надо сделать – для начала [...]

  22. git-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 [...]

  23. suzanne Says:

    Works great! Thanks a lot :-)

  24. 7eggert 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.

  25. anantshri 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.

  26. Eddy 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!

  27. martin Says:

    Wont’ work for me… still have command not found! Can anybody help?

  28. anantshri 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.

  29. Box Says:

    Thanks it worked fine for me.

  30. Craig Says:

    I had to change the third step to read “/usr/sbin/” rather than “/usr/bin” before this worked for me.

  31. anantshri Says:

    thanks for pointing that out steps corrected.

  32. Inhibit Says:

    Works great for adding the bisigi themes in on Debian Squeeze. Thanks for the script!

  33. DoomBook » 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 [...]

  34. Add 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 [...]

  35. Tenrousei Says:

    worked great on debian squeeze just finally added wine 1.3 Thanks

  36. Sanbor Says:

    Worked perfect in Linux Mint Debian 2011. Thanks!

  37. Melkor Says:

    Excelent! works like a charm!

  38. Todd Says:

    Thank You! This solved my problem. I’m using debian squeeze.

  39. Russian-Linuxoid Says:

    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

  40. 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.

  41. anantshri Says:

    as I already said in disclaimer Ubuntu and debian not 100%binary compatible so issues will be there

  42. Ely 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):
    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’

  43. 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 [...]

  44. Christopher Says:

    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

Leave a Reply

CommentLuv badge