131 lines
4.0 KiB
Bash
Executable File
131 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#Install basic packages
|
|
apt-get update
|
|
apt-get install apt-transport-https curl wget -y
|
|
|
|
#Ask the user if he wants to install influxdb.
|
|
echo -ne "Do you want to install influxdb [yes/no]: "; read responce
|
|
case $responce in
|
|
[yY] | [yY][eE][sS] | "" ) influxdb=yes ;;
|
|
[nN] | [nO][oO] ) influxdb=no ;;
|
|
esac
|
|
echo ""
|
|
|
|
if [[ ${influxdb} == "yes" ]]; then
|
|
curl -sL https://repos.influxdata.com/influxdb.key | apt-key add -
|
|
echo "#Influxdb repository" | tee -a /etc/apt/sources.list.d/influxdb.list
|
|
echo "deb https://repos.influxdata.com/debian stretch stable" | tee -a /etc/apt/sources.list.d/influxdb.list
|
|
apt-get update
|
|
apt-get install influxdb python3 python3-pip -y
|
|
sleep 2
|
|
pip3 install influxdb
|
|
sleep 2
|
|
systemctl daemon-reload
|
|
systemctl start influxd
|
|
sleep 2
|
|
echo ""
|
|
fi
|
|
|
|
#Ask the user if he wants to install grafana.
|
|
echo -ne "Do you want to install Grafana (amd64) (recommended for the most Systems) [yes/no]: "; read responce
|
|
case $responce in
|
|
[yY] | [yY][Ee][Ss] | "" ) grafana-amd64=yes ;;
|
|
[nN] | [nN][oO] ) grafana-amd64=no ;;
|
|
esac
|
|
echo ""
|
|
|
|
if [[ ${grafana-amd64} == "yes" ]]; then
|
|
curl https://packagecloud.io/gpg.key | apt-key add -
|
|
echo '#Grafana repository' | tee -a /etc/apt/sources.list.d/grafana.list
|
|
echo 'deb https://packagecloud.io/grafana/stable/debian/ stretch main' | tee -a /etc/apt/sources.list.d/grafana.list
|
|
apt-get update
|
|
apt-get install grafana -y
|
|
sleep 2
|
|
systemctl daemon-reload
|
|
systemctl enable grafana-server.service
|
|
systemctl start grafana-server.service
|
|
sleep 2
|
|
echo ""
|
|
fi
|
|
|
|
echo -ne "Do you want to install Grafana (armhf) (recommended for armhf based Systems like a Raspberry Pi) [yes/no]: "; read responce
|
|
case $responce in
|
|
[yY] | [yY][Ee][Ss] | "" ) grafana-armhf=yes ;;
|
|
[nN] | [nN][oO] ) grafana-armhf=no ;;
|
|
esac
|
|
echo ""
|
|
|
|
if [[ ${grafana-armhf} == "yes" ]]; then
|
|
cd /tmp
|
|
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.2.4_armhf.deb
|
|
dpkg -i grafana_5.2.4_armhf.deb
|
|
sleep 2
|
|
systemctl daemon-reload
|
|
systemctl enable grafana-server.service
|
|
systemctl start grafana-server.service
|
|
sleep 2
|
|
echo ""
|
|
fi
|
|
|
|
echo -ne "Do you want to install Grafana (arm64) (recommended for ARM64 based Systems) [yes/no]: "; read responce
|
|
case $responce in
|
|
[yY] | [yY][Ee][Ss] | "" ) grafana-arm64=yes ;;
|
|
[nN] | [nN][oO] ) grafana-arm64=no ;;
|
|
esac
|
|
echo ""
|
|
|
|
if [[ ${grafana-arm64} == "yes" ]]; then
|
|
cd /tmp
|
|
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.2.4_arm64.deb
|
|
dpkg -i grafana_5.2.4_arm64.deb
|
|
sleep 2
|
|
systemctl daemon-reload
|
|
systemctl enable grafana-server.service
|
|
systemctl start grafana-server.service
|
|
sleep 2
|
|
echo ""
|
|
fi
|
|
|
|
#Variables
|
|
while [[ $db == "" ]]
|
|
do
|
|
read -p "Enter the desired database name you want to CREATE in influxdb: " db
|
|
echo "Enter a valid database name"
|
|
done
|
|
|
|
while [[ $retention == "" ]]
|
|
do
|
|
read -p "Enter the retention policy you wish to have for the data. Example - 30d: " retention
|
|
echo "Enter a valid retention policy value"
|
|
done
|
|
|
|
while [[ $policyname == "" || $policyname =~ [0-9] ]]
|
|
do
|
|
read -p "Enter the policy name (do not enter numbers in the name): " policyname
|
|
echo "Enter a valid policy name"
|
|
done
|
|
|
|
#Create the influx database depending on variables
|
|
echo "Creating Influxdb database $db ."
|
|
curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE $db"
|
|
|
|
echo "Setting up retention policy on $db ."
|
|
curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE RETENTION POLICY "$policyname" on "$db" DURATION $retention replication 1 DEFAULT"
|
|
|
|
#Ask for the smartplug IP
|
|
read -p "Enter the IP of your smartplug: " IP
|
|
|
|
#Adjust script
|
|
sed -i "s/IP/$IP/g" /opt/pyHS100/influxdbexporter.py
|
|
sed -i "s/dbase/$db/g" /opt/pyHS100/influxdbexporter.py
|
|
|
|
#Import the service and add the user
|
|
mv /opt/pyHS100/influxdbexporter.service /etc/systemd/system/
|
|
useradd -M -d /opt/pyHS100 -s /bin/false exporter
|
|
chown exporter:nogroup /opt/pyHS100 -R
|
|
systemctl daemon-reload
|
|
systemctl enable influxdbexporter.service
|
|
sleep 2
|
|
systemctl start influxdbexporter.service
|