pythonshellpippaho

How to check whether paho mqtt is installed


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

Solution

  • 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