Package-Management

如何在 Solaris 11 上以機器可讀格式獲取 pkg 屬性

  • July 16, 2018

我希望能夠(從 shell 腳本中)提取 IPS 包的屬性。基本上,我所追求的資訊與命令中列出的資訊完全相同pkg info,但不幸的是,此命令列出的資訊格式不適合從腳本中讀取。下面的例子:

$ pkg info archiver/gnu-tar
         Name: archiver/gnu-tar
      Summary: GNU version of the tar archiving utility
  Description: Tar is a program for packaging a set of files as a single
               archive in tar format.
     Category: Development/GNU
        State: Installed
    Publisher: solaris
      Version: 1.26
Build Release: 5.11
       Branch: 0.175.0.0.0.2.537
Packaging Date: October 19, 2011 09:11:16 AM
         Size: 1.73 MB
         FMRI: pkg://solaris/archiver/gnu-tar@1.26,5.11-0.175.0.0.0.2.537:20111019T091116Z

我希望有類似的東西pkg get-property pkg.summary archiver/gnu-tar可以作為命令使用,但找不到這樣的命令。我真的很討厭嘗試解析上述輸出。其次,手冊頁明確指出,輸出pkg info是供人閱讀的,而不是機器閱讀的。

大多數pkg info報告來自包中定義包屬性和其他元數據的設置操作。對於您的歸檔器/gnu-tar 範例:

% pkg contents -t set -o name,value archiver/gnu-tar
NAME                          VALUE
info.classification           org.opensolaris.category.2008:Development/GNU
info.source-url               http://ftp.gnu.org/gnu/tar/tar-1.26.tar.bz2
info.upstream-url             http://www.gnu.org/software/tar/
org.opensolaris.arc-caseid    PSARC/2000/488
org.opensolaris.consolidation userland
pkg.description               Tar is a program for packaging a set of files as a single archive in tar format.
pkg.fmri                      pkg://solaris/archiver/gnu-tar@1.26,5.11-0.175.1.0.0.20.0:20120709T173816Z
pkg.summary                   GNU version of the tar archiving utility
variant.arch                  ['i386', 'sparc']

% pkg contents -H -t set -o value -a name=pkg.summary archiver/gnu-tar
GNU version of the tar archiving utility

引用自:https://unix.stackexchange.com/questions/45599