Bash script | determine if package is AUR or not

I need a fast & elegant way to determine if package (known only by name) is AUR or not (just logical switch, without output).

What i came up so far is:

...

pacman -Si "$packageName" >/dev/null 2>&1

if [ $? -eq 0 ];
then
    source="pacman"
else
    source="AUR"
fi

Technically it works, but it's pretty slow in context of hundreds of packages :woozy_face:

Effective ideas are welcome :slight_smile:

1 Like

pacman -Qm will display all non-repo packages.

3 Likes

You mean to check this $packageName against given list?

But i need this script in context of not installed AUR pacakges, and -Qm lists installed as far as i can tell...

yay -Si $packagename | awk -F: '/Repository/{print $2}'

1 Like

Something similar possible with pacman or yaourt?
Would be preferable, since those are preinstalled)

yaourt is dead.
Pacman doesn't scan AUR.

1 Like

Wow, thx for mentioning...Why yaourt still used by Manjaro Deepin by default then?

I was thinking about something tricky like mentioned in OP, basically if pacman error then...It's AUR (otherwise if it fails i don't really care though)

Why are you trying to reinvent the wheel it just turn the kiss principle upside down making it harder for yourself Lol :laughing:

You could direct the above command into a variable:

VARIABLE=$(yay -Si $packagename | awk -F: '/Repository/{print $2}')
if [[ $VARIABLE = "aur" ]]; then 
etc. etc.
1 Like

Assuming you are talking about packages that are installed on your system, I would use expac for this. It can output package detail(including the repo) in a wide variety of formats.

1 Like

Nope, it's for non-installed actually...

But to access local package info i usually use:

pacman -Qi -p "$package"

It reads info directly from .pkg.tar.xz file for any repo include those built from AUR :upside_down_face:

or without -p for just installed

But pacman doesn't know about non-installed packages that in AUR?

expac not only provides more information but allows you to not have to do so one package at a time. It isn't always the right tool, but it is a good tool to have in your toolbox.

1 Like

Yeah, it returns:

error: package 'cpu-x' was not found

in this case, that's why i was trying to catch it with

if [ $? -eq 0 ];

But @anon23612428 actually gave me idea, i suppose string comparison would be way faster, will test now...

expac can search sync repositories though. So there's no need for the packages to be installed.

You don't need a script. Just use pacman -Ss <package>. If it returns nothing then it isn't in the repos. trizen -Ss <package> will get repos' and AUR packages and trizen -Sas <package> will search for AUR packages only. You can use yaourt, yay or another helper in the same way instead of trizen.

EDIT: ok, the s option isn't the best choice for a specific package. See my next post.

1 Like

Good point. It returns exit code 1 if the package is not found - which you can then use in e.g. an if clause.

Ain't -Ss itself is slower than -Si ?

Another possibility:
[[ -z $(pacman -Si $packagename 2>/dev/null) ]]; echo "aur"

Or:

pacman -Si $packagename 2>/dev/null
if [[ $? == 1 ]]; then echo "aur"; fi

No, -Si fetches info for a specific package and -Ss fetches search results for a keyword. I really can't grasp the point of the script. For example, I want to know if virtualbox is in AUR: trizen -Sas virtualbox

This returns a huge list because it search for keyword, not the package. If I want to search for the package name then I need to use the "i" option:

[mbb@mbb-laptop ~]$ trizen -Sai virtualbox
:: virtualbox not found.

To put this on a script is very simple.

EDIT: You can also use -Ss with grep but I don't see the point:

[mbb@mbb-laptop ~]$ PNAME=virtualbox; trizen -Sas $PNAME | grep "aur\/$PNAME "
[mbb@mbb-laptop ~]$ PNAME=virtualbox-bin; trizen -Sas $PNAME | grep "aur\/$PNAME "
aur/virtualbox-bin 6.0.4-1 [49+] [1.08%] [29 Jan 2019]

@anon23612428
Both works fine, but in terms of speed strangely enough same as op, though i think string comparison is just in general faster for bash than catching result of $? :thinking:

btw you've meant ==, instead of = i suppose please edit original message, so nobody will catch this typo :slight_smile:

@mbb
I'm experimenting with pacman -Ss now, it's fast but i'm a little concerned that it search for keywords like google, there is a chance that it can catch some part of package name from AUR in manjaro repos, so doesn't seem to be reliable...

trizen is cool option no doubt, but in my case i'd like to stick with something preinstalled like pacman (which is something that all Manjaro editions have)

I really can't grasp the point of the script.

It's fate of all of my isolated bash-related questions :laughing:
All i can say - definitely not typical scenario use case.

1 Like

Forum kindly sponsored by