-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·232 lines (179 loc) · 5.25 KB
/
configure
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
this_dir=$(cd `dirname $0`;pwd)
this_script=$(basename $0)
configDir=$this_dir/etc
configFile=$configDir/piLogger.conf
configYml=$configDir/piLogger.yml
withAbioWire=""
piLoggerLocale=""
#=============================
# functions
#=============================
errorExit(){
echo "ERROR: $@"
exit 1
}
usage(){
cat<<EOT
Usage:
$this_dir/$this_script [options]
Options:
--withAbioWire -> Using abio wire interface (will use Axiris port of owfs)
--withLocale -> Setting up en_US.UTF-8 locale
--minimizeInstall -> Remove any unnecessary package/files from the Raspbian installation (Caution, will remove a lot!)
--noPassword -> user pi does not have a password
Default:
* Default use of dpkg owfs
EOT
}
check(){
echo "* Packages:"
for package in owfs rrdtool lighttpd
do
echo -n " - $package:"
sudo dpkg -s $package >/dev/null 2>&1 && echo -n " OK! installed" || echo -n " ERROR: not installed"
echo ""
done
echo "* Directories:"
for dir in /var/lib/piLogger /var/lib/piLogger/db /var/lib/piLogger/cache /var/lib/piLogger/xml /var/lib/piLogger/graphs
do
echo -n " - $dir:"
[ -d $dir ] && echo -n " OK! exists" || echo -n " ERROR: does not exist"
echo ""
done
echo "* Soft links:"
for link in $this_dir/html/cache $this_dir/html/graphs $this_dir/html/xml /etc/piLogger.d
do
echo -n " - $link:"
[ -h $link ] && echo -n " OK! exists" || echo -n " ERROR: does not exist"
echo ""
done
echo "* Crontab:"
for crontabEntry in "bin/logAll" "bin/refreshCaches sensors" "bin/refreshCaches 12h" "bin/refreshCaches 24h" "bin/refreshCaches 168h"
do
echo -n " - $crontabEntry:"
crontab -l | grep "$crontabEntry" >/dev/null 2>&1 && echo -n " OK! exists" || echo -n " ERROR: does not exist"
echo ""
done
echo "* Logrotate:"
echo -n " - file /etc/logrotate.d/piLogger:"
[ -f /etc/logrotate.d/piLogger ] && echo -n " OK! exists" || echo -n " ERROR: does not exist"
echo ""
echo "* Config file entries:"
echo -n " - $configDir/piLogger.conf"
[ -f $configDir/piLogger.conf ] && echo -n " OK! exists" || echo -n " does not exist"
echo ""
[ -f $configDir/piLogger.conf ] && {
for parameter in interface piLoggerLocale baseDir htmlDir oneWireDir cacheDir temperatureFile spoolDir
do
echo " - $parameter="$(grep "^${parameter}=" $configDir/piLogger.conf | cut -d"=" -f2 )
done
}
}
#=============================
# Command line parameters
#=============================
while [ -n "$1" ]
do
case $1 in
--check)
check
exit 0
;;
--withAbioWire)
withAbioWire=true
interface=AbioWire
shift
;;
--withLocale)
withLocale=true
piLoggerLocale=true
shift
;;
--minimizeInstall)
minimizeInstall=true
shift
;;
--noPassword)
noPassword=true
shift
;;
*)
usage
exit 1
;;
esac
done
#=============================
# MAIN
#=============================
#--- have SUDO ask for password if necessary
res=0
[ -z "$noPassword" ] && { echo "Your user need a password for sudo" ; sudo -v ; res=$? ; }
[ $res -ne 0 ] && { echo "Sudo ended badly, exiting" ; exit 1 ; }
sudoCount=$(sudo -l 2>/dev/null | awk 'printit=="true" {print} /may run the following/ {printit="true"}' | grep "ALL$" | wc -l)
[ $sudoCount -eq 0 ] && { echo "WARNING: you will need sudo rights for the installation. Check with sudo -l" ; }
[ ! -d "$configDir" ] && mkdir -p $configDir
#--- prepare the config file
[ -f $configFile ] && errorExit "File $configFile already exists. Exiting! Please remove the config file before running again."
[ -f $configYml ] && errorExit "File $configYml already exists. Exiting! Please remove the config file before running again."
#--- set the interface
[ -z "$interface" ] && interface=default
numCpu=$(cat /proc/cpuinfo | grep Processor | wc -l)
deviceIdentifier=$(cat /sys/class/net/eth0/address | md5sum | cut -d" " -f1)
cat>$configFile<<EOT
#----------------------------
# Config file for piLogger
#----------------------------
interface=$interface
piLoggerLocale=$piLoggerLocale
baseDir=$this_dir
dataDir=/var/lib/piLogger
oneWireDir=${oneWireDir:-/mnt/1wire}
htmlDir=\$baseDir/html
cacheDir=\$dataDir/cache
temperatureFile=temperature
rrdDir=\$dataDir/db
dbDir=\$dataDir/db
graphDir=\$dataDir/graphs
backupDir=\$dataDir/backup
spoolDir=/var/spool/piLogger
appDbFile=\$dbDir/app.sqlite3
logDir=/var/log/piLogger
#----------------------
dateFormat="+%Y%m%d %H%M%S"
#-------------------------
# Parallel processing
#-------------------------
parallelProcessing=$numCpu
#-------------------------
# for remote logging
#-------------------------
#--- remoteLogging=true
remoteLogging=""
remoteHost=""
#-------------------------
# for piLogger Cloud
#-------------------------
deviceIdentifier=$deviceIdentifier
authToken=""
EOT
cat>$configYml<<EOT
remoteLogging:
enabled: true
host:
blacklist:
#-------------------------
# for piLogger Cloud
#-------------------------
piLogger_cloud:
deviceIdentifier: SECRET
authToken: "SECRET"
blacklist:
#------------------------
# shiftr.io
#------------------------
shiftr:
shiftrAuth: "SECRET"
EOT
[ -n "$minimizeInstall" ] && { echo "minimizeInstall=true" >> $configFile ; }