Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
using the cache to quickly get package info
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
ulenrich
Veteran
Veteran


Joined: 10 Oct 2010
Posts: 1482

PostPosted: Sun Jun 30, 2024 7:02 pm    Post subject: using the cache to quickly get package info Reply with quote

Code:
#!/bin/bash

if [[ "$1" = "--help" ]] ||[[ "$1" = "-h" ]];then
   echo "Search for Gentoo package names, like:"
   echo "$0  /ash  dev/  gcc$  ^sys"
   echo "This makes use of a cache REPOPATHNAME/metadata/pkg_desc_index"
   echo "If your REPO doesn't have the cache, then put an executable at"
   echo "/etc/portage/repo.postsync.d/SCRIPT"
   echo 'having the line:  egencache --update-pkg-desc-index --repo $1'
   exit
fi

function repoLocation() {
   D="";repo="$1"
   conF="/etc/portage/repos.conf/${repo%.conf}.conf"
   [ ! -s "${conF}" ] &&echo "cannot find repository ${repo}" &&return
   D=$(sed -n -e's/#.*//' -e'y/"/ /' -e"y/'/ /"\
    -e'/^location[ =]*/{s_.*=__;s_[[:blank:]]*\(.*\)[[:blank:]]*_\1_p;q}'\
    ${conF})
   [[ -d "$D" ]] &&echo $D
}

dfile=""
for i in /etc/portage/repos.conf/* ;do
   b=$(basename $i)
   L="$(repoLocation $b)/metadata/pkg_desc_index"
   [ -f $L ] \
     &&dfile="${dfile} $L"  \
     ||echo "missing cache, use egencache to create $L" >&2
done
if [[ "${dfile}" = "" ]] ;then
  dfile="/var/db/repos/gentoo/metadata/pkg_desc_index"
  [[ ! -f $dfile ]] \
   &&echo "missing cache - try the egencache tool" \
   &&exit
fi

T=""
while [ "$1" != "" ] ;do
  sed -E -n -e's/ .*$//' -e"\,$1, p"  ${dfile}
  shift
done |sort -u \
  |while read p ;do
    q=$(echo /var/db/pkg/${p}-[0-9]* )
    if [ -d "${q}" ] ;then
      echo -e -n "emerged\t ${q#/var/db/pkg/}   " \
       &&sed -e"s/amd64.*$/amd64/" -e"s/.* //" $q/KEYWORDS
      T=$(cat $q/DESCRIPTION )
      grep -e"^${p} " ${dfile} \
      |sed -e's%^.*/\(.*\)/metadata/pkg_desc_index:%\1\t %' -e's/:.*$//'
    else
      grep -e"^${p} " ${dfile} \
      |sed -e's%^.*/\(.*\)/metadata/pkg_desc_index:%\1\t %' -e's/:/\n\t/'
    fi
    [ "$T" != "" ] \
      &&echo -e -n "\t $T  " \
      &&T="" \
      &&[ -f "$q/HOMEPAGE" ] \
      &&cat $q/HOMEPAGE
     echo ""
  done
exit

Sorry my coding style.
Back to top
View user's profile Send private message
ulenrich
Veteran
Veteran


Joined: 10 Oct 2010
Posts: 1482

PostPosted: Sun Jun 30, 2024 9:24 pm    Post subject: Reply with quote

Output sample:
Code:
$ genlist  app.*/portage
gentoo    app-metrics/portage-exporter 0.1.0
    Prometheus exporter for Gentoo Portage

guru    app-portage/portage-lostfiles 0.5.5
    A simple script to identify files not tracked by Portage package manager

emerged    app-portage/portage-utils-0.96.1   amd64
gentoo    app-portage/portage-utils 0.95-r1 0.96-r1 0.96.1 0.97 9999
    Small and fast Portage helper tools written in C  https://wiki.gentoo.org/wiki/Portage-utils

emerged    sys-apps/portage-3.0.65   ~amd64
gentoo    sys-apps/portage 3.0.61-r1 3.0.63-r1 3.0.64-r3 3.0.65 9999
    The package management and distribution system for Gentoo  https://wiki.gentoo.org/wiki/Project:Portage
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4526
Location: Bavaria

PostPosted: Sun Jun 30, 2024 10:07 pm    Post subject: Reply with quote

Moved from Deutsche Dokumentation to Documentation, Tips & Tricks.

... because it is an english docu.
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum