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?
2 Answers
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:
#!/usr/bin/python
# 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():
try:
pkglist = []
f = open(sys.argv[1], "r")
for line in f:
if re.match('^Package: ', line):
pkglist.append(re.sub('^Package: ', '', line).rstrip('\n'))
f.close()
cache = apt.Cache()
for package in pkglist:
pkg = cache[package]
# check if package is installed
if not pkg.installed:
continue
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
#continue
#else:
# 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")
sys.exit(1)
if __name__ == "__main__":
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.
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:
python-gtksourceview2
Suggested packages:
libgtksourceview2.0-dev
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.
apt-cache
output, then the repo is always enabled. While this is likely to be so, nothing preventsapt-cache
implementation to break that in future. Something likeapt-cache is-repo-enabled repo-address
would be much better.