|
@@ -1,19 +1,30 @@
|
1
|
1
|
#!/bin/sh
|
|
2
|
+REPO_DIR=/opt/pyHeatpump
|
|
3
|
+LIB_DIR=/var/lib/pyheatpump
|
|
4
|
+
|
2
|
5
|
|
3
|
|
-# If directory exists don't run the script
|
4
|
6
|
# cd /opt/pyheatpump git clone https://git.yannweb.net/cli/pyHeatpump.git
|
5
|
|
-[ ! -d /opt/pyHeatpump/ ] && echo "Missing /opt/pyHeatpump/" && exit 1;
|
6
|
|
-[ ! -d /run/pyheatpump/ ] && echo "Missing /run/pyheatpump/" && exit 1;
|
|
7
|
+[ ! -d $REPO_DIR ] \
|
|
8
|
+ && echo "Missing $REPO_DIR" \
|
|
9
|
+ && exit 1;
|
7
|
10
|
|
8
|
|
-[ -f /run/pyheatpump/pyheatpump.sqlite3 ] && [ -f /run/pyheatpump/pyheatpump.ini ] \
|
9
|
|
- && echo "Incorrect runtime directory" && exit 1;
|
|
11
|
+[ ! -d /var/lib/pyheatpump ] && mkdir --mode 0700 /var/lib/pyheatpump
|
|
12
|
+# If files already exist don't var/lib the script
|
|
13
|
+[ -f $LIB_DIR/pyheatpump.sqlite3 ] && [ -f $LIB_DIR/pyheatpump.ini ] \
|
|
14
|
+ && exit 0;
|
10
|
15
|
|
11
|
16
|
# Database initialization
|
12
|
|
-sqlite3 -init /opt/pyHeatpump/db/pyheatpump.sql /run/pyheatpump/pyheatpump.sqlite3 .quit \
|
|
17
|
+if [ ! -f $LIB_DIR/pyheatpump.sqlite3 ];
|
|
18
|
+then
|
|
19
|
+ sqlite3 -init $REPO_DIR/db/pyheatpump.sql $LIB_DIR/pyheatpump.sqlite3 .quit \
|
13
|
20
|
|| (echo "Failed to initialize database" && exit 1);
|
|
21
|
+fi
|
14
|
22
|
|
15
|
23
|
# Default configuration setup
|
16
|
|
-cp /opt/pyHeatpump/config/pyheatpump.prod.ini.dist /run/pyheatpump/pyheatpump.ini \
|
|
24
|
+if [ ! -f $LIB_DIR/pyheatpump.ini ];
|
|
25
|
+then
|
|
26
|
+ cp $REPO_DIR/config/pyheatpump.prod.ini.dist $LIB_DIR/pyheatpump.ini \
|
17
|
27
|
|| (echo "Failed to initialized configuration file" && exit 1);
|
|
28
|
+fi
|
18
|
29
|
|
19
|
30
|
exit 0;
|