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
... 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.
]]>#!/bin/bash DEPS="python2-setuptools git wget" # Get missing dependencies targets=$(pacman -T $DEPS) # Install missing dependencies sudo pacman -S $targets
This works perfectly, thanks
]]>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.
]]>#!/bin/bash
DEPS="python2-setuptools git wget"
# Get missing dependencies
targets=$(pacman -T $DEPS)
# Install missing dependencies
sudo pacman -S $targets
]]>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.
]]>#!/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?
]]>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".
]]>0X1A wrote:if ( sudo pacman -Q $DEPS >/dev/null ) ; then
Are you doing this in bash? Use [[
Also, you don't need sudo for -Q
Yeah I am, using [[ ]] expects a conditional binary operator
]]>if ( sudo pacman -Q $DEPS >/dev/null ) ; then
Are you doing this in bash? Use [[
Also, you don't need sudo for -Q
]]>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.
]]>