#!/bin/bash

# which program has been called?

CMD=${0##*/m}
MCDIR=$(dirname $0)
# try to figure if python salt modules are installed for python3 and/or python2

python2_installed=1
python3_installed=1

python -c "import salt.client" > /dev/null 2>&1
RC2=$?

python3 -c "import salt.client" > /dev/null 2>&1
RC3=$?

python2_installed=$RC2
python3_installed=$RC3

# we prefer python3 if installed
if [[ $python3_installed -eq 0 ]]; then
    python3 ${MCDIR}/mclient.py $CMD

# take python2 if found but no python3
elif [[ $python2_installed -eq 0 ]]; then
    python ${MCDIR}/mclient.py $CMD

# bail out if no python salt modules found
else
    echo "Couldn't find installed salt python modules - exiting"
fi
