You are not logged in.

#1 2011-09-25 19:01:37

jiggpig
Member
Registered: 2011-01-07
Posts: 6

[SOLVED] Getting PKGBUILD Path from Package name

Anyone know of a reliable way to get the path to a package's PKGBUILD file in the ABS using the package's name? At first, I tried something like this:

function get-abs-path {
        for repo in core extra community multilib
        do
                if [ -r /var/abs/$repo/$1 ]; then
                        echo /var/abs/$repo/$1/PKGBUILD
                fi
        done
}

The problem with this is that it does not handle split packages correctly. The PKGBUILDs for packages such as gcc-libs, compiz-core etc cannot be located this way because they reside in a different package's PKGBUILD.

The only thing that I have thought up so far would be to scan each and every package in the ABS and generate a database of the paths - that has its own issues though. (Its slow, and parsing the PKGBUILD files correctly for their names is not exactly easy).

Any ideas?

Edit: Marked as solved.

Last edited by jiggpig (2011-09-26 02:43:27)

Offline

#2 2011-09-25 19:44:18

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Getting PKGBUILD Path from Package name

Commonly asked question with no good answer. Go with the database idea. I suggest building an associative array of 'array[split] => provider' which can be sourced and used as a lookup table.

Offline

#3 2011-09-25 20:04:12

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Getting PKGBUILD Path from Package name

Mmmm so this sort of piqued my interest. I tried this a while ago, but was bent on not sourcing the PKGBUILDs which made my life hell, didn't quite work, etc etc, threw it away...

#!/bin/bash

. /etc/makepkg.conf
{
  echo "declare -A splitpkgdb"
  for p in "/var/abs/*/*/PKGBUILD; do
    (
      pkgdir=${p%/PKGBUILD}
      . "$pkgdir/PKGBUILD" 2>/dev/null
      for split in "${pkgname[@]}"; do
        printf "splitpkgdb[%s]=%s\n" "$split" "${pkgdir##*/}"
      done
    )
  done | sort -u
} >db

The outfile 'db' should be about 5400 lines and is ready for sourcing by a calling application. One design decision worth noting here is that you only get the provider that the split belongs to. You'll still need to do a repo lookup for the resolved package. This is to avoid clashes with packages existing in multiple repos (e.g. curl might exist in testing and core at the same time).

Last edited by falconindy (2011-09-26 04:01:40)

Offline

#4 2011-09-25 20:18:12

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: [SOLVED] Getting PKGBUILD Path from Package name

This is rather a package creating topic. Moving to Creating & Modifying Packages.


To know or not to know ...
... the questions remain forever.

Offline

#5 2011-09-26 02:40:29

jiggpig
Member
Registered: 2011-01-07
Posts: 6

Re: [SOLVED] Getting PKGBUILD Path from Package name

That works perfectly; thank you, falconindy!

Offline

Board footer

Powered by FluxBB