如何在基于 Debian 的发行版中列出所有已安装软件包的许可证?

How to list licences of all installed packages in Debian-based distros?

我想在我的 Ubuntu 服务器上获得所有已安装的软件包许可证,我可以使用 (this 2013 post):

全部转储
packages=$( dpkg --get-selections | awk '{ print  }' )
for package in $packages; do
  echo "$package: "
  cat /usr/share/doc/$package/copyright
  echo; echo
done > /tmp/licenses.txt
less /tmp/licenses.txt

但是输出是一个巨大的无用文件,其中包含每个包的所有版权数据。我需要这样的东西:

package: package_name        licence: licence_name

是否有解析器或其他工具可以获取这样的数据?

目前您尝试的内容支持不佳,但正在努力在文件 /usr/share/doc/*/copyright 文件中提供 machine-readable 信息。参见示例 this excerpt:

Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: at
Source: git://anonscm.debian.org/collab-maint/at.git
Comment: This package was debianized by its author Thomas Koenig
 <ig25@rz.uni-karlsruhe.de>, taken over and re-packaged first by Martin
 Schulze <joey@debian.org> and then by Siggy Brentrup <bsb@winnegan.de>,
 and then taken over by Ryan Murray <rmurray@debian.org>.
 .
 In August 2009 the upstream development and Debian packaging were taken over
 by Ansgar Burchardt <ansgar@debian.org> and Cyril Brulebois <kibi@debian.org>.
 .
 This may be considered the experimental upstream source, and since there
 doesn't seem to be any other upstream source, the only upstream source.

Files: *
Copyright: 1993-1997,  Thomas Koenig <ig25@rz.uni-karlsruhe.de>
           1993,       David Parsons
           2002, 2005, Ryan Murray <rmurray@debian.org>
License: GPL-2+

Files: getloadavg.c
Copyright: 1985-1995, Free Software Foundation Inc
License: GPL-2+

Files: posixtm.*
Copyright: 1989-2007, Free Software Foundation Inc
License: GPL-3+

Files: parsetime.pl
Copyright: 2009, Ansgar Burchardt <ansgar@debian.org>
License: ISC 

License: GPL-2+
 This program is free software; you can redistribute it
 and/or modify it under the terms of the GNU General Public
 License as published by the Free Software Foundation; either
 version 2 of the License, or (at your option) any later
 version.

有关详细信息,请参阅 http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 中的规范(上面链接)。

如您所见,每个包必须有一个许可证的基本假设是错误的。每个文件 可能有多个许可证 -- 根据您要解决的问题,当然可以忽略其中的许多许可证(例如,如果您想调查是否无论您是否拥有 Apache 许可下的东西,对于已转换为这种新格式的包来说,这应该很容易做到。

这是 Debian Jessie 的新功能,于 2015 年发布;旧版本的 Debian 没有这样的东西。如果您需要审核包含旧软件包的系统,您可以做的最好的事情可能是 grep copyright 文件以查找看起来像 GPL、BSD、MIT 等的片段,然后希望您不会遗漏太多;但是希望在一些脆弱的 grepping 之上似乎对任何适当的法律工作都是一种诅咒,我认为我们可以假设这是你尝试这样做的原因。更好的方法可能是找到您正在审核的包的当前 copyright 文件,其中包含大致 machine-readable 信息,并希望(又是这个词)它们足以满足您拥有的旧版本也安装了。

(为了进行比较,旧版本也可在 http://metadata.ftp-master.debian.org/changelogs/main/a/at/ 获得,供您检查。)

我不再密切关注 Ubuntu,但假设他们在几个版本之前就开始接受这一变化。事实上,http://packages.ubuntu.com/xenial/at 似乎有相同的 copyright 文件。