giterlizzi / perl-URI-PackageURL

Perl extension for Package URL
Artistic License 2.0
4 stars 1 forks source link

Add options to "purl-tool(1)" for create canonical "purl" from CLI #9

Closed giterlizzi closed 12 months ago

giterlizzi commented 12 months ago

Add options to "purl-tool(1)" for create canonical "purl" from CLI.

purl-tool --type cpan \
          --namespace SRI \
          --name Mojolicious \
          --version 9.35

pkg:cpan/SRI/Mojolicious@9.35

This is useful for create on-the-fly "purl" from scripts.

#!bash

# rpm-to-purl - Convert all installed RPM packags in purl string

# (C) 2023, Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
# License MIT

. /etc/os-release

PACKAGES=$(rpm -qa --qf '%{NAME}\t%{VERSION}-%{RELEASE}\t%{ARCH}\n')

while IFS= read -r LINE; do

  PKG_NAME=$(echo $LINE | cut -d ' ' -f1)
  PKG_VER=$(echo $LINE | cut -d ' ' -f2)
  PKG_ARCH=$(echo $LINE | cut -d ' ' -f3)

  purl-tool --type rpm \
            --namespace $ID \
            --name $PKG_NAME \
            --version $PKG_VER \
            --qualifier distro=$ID-$VERSION_ID \
            --qualifier arch=$PKG_ARCH

done <<< "$PACKAGES"