This repository has been archived by the owner on Mar 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
justATVdetail.run
executable file
·90 lines (77 loc) · 2.92 KB
/
justATVdetail.run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
source config.ini
if [ -z "$SQL_password" ]
then
query(){
mysql -NB -h$DB_IP -P$DB_PORT -u$SQL_user "S1" -e "$2;"
}
else
query(){
mysql -NB -h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password "$1" -e "$2;"
}
fi
# Logging
mkdir -p $PATH_TO_STATS/logs
touch $PATH_TO_STATS/logs/log_$(date '+%Y%m').log
echo "[`date '+%Y%m%d %H:%M:%S'`] justATVdetails.run executed" >> $PATH_TO_STATS/logs/log_$(date '+%Y%m').log
# Check mariadb version
echo ""
DBversion=$(query "$MAD_DB" "SELECT left(version(),4)")
if ((${DBversion/./} > 101)) ;
then
echo "MariaDB version check passed"
echo ""
else
echo "Mariadb version should be 10.2 or higher !!!"
echo ""
exit
fi
echo "Create tables"
echo ""
cp $PATH_TO_STATS/default_files/tables.sql.default $PATH_TO_STATS/tables.sql
cd $PATH_TO_STATS && sed -i "s/pogodb/$STATS_DB/g" *.sql
cd $PATH_TO_STATS && sed -i "s/rmdb/$MAD_DB/g" *.sql
if [ -z "$SQL_password" ]
then
mysql -h$DB_IP -P$DB_PORT -u$SQL_user $STATS_DB < $PATH_TO_STATS/tables.sql
else
mysql -h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password $STATS_DB < $PATH_TO_STATS/tables.sql
fi
echo "Create crontab file"
echo ""
rm -f $PATH_TO_STATS/crontab.txt
touch $PATH_TO_STATS/crontab.txt
echo "#### STATS ####" >> $PATH_TO_STATS/crontab.txt
# get ATV details
if "$atvdetails"
then
echo "Set daily download of ATV settings"
echo ""
sed -i "$ a \#\# ATV details" $PATH_TO_STATS/crontab.txt
sed -i "$ a 20 */$atvdetails_hours * * * cd pathToStatscron_files && ./atvdetails.sh 2>>pathToStatslogs/log_\$(date '+\\\%Y\\\%m').log" $PATH_TO_STATS/crontab.txt
fi
PATH_TO_STATS2=$(sed 's@/@\\/@g' <<< $PATH_TO_STATS)
cd $PATH_TO_STATS && sed -i "s/pathToStats/$PATH_TO_STATS2/g" *.txt
if [ -z "$SQL_password" ]
then
sed -i "s/userpass/-h$DB_IP -P$DB_PORT -u$SQL_user/g" $PATH_TO_STATS/crontab.txt
else
sed -i "s/userpass/-h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password/g" $PATH_TO_STATS/crontab.txt
fi
echo "Creating grafana files"
echo ""
DS_STATS="${DataSource_stats^^}"
DS_MAD="${DataSource_MAD^^}"
mkdir -p $PATH_TO_STATS/grafana
cd $PATH_TO_STATS/grafana/ && rm -f *.json && rm -f *.default
cp $PATH_TO_STATS/default_files/10_ATVdetails.json.default $PATH_TO_STATS/grafana/10_ATVdetails.json
cp $PATH_TO_STATS/default_files/13_device_overview.json.default $PATH_TO_STATS/grafana/13_device_overview.json
cp $PATH_TO_STATS/default_files/15_device_temperature_overview.json.default $PATH_TO_STATS/grafana/15_device_temperature_overview.json
cp $PATH_TO_STATS/default_files/20_mad_stuff.json.default $PATH_TO_STATS/grafana/20_mad_stuff.json
cp $PATH_TO_STATS/default_files/21_mad_cpu_mem.json.default $PATH_TO_STATS/grafana/21_mad_cpu_mem.json
cd $PATH_TO_STATS/grafana/ && sed -i "s/pogodb/$DataSource_stats/g" *.json
cd $PATH_TO_STATS/grafana/ && sed -i "s/rmdb/$DataSource_MAD/g" *.json
cd $PATH_TO_STATS/grafana/ && sed -i "s/POGODB/$DS_STATS/g" *.json
cd $PATH_TO_STATS/grafana/ && sed -i "s/RMDB/$DS_MAD/g" *.json
echo ''
echo "All done"