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 https://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
great job, may be useful
Pingback: Come aggiungere PPA in Debian | EDMOND'S WEBLOG
@edmond.
Thanks for the link back.
sharing and helping is the only reason of putting this on blog.
Here you can find the script to remove repository and gpg key:
http://www.sourceslist.eu/guide/script-remove-apt-repository/
@Ingalex good one buddy, this would be a good tool
however we can also work on gui version’s of both.
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.
@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.
Pingback: Aรฑadir add-apt-repository a LMDE y Debian Squeeze « Gnometips
Pingback: Debian: script to manipulate apt sources quickly from the command line « Elric's random thoughts in idle times
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
now thats what i’m talking bout!
great tool – thank you so much!!
Why am I getting a 404 error when I attempt to wget-retrieve your script?
Wget is now enabled, you can download the file.
works like a charm
It should be:
sudo chmod o+x /usr/sbin/add-apt-repository
(sbin)
and:
sudo chown root:root /usr/sbin/add-apt-repository
Thank you.
Hello,
Good job !
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
Good one buddy.
right now at office will update my own script later tonight….
Pingback: Debian: ะดะพะฑะฐะฒะปัะตะผ add-apt-repository – Unix4Me
Pingback: git-ftp e alias « itora web
Works great! Thanks a lot ๐
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.
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.
My friend referred me to your site, so I thought Iโd come have a read. Very interesting insights, will be back for more!
Wont’ work for me… still have command not found! Can anybody help?
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.
Thanks it worked fine for me.
I had to change the third step to read “/usr/sbin/” rather than “/usr/bin” before this worked for me.
thanks for pointing that out steps corrected.
Works great for adding the bisigi themes in on Debian Squeeze. Thanks for the script!
Pingback: DoomBook » Blog Archive » Using PPA Repositories with Debian add-apt-repository Script
Pingback: Add a ppa archive to Debian « LAMPish tidbits
worked great on debian squeeze just finally added wine 1.3 Thanks
Worked perfect in Linux Mint Debian 2011. Thanks!
Excelent! works like a charm!
Thank You! This solved my problem. I’m using debian squeeze.
Thank you so mach for your job!
Now i can use W.I.N.E. on my Wheezy from Ubuntu-PPA!
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.
as I already said in disclaimer Ubuntu and debian not 100%binary compatible so issues will be there
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’
Pingback: Adding Ubuntu PPAs to Debian Squeeze 6.0 | GoSaBe Blog
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
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!
Thank you so much for sharing this! You rock.
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.
Pingback: Cara Menambah PPA di Debian
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.
Works great (Debian Squeeze), thanks. Maybe /usr/local/sbin would be a better place for it than /usr/sbin?
Excellent post! Really loved it, havent seen an artice this good in a while.
Cool: it works on my Raspi / Raspberry Pi with Debian squeeze.
Thank you!
thanks ๐ now i can easily install pidgin ๐ haha:)
Hi, nice job your script
i’m currently trying a debian, but due to driver issues i need a ppa. Your script seems to be the trick and indeed allowed me to add the ppa, but when i try to update the way i would with ubuntu, i got this :
root@centime-crunchbang:/home/centime/downloads# apt-get update | grep cedar
Ign http://ppa.launchpad.net/sarvatt/cedarview/ubuntu/ lucid/main Translation-en
Ign http://ppa.launchpad.net/sarvatt/cedarview/ubuntu/ lucid/main Translation-fr
W: Impossible de rรฉcupรฉrer http://ppa.launchpad.net/sarvatt/cedarview/ubuntu/dists/lucid/main/binary-i386/Packages.gz 404 Not Found
any idea of what i sould do to make it work ?
thanks a lot !
my script was based on previous LTS release now your repository which you added don’t have any package for lucid.
you can do one simple thing edit /etc/apt/sources.lst and modify the line which says this and find lucid repalce to precise that should solve your problem.
Pingback: Repositories and ppa's
Thank-you for the very useful script.
I made some changes and have some critique, hope you don’t mind!
Your “security fix” for temp files does not work.
Mallory can run your code with `date -d ‘100 seconds’`, etc.
It is not a good idea to ‘roll your own security’.
You could do what the guy said, use mktemp:
tmpfile=`mktemp /tmp/apt_add_key.XXXXXXXXXX.txt`
echo $tmpfile
/tmp/apt_add_key.NKBIape16r.txt
You don’t actually need that file:
key=`apt-get update 2>&1 >/dev/null | cut -d”:” -f6 | cut -d” ” -f3`
This might be a better way to list unknown key/s:
apt-get update 2>&1 >/dev/null | sed -n ‘/NO_PUBKEY/s/.* //p’
But there is another security problem.
You are installing keys automatically based on error messages and unsecured channels, this undermines the security that these keys are supposed to provide. It’s vulnerable to a ‘man in the middle’ attack.
Instead, we can look up the keys on https://launchpad.net/, which is fairly safe.
I posted a modified and over-engineered^Whacked version of your script.
sswam.net/b/apt-ppa-debian
My script got a bit too long, probably shouldn’t do this sort of thing in bash!
probably has it’s own host of bugs and security faults….!
Have fun.
Your script still has some security bugs with temp files and adding a key based on data from insecure http,
I revised it here: http://sam.nipl.net/b/apt-ppa-debian See also: http://sam.nipl.net/b/wine-debian-squeeze
“/usr/sbin”.
Gracias…
Pingback: Fix for missing apt-add-repository in Debian
Pingback: ZFS (+Full Disk Encryption) on Debian in 15 Minutes! · Matt's Life Bytes
Pingback: Is it safe to install Ubuntu packages on Debian?
Thank you SO much, this is priceless! Bookmarked and will link on my blog in an upcoming post.
Thanks a lot works great
Tested in debian with the smplayer ppa ๐
/usr/local/sbin would be a better place for it than /usr/sbin for sure on wheezy ……..
Thanks for the tip, will check. this code at this point is a very old release there are couple of other things also that need to be secured, plus as and when i get time i will shift the code to github so that anyone can modify and suggest changes directly.
Thanks so much. Very useful script and great installation instructions! It’s a no-brainer ๐
Hi,
you should’nt add the sources to /etc/apt/sources.list
instead, create a file in /etc/apt/sources.list.d/.list
It’s not a good approach to write custom sources directly into the /etc/apt/sources.list in general as this file might be managed through services (i.e. puppet)
regards,
bert
Hi Bert,
I agree with you. But right now in middle of a hectic week. hopefully next week i will update the script.
sorry, I meant /etc/apt/sources.list/PPANAME.list
Thanks this helped me get some packages I needed installed on my hosted Debian 6.0 minimal install server.
For make it work today you only have to change “lucid” for “xenial”. Thank you for info and links ๐
IT WORKS on newest Jeesie. Great Job.
Thank you very much, worked perfect in LMDE 5. Just change the line 14 for my needs and preferences to this:
echo “deb http://ppa.launchpad.net/$ppa_name/ubuntu focal main” >> /etc/apt/sources.list.d/ppa-fix.list