我们正在使用我们自己的 Ubuntu 软件包存储库,我需要一种方法来检查存储库是否真的在每个工作站上使用。我可以使用apt-cache policy|grep 'our-repository-address',但我的一些同事不喜欢它,因为“grep”。这对他们来说看起来像是一个不可靠的黑客......这个检查还有其他方法还是apt-cache policy|grep 'our-repository-address'很标准?
您必须单独检查存储库提供的每个包。
如果包只是本地重建并且版本字符串与另一个存储库中的版本字符串相同,则必须手动检查/var/lib/dpkg/info/PACKAGE.md5sums中的 md5sums (如果包不编译任何内容并且存储库结构没有不同)没有办法澄清来源)。
如果版本字符串不同,您可以使用以下代码片段:
#!/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()
Run Code Online (Sandbox Code Playgroud)
用法script PACKAGELIST例如:
script /var/lib/apt/lists/ftp.debian.org_debian_dists_experimental_main_binary-amd64_Packages
Run Code Online (Sandbox Code Playgroud)
您还必须调整本地存档的组件、存档等(请参阅下面的相关发布文件/var/lib/apt/lists)。
如果安装了软件包但不是从您的存储库安装的,您将获得软件包名称 - 如果没有安装,一切都很好。
我假设,您已经知道这样一个事实:如果您希望使用您的存储库而不是默认的 Ubuntu 存储库,您应该将您的存储库行放在/etc/sources.list文件的顶部。这是一个问题和答案。
如果您已经将存储库放在“sources.list”文件的顶部,您可以检查软件包安装是否--print-uris在命令中使用 switch apt-get,如下所示
sudo apt-get install scribes --print-uris
Run Code Online (Sandbox Code Playgroud)
此命令在我的机器中返回以下结果(我还有一个小型本地存储库)
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
Run Code Online (Sandbox Code Playgroud)
最后两行清楚地表明用于所需两个文件的存储库。
希望这可以帮助解决您的问题。
| 归档时间: |
|
| 查看次数: |
4060 次 |
| 最近记录: |