You are not logged in.

#1 2022-11-12 21:46:11

mattz7
Member
Registered: 2020-01-07
Posts: 12

[SOLVED] a way to list all aur dependencies RECURSIVELY

Hi guys!

I've tried to write the code today in BASH but I got to admit I've failed.

Basically I'm writing a makepkg wrapper that is supposed to build AUR packages in a chroot env.

And there is one critical feature I would like to have: downloading AUR dependencies, and if need be, AUR dependencies of AUR dependencies and so on (:D).

Could someone savvy help me with this?

Here are some snippets:

DEPS=($(tr -d "[:blank:]" < .SRCINFO | grep '^depends' | awk -F '=' '{ print $2 }'))
AURDEPS=()

for dep in ${DEPS[@]}; do
   if ! arch-chroot $chroot/root pacman -Si $dep; then
   AURDEPS+=$dep
   fi
done

Thanks in advance,
Matt

Last edited by mattz7 (2022-11-12 23:36:50)

Offline

#2 2022-11-12 22:19:35

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] a way to list all aur dependencies RECURSIVELY

I always use aurutils for these sort of queries...

slithery@purple:~$ aur depends longview
perl-io-lockedfile
perl-linux-distribution
perl-json-pp
perl-log-loglite
longview

No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2022-11-12 22:33:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: [SOLVED] a way to list all aur dependencies RECURSIVELY

That's a rather long pipeline ending in awk all for something that awk would do:

DEPS=$(awk  '$1 == "depends" { print $3; }' .SRCINFO)

Then I'm not sure why you'd loop through the DEPS running pacman for each one.  Just run pacman once ... or twice if you want to check first for what's needed (as you may not need to do anything for an "AURDEP" that is already installed):

MISSING_DEPS=$(pacman -T $DEPS)

Then see which of these can't be found in any configured repos:

AURDEPS=$(pacman -Sp $MISSING_DEPS 2>&1 >/dev/null | awk '{ print $NF; }')

As for the recursive part of this - this script itself should likely be called recursively for each "AURDEP".  So all together, perhaps something like this:

#!/bin/sh

deps=$(awk  '$1 == "depends" { print $3; }' .SRCINFO)
[ -z "$deps" ] && exit
missing_deps=$(pacman -T $deps)
[ -z "$missing_deps" ] && exit
aur_deps=$(pacman -Sp $missing_deps 2>&1 >/dev/null | awk '{ print $NF; }')
[ -z "$aur_deps" ] && exit

my_dir=$pwd
for pkg in $aur_deps; do
	# git clone $pkg if needed
	# cd to $pkg
	$0
done
cd $my_dir

echo "$aur_deps"

Note that as-is this code would recurse infinitely if there are circular aur-dependencies.  You could add a check for this if you wanted to protect against such an occurrence.

Last edited by Trilby (2022-11-12 22:44:35)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#4 2022-11-12 22:43:47

mattz7
Member
Registered: 2020-01-07
Posts: 12

Re: [SOLVED] a way to list all aur dependencies RECURSIVELY

@Slithery, thanks for suggesting using a pacman wrapper but I'd rather not to.

@Trilby, thank you for optimizing my code, but I'm not entirely satisfied yet. You're saying

As for the recursive part of this - this script itself should likely be called recursively for each "AURDEP".

but how do you accomplish that? I'd imagine there would have to be a while loop with a conditional break or something. Or wait, maybe I get it now. Would I have to run the script from within?

Last edited by mattz7 (2022-11-12 22:45:02)

Offline

#5 2022-11-12 22:45:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: [SOLVED] a way to list all aur dependencies RECURSIVELY

mattz7 wrote:

how do you accomplish that?

See my edit.  Of course it might be better in the end to have much of this in a function that calls itself recursively rather than a script that invokes itself (via "$0") recursively.  But the logic is the same ... actually there are some nice advantages to the function encapsulation here:

#!/bin/sh

recursive_aurdeps() { # first arg is path to PKGBUILD
	cd $1
	deps=$(awk '$1 == "depends" { print $3; }' .SRCINFO)
	[ -z "$deps" ] && return
	missing_deps=$(pacman -T $deps)
	[ -z "$missing_deps" ] && return
	aur_deps=$(pacman -Sp $missing_deps 2>&1 >/dev/null | awk '{ print $NF; }')
	[ -z "$aur_deps" ] && return

	for pkg in $aur_deps; do
		# git clone $pkg if needed
		recursive_aurdeps $path_to_pkg
	done

	echo "$aur_deps"
}

(edit: replaced "exit" with "return" for the function)

Last edited by Trilby (2022-11-12 22:52:17)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#6 2022-11-12 22:56:33

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] a way to list all aur dependencies RECURSIVELY

mattz7 wrote:

@Slithery, thanks for suggesting using a pacman wrapper but I'd rather not to.

You don't have to actually use it, but you can read the code to research how someone else has already solved the same problem...
https://github.com/AladW/aurutils/blob/ … ur-depends


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#7 2022-11-12 23:01:49

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,540

Re: [SOLVED] a way to list all aur dependencies RECURSIVELY

aurutils is not a pacman wrapper...

Offline

#8 2022-11-12 23:09:48

mattz7
Member
Registered: 2020-01-07
Posts: 12

Re: [SOLVED] a way to list all aur dependencies RECURSIVELY

@Trilby, thanks a million! I'll try to implement the code in my script and report back once I have it working smile

Offline

Board footer

Powered by FluxBB