You are not logged in.

#1 2024-01-21 18:48:14

Harey
Member
From: Bavaria, Germany
Registered: 2007-03-24
Posts: 359

[Solved] Using pacman in scripts

Hi all,

I need to process the output of pacman in a script. I need to know if a certain package is installed and based on that information uninstall another. In this case it is virtualbox. Based on this information I want to uninstall virtualbox-ext-oracle programmatically before to avoid the update script being interrupted.
I could use 'pacman -Qsq' and grep for virtualbox but that leaves me with more packages:

[root@lenovix harvey]# pacman -Qsq virtualbox | grep virtualbox
virtualbox
virtualbox-ext-oracle
virtualbox-guest-iso
virtualbox-host-dkms

But I only need information about virtualbox itself. Also on a machine that has virtualbox-guest-utils installed this would give me a false postive.

How could I solve this?

Greetings
Harvey

Last edited by Harey (2024-01-21 19:28:21)


Linux is like a wigwam: No Gates, no Windows and an Apache inside

Offline

#2 2024-01-21 19:02:20

lambdarch
Member
Registered: 2021-01-10
Posts: 63

Re: [Solved] Using pacman in scripts

pacman -Qsq '^virtualbox$'

But maybe this would be faster?

pacman -Qq | grep -qx virtualbox

EDIT: Ah! I missed the -i option below wink

Last edited by lambdarch (2024-01-21 19:04:52)

Offline

#3 2024-01-21 19:02:29

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,670
Website

Re: [Solved] Using pacman in scripts

pacman -Qi virtualbox &>/dev/null

Returns 0 if the package is installed, otherwise 1.

EDIT: reading the manpage, it looks like this is the exact use case for deptest:

man pacman wrote:
       -T, --deptest 
           Check dependencies; this is useful in scripts such as makepkg to check installed packages. This operation
           will check each dependency specified and return a list of dependencies that are not currently satisfied on
           the system. This operation accepts no other options. Example usage: pacman -T qt "bash>=3.2".
pacman -T virtualbox >/dev/null

Returns 0 if the package is installed, otherwise 127.

Last edited by WorMzy (2024-01-21 19:07:33)


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#4 2024-01-21 19:28:01

Harey
Member
From: Bavaria, Germany
Registered: 2007-03-24
Posts: 359

Re: [Solved] Using pacman in scripts

Hello and thanks to both of you!
I'll go with the

pacman -Qi virtualbox &>/dev/null

Greetings
Harvey

Edit: Some more information
I needed to tell if in a 'pacman -Syu' update there will be a virtualbox-update contained. But 'pacman -Quq virtualbox' gives me more hits than only virtualbox, so I had to find a way to securely tell me when there is a virtualbox update in queue to remove virtualbox-ext-oracle before. Otherwise the update would fail. And checking if virtualbox is really installed seems the way to go.

Last edited by Harey (2024-01-21 19:58:17)


Linux is like a wigwam: No Gates, no Windows and an Apache inside

Offline

#5 2024-01-21 20:14:49

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

Re: [Solved] Using pacman in scripts

There's really no need for the '-i' there.  That requires pacman to collect more information that just ends up being sent to /dev/null anyways.

However all of this sounds like a very bit X-Y problem.  How would the presence of an AUR package cause the update of a repo package to fail?  If it does, that's surely an error in the package that should be fixed.  It looks like the AUR package will not cause the updgrade to fail, but rather that you just need to upgrade the AUR package every time the repo package is updated, right?

Last edited by Trilby (2024-01-21 20:17:01)


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

Offline

#6 2024-01-21 20:39:16

seth
Member
Registered: 2012-09-03
Posts: 48,398

Re: [Solved] Using pacman in scripts

Afaiu the OP the packages will conflict and the OP wants to avoid the script having to deal w/ the pacman IO

That being said, I highly concur to drop the "i", it's unnecessary and slows down the query considerably if the package is present.

Offline

#7 2024-01-21 21:43:34

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

Re: [Solved] Using pacman in scripts

seth wrote:

Afaiu the OP the packages will conflict and the OP wants to avoid the script having to deal w/ the pacman IO

If so, checking is a bit silly.  Just install everything except virtualbox-ext-oracle, then just try to install this package and ignore any failure due to conflicts (as the new package will just not be installed which is the end goal anyways).

But on the actual pacman command, if other providers of virtualbox should be handled similarly, then -T should be used, not -Q.


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

Offline

#8 2024-01-22 08:10:00

Harey
Member
From: Bavaria, Germany
Registered: 2007-03-24
Posts: 359

Re: [Solved] Using pacman in scripts

No, there is a conflict with this update. If virtualbox-ext-oracle is installed the update with pacman -Syu --noconfirm will bail out. The author of the AUR package is not willing to change this situation (see here) so atm there is only one solution: check if pacman -Syu contains virtualbox, then uninstall the old version of virtualbox-ext-oracle, do the pacman -Syu and install the new version of virtualbox-ext-oracle. Not very straightforward, but I have not found another solution. Glad to hear your ideas though wink


Linux is like a wigwam: No Gates, no Windows and an Apache inside

Offline

#9 2024-01-22 11:50:16

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,812

Re: [Solved] Using pacman in scripts

It seems virtualbox and virtualbox-ext-oracle need to be of he exact same version to work.

A flow like this might work :

Put virtualbox-ext-oracle binary in a local / custom repository

when a newer virtualbox package is available in repos verify if aur virtualbox-ext-oracle does match that version .
If not, don't update virtualbox.

If yes, build the new version of virtualbox-ext-oracle and put it in the repo.
run pacman -Syu and let pacman update virtualbox & virtualbox-ext-oracle together.

According to the archwiki virtualbox page there is already a custom repo that includes this package, so you may not need to setup your own or build the extension package.
see https://wiki.archlinux.org/title/Unoffi … ries#seblu

Last edited by Lone_Wolf (2024-01-22 11:51:17)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#10 2024-01-22 12:34:58

Harey
Member
From: Bavaria, Germany
Registered: 2007-03-24
Posts: 359

Re: [Solved] Using pacman in scripts

Hey, that's a great idea! In this way I could somewhat streamline not only virtualbox-ext-oracle  but all of my AUR and selfbuilt package installations. I will surely take a closer look! Thank you!


Linux is like a wigwam: No Gates, no Windows and an Apache inside

Offline

#11 2024-01-22 14:09:48

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

Re: [Solved] Using pacman in scripts

How can installing virtual box then virtualbox-ext-oracle cause a conflict only if they are different versions?  I believe there could be an error - but not a file conflict.

Oh, it's just a dependency mismatch.  In that case, you could also use the -d flag, then just rebuild/install AUR packages afterwards as you'd need to anyways.  But just building the new version of the AUR package first and installing them together would be best.

Last edited by Trilby (2024-01-22 14:13:26)


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

Offline

Board footer

Powered by FluxBB