#Function to see if a package is installed on Debian and derivatives
BASH
javascript
function instalado() {
#We check if the wget package is installed using the aptitude command
aux=$(aptitude show wget | grep "Estado: instalado")
if `echo "$aux" | grep "Estado: instalado" >/dev/null`
then
return 1
else
return 0
fi
}
# we call the function
instalado $1 &> /dev/null
#We check the result... if it gives 1 it is installed and if it gives 0 it is not installed.
if [ "$?" = "1" ]
then
#If the package is installed I send a message
echo el paquete $aux ya esta instado.
#If it was not installed...for example we install it...
else
apt-get install wget
fi#Function to see if a package is installed in redhat, centos, suse and derivatives
BASH
javascript
function instalado() {
#We check if the wget package is installed using the rpm command
aux=$(rpm -qa wget)
#We filter the result of the rpm command using grep and save the result.
if `echo "$aux" | grep "wget" >/dev/null`
then
return 1
else
return 0
fi
}
#We call the function
instalado $1 &> /dev/null
#We check the result... if it gives 1 it is installed and if it gives 0 it is not installed.
if [ "$?" = "1" ]
then
#If the package is installed I send a message
echo el paquete $aux ya esta instado.
#If it was not installed...for example we install it...
else
yum install wget
fi
Comments