You are not logged in.
I'm working on a custom pacman wrapper (written in Vlang w/ C backend) that can differentiate between packages from the standard repositories, AUR, and invalid packages. Getting packages from the AUR RPC is easy enough, but the standard repositories is harder. Currently if I want to search for packages there, the two methods I am aware of are:
- Regex (slow)
- Comm and pacman -Ssq (writing an unnecessary file)
Any other ideas for how to accomplish this? Maybe it could be part of the official repositories web interface, but it has really poor documentation so not sure.
Offline
The repos have a call. I use this:
Offline
Keep in mind that the official repositories API is only for querying minimal amounts of packages. Combine it with only querying a single package at a time, and any AUR helper using it will stop working very quickly.
https://github.com/arcan1s/ahriman/pull … 1106412297
- Comm and pacman -Ssq (writing an unnecessary file)
The overhead of this is completely negligible, even more compared to resolving things over the network. Write the file to a temporary location (mktemp) if you want to get rid of it after the script ends.
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
I'm not sure I fully understand the question, but certainly comm filtering of a list of all packages or a regex search are not the only options available via pacman. If filtering with comm would even work, you are not doing a regex search, but a full package name match, right? So if you want to search by a full package name (without regex) you can use `pacman -Sp <pkgname>`. You can pass a list of packages as well, however despite printing an error for every package not found, pacman will not print any output at all for found packages if there is any error. So this ends up only listing packages from a list not in the repos:
pacman -Sp - < list 2>&1 >/dev/null | awk '{ print $NF; }'
But if you've already filtered out AUR packages from the list, then what's left is either a repo package or nonexistent - the above command will give you the set of nonexistent packages, and whatever remains is a repo package.
Though I agree with the above, what's wrong with a temporary file? You would need one with any other approach too I imagine. If you get the list of files that are in the repos, you'd need to store that list somewhere in order to feed to pacman to install those packages. Again depending on context, this wouldn't even require any (additional) file:
# list repo packages from "pkglist":
pacman -Ssq | comm -12 - pkglist
Or if pkglist itself is not a file but piped from some other command, then you would need a temp file to run on a non-bash posix shell - but on bash and several other popular modern shells you could use process substitution which doesn't require a separate file:
#!/bin/bash
echo $pkglist | comm -12 <(pacman -Ssq) -
Last edited by Trilby (2023-03-12 13:39:02)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks everyone! Looks like I'll be going the way of using a temporary file after all
Offline
If the back-end is in C, why don't you use the ALPM API?
Wait could you elaborate I'm not very familiar with the ALPM API and haven't used it before, but I do really like the idea of using it.
Offline
You can find a series of examples here: https://github.com/andrewgregory/pacuti … master/lib
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline