This commit is contained in:
hjelev
2022-03-19 00:34:30 +02:00
parent 1d1f9ba133
commit a4df4c13b0
3 changed files with 23 additions and 19 deletions

View File

@@ -1,11 +1,22 @@
printm () { printm () {
line="------"
length=$(expr length "$1") length=$(expr length "$1")
length=$(($length + 4))
printf "\n"
printf -- '-%.0s' $(seq $length); echo "" printf -- '-%.0s' $(seq $length); echo ""
echo "$1" printf "| $1 |\n"
printf -- '-%.0s' $(seq $length); echo "" printf -- '-%.0s' $(seq $length); echo ""
} }
print_green () {
tput setaf 2; echo "$1"
tput sgr 0
}
print_yellow () {
tput setaf 3; printf "$1"
tput sgr 0
}
printm "Raspberry Pi MQTT monitor installer" printm "Raspberry Pi MQTT monitor installer"
check_and_install_pip () { check_and_install_pip () {
@@ -16,21 +27,13 @@ check_and_install_pip () {
echo "- Pip is not installed, installing it." echo "- Pip is not installed, installing it."
sudo apt install python-pip sudo apt install python-pip
else else
print_green "+ Found $pip"
tput setaf 2; echo "+ Found $pip"
tput sgr 0
fi fi
} }
check_and_install_paho () { install_requirements () {
pip=$(pip list | grep "paho-mqtt"); printm "Installing requirements"
if [[ "$pip" == *"paho-mqtt"* ]]; then pip install -r requirements.txt
echo "+ Found $pip"
else
echo "- Paho-mqtt is not installed, installing it."
pip install paho-mqtt
fi
} }
update_config () { update_config () {
@@ -76,9 +79,9 @@ set_cron () {
crontab -l > tempcron crontab -l > tempcron
if grep -q rpi-cpu2mqtt.py tempcron; then if grep -q rpi-cpu2mqtt.py tempcron; then
cronfound=$(grep rpi-cpu2mqtt.py tempcron) cronfound=$(grep rpi-cpu2mqtt.py tempcron)
echo " There is already a cronjob running rpi-cpu2mqtt.py - skipping cronjob creation" print_yellow " There is already a cronjob running rpi-cpu2mqtt.py - skipping cronjob creation\n"
printf " If you want the cronjob to be automatically created remove the line below from your\n cronjobs list and run the installer again.\n" print_yellow " If you want the cronjob to be automatically created remove the line below from your\n cronjobs list and run the installer again.\n\n"
echo "${cronfound}" echo " ${cronfound}"
else else
printf "How often do you want the script to run in minutes? " printf "How often do you want the script to run in minutes? "
@@ -94,7 +97,7 @@ set_cron () {
main () { main () {
check_and_install_pip check_and_install_pip
check_and_install_paho install_requirements
update_config update_config
set_cron set_cron
printm "Done" printm "Done"

View File

@@ -7,7 +7,7 @@ printm () {
} }
printm "Cloning rpi-mqtt-monitor git repository" printm "Cloning rpi-mqtt-monitor git repository"
echo $line
git clone https://github.com/hjelev/rpi-mqtt-monitor.git git clone https://github.com/hjelev/rpi-mqtt-monitor.git
cd rpi-mqtt-monitor cd rpi-mqtt-monitor
bash install.sh bash install.sh

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
paho-mqtt==1.5.0