0

I am running an .sh file and within that I am installing pip and paho-mqtt. I am running the file in ubuntu. But when I run the file for the second time also the pip and paho installation in happening. I want to check whether those are installed before executing these lies. Can someone help me with this.

My file is as follows,

#install mqtt dependency
git clone git://git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.python.git
cd org.eclipse.paho.mqtt.python
sudo python setup.py install

sudo apt install python-pip
sudo pip install paho-mqtt

What i want to do is,

if !(check is installed) then
    #install mqtt dependency
    git clone git://git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.python.git
    cd org.eclipse.paho.mqtt.python
    sudo python setup.py install

    sudo apt install python-pip
    sudo pip install paho-mqtt
AnjuT
  • 166
  • 1
  • 4
  • 17
  • Possible duplicate of [Check if a package is installed and then install it if it's not](https://stackoverflow.com/questions/1298066/check-if-a-package-is-installed-and-then-install-it-if-its-not) – Zev Averbach Jun 13 '17 at 04:46
  • I used the command in terminal earlier and it works fine. But I wanted to know how to add this to a .sh file to check if it's installed. Like, (if ; then) – AnjuT Jun 13 '17 at 04:55

1 Answers1

0

This helped me

s=`dpkg -s python-pip | grep Status`
if [[ $s == *"installed"* ]]; then
    #installed
else
    git clone git://git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.python.git
    cd org.eclipse.paho.mqtt.python
    sudo python setup.py install
    sudo apt install python-pip 
fi
AnjuT
  • 166
  • 1
  • 4
  • 17