Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

For both 10.04 LTS and 12.04 LTS, is there a way check to see if a source is in /etc/apt/sources.list from a bash script, other than using grep?

share|improve this question
2  
Why is grep out of the question? Does this repo you are looking for have a unique package? If so you could do "apt-cache search mypackage". –  reverendj1 May 22 '12 at 19:14
    
I don't mind using grep. I am relatively new to being an admin on an Ubuntu box (much more used to how Slackware does things) and I wanted to make sure there wasn't something within the apt/dpkg suite of tools that would be better suited. The "apt-cache search" may work for one repo, but I don't think it will for the other one. –  Lee Lowder May 22 '12 at 19:19
    
That makes sense. I don't think there is any built-in mechanism to list/check what repos are configured. One thing to point out, you should always create a new repo.list file for any extra repos in /etc/apt/sources.list.d, instead of putting them directly to /etc/apt/sources.list. It is a little safer, and makes it much neater. Maybe that could also be how you check for them to exist. –  reverendj1 May 22 '12 at 19:30
add comment

2 Answers

apt-cache policy shows all available sources. Example output (trimmed):

Package files:
 100 /var/lib/dpkg/status
     release a=now
 500 http://ppa.launchpad.net/lekensteyn/wacom-tablet/ubuntu/ precise/main i386 Packages
     release v=12.04,o=LP-PPA-lekensteyn-wacom-tablet,a=precise,n=precise,l=Wacom Tablet Drivers,c=main
     origin ppa.launchpad.net
 500 http://ppa.launchpad.net/lekensteyn/wacom-tablet/ubuntu/ precise/main amd64 Packages
     release v=12.04,o=LP-PPA-lekensteyn-wacom-tablet,a=precise,n=precise,l=Wacom Tablet Drivers,c=main
     origin ppa.launchpad.net
 500 http://ppa.launchpad.net/bumblebee/testing/ubuntu/ precise/main i386 Packages
     release v=12.04,o=LP-PPA-bumblebee-testing,a=precise,n=precise,l=Bumblebee Developer releases,c=main
     origin ppa.launchpad.net
 500 http://ppa.launchpad.net/bumblebee/testing/ubuntu/ precise/main amd64 Packages
     release v=12.04,o=LP-PPA-bumblebee-testing,a=precise,n=precise,l=Bumblebee Developer releases,c=main
     origin ppa.launchpad.net
 500 http://archive.canonical.com/ubuntu/ precise/partner i386 Packages
     release v=12.04,o=Canonical,a=precise,n=precise,l=Partner archive,c=partner
     origin archive.canonical.com
...
 500 http://nl.archive.ubuntu.com/ubuntu/ precise/main Translation-nl
 500 http://nl.archive.ubuntu.com/ubuntu/ precise/main Translation-en
 500 http://nl.archive.ubuntu.com/ubuntu/ precise/multiverse i386 Packages
     release v=12.04,o=Ubuntu,a=precise,n=precise,l=Ubuntu,c=multiverse
     origin nl.archive.ubuntu.com
 500 http://nl.archive.ubuntu.com/ubuntu/ precise/universe i386 Packages
     release v=12.04,o=Ubuntu,a=precise,n=precise,l=Ubuntu,c=universe
     origin nl.archive.ubuntu.com
 500 http://nl.archive.ubuntu.com/ubuntu/ precise/restricted i386 Packages
     release v=12.04,o=Ubuntu,a=precise,n=precise,l=Ubuntu,c=restricted
     origin nl.archive.ubuntu.com
 500 http://nl.archive.ubuntu.com/ubuntu/ precise/main i386 Packages
     release v=12.04,o=Ubuntu,a=precise,n=precise,l=Ubuntu,c=main
     origin nl.archive.ubuntu.com
 500 http://nl.archive.ubuntu.com/ubuntu/ precise/multiverse amd64 Packages
     release v=12.04,o=Ubuntu,a=precise,n=precise,l=Ubuntu,c=multiverse
     origin nl.archive.ubuntu.com
 500 http://nl.archive.ubuntu.com/ubuntu/ precise/universe amd64 Packages
     release v=12.04,o=Ubuntu,a=precise,n=precise,l=Ubuntu,c=universe
     origin nl.archive.ubuntu.com
 500 http://nl.archive.ubuntu.com/ubuntu/ precise/restricted amd64 Packages
     release v=12.04,o=Ubuntu,a=precise,n=precise,l=Ubuntu,c=restricted
     origin nl.archive.ubuntu.com
 500 http://nl.archive.ubuntu.com/ubuntu/ precise/main amd64 Packages
     release v=12.04,o=Ubuntu,a=precise,n=precise,l=Ubuntu,c=main
     origin nl.archive.ubuntu.com
Pinned packages

Using awk to retrieve the actual source (URL or file):

$ apt-cache policy | awk '/^ *[0-9]/{print $2 " " $3}'
/var/lib/dpkg/status 
http://ppa.launchpad.net/lekensteyn/wacom-tablet/ubuntu/ precise/main
http://ppa.launchpad.net/lekensteyn/wacom-tablet/ubuntu/ precise/main
http://ppa.launchpad.net/bumblebee/testing/ubuntu/ precise/main
http://ppa.launchpad.net/bumblebee/testing/ubuntu/ precise/main
...
http://nl.archive.ubuntu.com/ubuntu/ precise/universe
http://nl.archive.ubuntu.com/ubuntu/ precise/restricted
http://nl.archive.ubuntu.com/ubuntu/ precise/main
share|improve this answer
add comment
up vote 0 down vote accepted

I wound up using grep to check the sources.list and also checking in sources.list.dfor the presence of a foo.list.

While not as clean of a solution as I had hoped for, it does the job well enough for what I needed.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.