You are not logged in.

#1 2023-03-12 06:15:20

Retr0r0cket
Member
From: Sol III
Registered: 2021-11-24
Posts: 15

How to check if list of packages exist in official arch repositories

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

#2 2023-03-12 06:34:04

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: How to check if list of packages exist in official arch repositories

The repos have a call. I use this:

https://hg.sr.ht/~jasonwryan/shiv/brows … ch?rev=tip


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2023-03-12 11:34:53

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,412
Website

Re: How to check if list of packages exist in official arch repositories

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

#4 2023-03-12 13:32:30

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

Re: How to check if list of packages exist in official arch repositories

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

Online

#5 2023-03-12 21:29:04

Retr0r0cket
Member
From: Sol III
Registered: 2021-11-24
Posts: 15

Re: How to check if list of packages exist in official arch repositories

Thanks everyone! Looks like I'll be going the way of using a temporary file after all

Offline

#6 2023-03-13 12:36:21

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 1,985
Website

Re: How to check if list of packages exist in official arch repositories

If the back-end is in C, why don't you use the ALPM API?


macro_rules! yolo { { $($tokens:tt)* } => { unsafe { $($tokens)* } }; }

Offline

#7 2023-03-13 17:28:01

Retr0r0cket
Member
From: Sol III
Registered: 2021-11-24
Posts: 15

Re: How to check if list of packages exist in official arch repositories

schard wrote:

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

#8 2023-03-13 17:39:24

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,412
Website

Re: How to check if list of packages exist in official arch repositories

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

Board footer

Powered by FluxBB