You are not logged in.
Pages: 1
Hey, I'm trying to write a script that'll check for dependencies to install and build something. I can check to see if the file exists but that seems kind of brute force. I'm trying to use
pacman -Q
but I can't get it quite right.
Example:
DEPS="python2-setuptools git curl wget"
if ( sudo pacman -Q $DEPS >/dev/null ) ; then
echo "Deps not installed, installing now"
sudo pacman -S $DEPS
else
echo "Dependencies met."
fi
But this always returns that DEPS aren't installed and prompts to reinstall.
Last edited by 0X1A (2013-10-03 18:55:03)
Offline
if ( sudo pacman -Q $DEPS >/dev/null ) ; then
Are you doing this in bash? Use [[
Also, you don't need sudo for -Q
Offline
Offline
Use -T switch.
pacman -T git python2-setuptools amarok
python2-setuptools
amarok
P.S. git is the only application I've installed. The rest are being listed as "targets".
Last edited by XURL (2013-10-03 18:13:03)
☑ CPU: Single core Intel Pentium M (-UP-) clocked at 1733.000 Mhz
☑ MEM: 490.1 MB
☑ HDD: 40.1 GB
Offline
Direct fix of your code would look like this:
#!/bin/bash
DEPS="python2-setuptools git curl wget"
pacman -Q $DEPS &> /dev/null
if [[ $? -ne 0 ]] ; then
echo "Deps not installed, installing now"
sudo pacman -S $DEPS
else
echo "Dependencies met."
fi
, but as pointed above, it's not the best approach, what exactly are you trying to accomplish?
Last edited by kaszak696 (2013-10-03 18:26:40)
'What can be asserted without evidence can also be dismissed without evidence.' - Christopher Hitchens
'There's no such thing as addiction, there's only things that you enjoy doing more than life.' - Doug Stanhope
GitHub Junkyard
Offline
Direct fix of your code would look like this:
#!/bin/bash DEPS="python2-setuptools git curl wget" pacman -Q $DEPS &> /dev/null if [ $? -ne 0 ] ; then echo "Deps not installed, installing now" sudo pacman -S $DEPS else echo "Dependencies met." fi
, but as pointed above, it's not the best approach, what exactly are you trying to accomplish?
This works, but still prompts for re-installation. I'm just trying to see if the user has those packages installed and if not then install them.
Offline
#!/bin/bash
DEPS="python2-setuptools git wget"
# Get missing dependencies
targets=$(pacman -T $DEPS)
# Install missing dependencies
sudo pacman -S $targets
Last edited by XURL (2013-10-03 18:33:45)
☑ CPU: Single core Intel Pentium M (-UP-) clocked at 1733.000 Mhz
☑ MEM: 490.1 MB
☑ HDD: 40.1 GB
Offline
This works, but still prompts for re-installation. I'm just trying to see if the user has those packages installed and if not then install them.
Pacman has a very nifty switch --needed, that takes case of that. Or use XURL's code.
Last edited by kaszak696 (2013-10-03 18:33:28)
'What can be asserted without evidence can also be dismissed without evidence.' - Christopher Hitchens
'There's no such thing as addiction, there's only things that you enjoy doing more than life.' - Doug Stanhope
GitHub Junkyard
Offline
Offline
... echo "Deps not installed, installing now" sudo pacman -S $DEPS ...
I'd recommend putting an --asdeps in that sync statement, or else $USER will have a lot of packages that he/she doesn't need/want later on when they remove $FOO.
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.
Online
Direct fix of your code would look like this:
#!/bin/bash DEPS="python2-setuptools git curl wget" pacman -Q $DEPS &> /dev/null if [[ $? -ne 0 ]] ; then echo "Deps not installed, installing now" sudo pacman -S $DEPS else echo "Dependencies met." fi
, but as pointed above, it's not the best approach, what exactly are you trying to accomplish?
You could simply have written
if ! pacman -Q $DEPS &> /dev/null; then
Offline
Pages: 1