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.

We are using our own repository for Ubuntu packages, and I need a way to check if the repository is really used on each workstation. I can use apt-cache policy|grep 'our-repository-address', but some of my colleagues don't like it because of "grep". It looks like an unreliable hack to them... Is there other way for this check or apt-cache policy|grep 'our-repository-address' is quite standard?

share|improve this question

migrated from stackoverflow.com Dec 29 '11 at 13:17

This question came from our site for professional and enthusiast programmers.

If that command works for you, there is nothing wrong with grep. grep is a standard command and I would show them the output with and without grep and point them to man grep. –  bodhi.zazen Dec 29 '11 at 15:20
Grepping is wrong, because it assumption that if repo address is in apt-cache output, then the repo is always enabled. While this is likely to be so, nothing prevents apt-cache implementation to break that in future. Something like apt-cache is-repo-enabled repo-address would be much better. –  Alexander Gladysh Jan 3 '12 at 20:54

2 Answers 2

You have to check each package provided by repository individually.
If package is only a local rebuild and version string is the same as in another repository you have to check manually md5sums in /var/lib/dpkg/info/PACKAGE.md5sums (if package does not compile anything and repository structures don't differ there is no way to clarify origin).

If version strings differ you can use following code snippet:

# Check original repository of installed packages from list.
# Usage: script PACKAGELIST

import apt
import sys
import re

# set values for local repository
component = "main"
archive = "experimental"
origin = "Debian"
label = "Debian"
site = "ftp.debian.org"

def main():
    pkglist = []
    f = open(sys.argv[1], "r")
    for line in f:
      if re.match('^Package: ', line):
        pkglist.append(re.sub('^Package: ', '', line).rstrip('\n'))

    cache = apt.Cache()
    for package in pkglist:
      pkg = cache[package]

      # check if package is installed
      if not pkg.installed:

      if pkg.installed.origins[0].component != component or \
          pkg.installed.origins[0].archive != archive or \
          pkg.installed.origins[0].origin != origin or \
          pkg.installed.origins[0].label != label or \
          pkg.installed.origins[0].site != site:
        print package
      #  print package + " is in repo."

  except KeyboardInterrupt:
    print "\nShutdown requested...exiting"
  except Exception, e:
    sys.stderr.write("An unecpected exeption was encountered: %s" % str(e) + "\n")

if __name__ == "__main__":

Usage is script PACKAGELIST e.g.:

script /var/lib/apt/lists/ftp.debian.org_debian_dists_experimental_main_binary-amd64_Packages

You also have to adjust component, archive, ... for your local archive (see related Release file under /var/lib/apt/lists).

If package is installed but not from your repository you get package name - everything is fine if not.

share|improve this answer

I assume that, you already know the fact that, If you want your repository being used instead of the default Ubuntu repository, You should put your's repo line on the top of /etc/sources.list file. Here is a question and answer about that topic.

If you already put your repository on the top of "sources.list" file, you can check whether a package installation is using --print-uris switch in the apt-get command, as the following one

sudo apt-get install scribes --print-uris 

This command returns the following result in my machine ( I also have a small local repository)

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
Suggested packages:
The following NEW packages will be installed:
  python-gtksourceview2 scribes
0 upgraded, 2 newly installed, 0 to remove and 634 not upgraded.
Need to get 0 B/1,191 kB of archives.
After this operation, 8,954 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
'file:/media/Main/Linux-Software/Ubuntu/Precise/./precise-debs/python-gtksourceview2_2.10.1-2build1_i386.deb' python-gtksourceview2_2.10.1-2build1_i386.deb 90224 MD5Sum:3db673894b791f8843c3b0dcd8958e38
'file:/media/Main/Linux-Software/Ubuntu/Natty/natty/./scribes_0.4~r910-0ubuntu2_all.deb' scribes_0.4~r910-0ubuntu2_all.deb 1100712 MD5Sum:6555b7060ecd662fe1597724e9846b9c

The last two line clearly indicate the repository being used for the two files needed.

Hope this may help some in your problem.

share|improve this answer

Your Answer


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