You are not logged in.
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
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
Offline
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
@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
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
@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
Offline
aurutils is not a pacman wrapper...
Offline
@Trilby, thanks a million! I'll try to implement the code in my script and report back once I have it working
Offline