如何找到系统上安装的所有许可证?

我想编写一个脚本,为我系统上安装的每个软件包输出许可证。

使用dpkg --get-selections我能够获得所有安装的列表。 但是,我没有办法获取每个包的许可证信息。 例如,我可以使用aptitude show来获取每个包的属性,但这不包括许可证:

 $ aptitude show apache2 Package: apache2 State: installed Automatically installed: no Version: 2.2.14-5ubuntu8.6 Priority: optional Section: httpd Maintainer: Ubuntu Developers  Uncompressed Size: 36.9k Depends: apache2-mpm-worker (= 2.2.14-5ubuntu8.6) | apache2-mpm-prefork (= 2.2.14-5ubuntu8.6) | apache2-mpm-event (= 2.2.14-5ubuntu8.6) | apache2-mpm-itk (= 2.2.14-5ubuntu8.6), apache2.2-common (= 2.2.14-5ubuntu8.6) Provided by: apache2-mpm-event, apache2-mpm-itk, apache2-mpm-prefork, apache2-mpm-worker Description: Apache HTTP Server metapackage The Apache Software Foundation's goal is to build a secure, efficient and extensible HTTP server as standards-compliant open source software. The result has long been the number one web server on the Internet. It features support for HTTPS, virtual hosting, CGI, SSI, IPv6, easy scripting and database integration, request/response filtering, many flexible authentication schemes, and more. Homepage: http://httpd.apache.org/ 

是否有第三方存储库将许可证与每个包相关联?

下载每个源包并检查它是否有许可信息听起来很痛苦,但也许这是最好的方法。

这就是我最终做的事情。 (导致~/licenses.txt包含/usr/share/doc中存在的所有许可证)

 $ packages=`dpkg --get-selections | awk '{ print $1 }'` $ for package in $packages; do echo "$package: "; cat /usr/share/doc/$package/copyright; echo ""; echo ""; done > ~/licenses.txt 

2012年,Debian发布了机器可读的debian / copyright文档,将来可以使用许可证。 目前,并非所有包都使用此格式。 命令

 grep -h '^License:' /usr/share/doc/*/copyright | sort -i | uniq -ic | sort -n 

仍然会返回大量垃圾。 为了获得更好的输出,您可能需要一个工具来解析每个文件,具体取决于Format:字段值。

一种完全不同的方式是/usr/share/common-licenses/的文件结构(thx到https://stackoverflow.com/questions/1884753/license-info-of-a-deb-package#1884785 )。 它列出了基于debian的发行版中使用的主要许可证(并包含其许可证文本)。 这个列表由包base-files提供,并没有链接到已安装包的列表,但它可能是普通老板/客户的足够信息。

 ls /usr/share/common-licenses/ Apache-2.0 BSD GFDL-1.2 GPL GPL-2 LGPL LGPL-2.1 Artistic GFDL GFDL-1.3 GPL-1 GPL-3 LGPL-2 LGPL-3 

更新我刚刚发布了一个简单的命令行解决方案,该解决方案通过大量的启发式方法从版权文件中提取许可证信息。 https://github.com/daald/dpkg-licenses 。 随意试试吧。 欢迎任何建议。

我只是偶然发现了dpkg-licenses( https://github.com/daald/dpkg-licenses )。

只需克隆回购

git clone https://github.com/daald/dpkg-licenses.git

然后

./dpkg-licenses> licenses.txt

并且您拥有当今最好的软件安装,版本和许可表格列表,您可以梦想……