blob: 542a387d2170507fde9edd40e57024b42b95e641 (
plain)
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
|
From c7f9d14e38a1b6d40b2fffa01433a3025eff9abd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Bollo?= <jose.bollo@iot.bzh>
Date: Tue, 26 Nov 2019 12:34:39 +0100
Subject: [PATCH 14/14] Ensure post install initialization of database
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Creation of the database was made during image creation,
leading to issue with SOTA. This adds the creation on
need before launching the service.
Change-Id: Idfd0676bd87d39f7c10eaafd63f3a318f675c972
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
---
db/CMakeLists.txt | 14 ++++++--------
db/security-manager-setup | 14 ++++++++++++++
systemd/security-manager.service.in | 1 +
3 files changed, 21 insertions(+), 8 deletions(-)
create mode 100644 db/security-manager-setup
diff --git a/db/CMakeLists.txt b/db/CMakeLists.txt
index d7af1a0..dcf5bc8 100644
--- a/db/CMakeLists.txt
+++ b/db/CMakeLists.txt
@@ -1,12 +1,10 @@
-SET(TARGET_DB "$(DB_FILENAME)")
-
ADD_CUSTOM_COMMAND(
- OUTPUT ${TARGET_DB} ${TARGET_DB}-journal
- COMMAND sqlite3 ${TARGET_DB} <db.sql
- )
+ OUTPUT .security-manager-setup
+ COMMAND sed '/--DB\.SQL--/r db.sql' security-manager-setup > .security-manager-setup
+ DEPENDS security-manager-setup db.sql
+)
# Add a dummy build target to trigger building of ${TARGET_DB}
-ADD_CUSTOM_TARGET(DB ALL DEPENDS ${TARGET_DB})
+ADD_CUSTOM_TARGET(DB ALL DEPENDS .security-manager-setup)
-INSTALL(FILES ${TARGET_DB} DESTINATION ${DB_INSTALL_DIR})
-INSTALL(FILES ${TARGET_DB}-journal DESTINATION ${DB_INSTALL_DIR})
+INSTALL(PROGRAMS .security-manager-setup DESTINATION ${BIN_INSTALL_DIR})
diff --git a/db/security-manager-setup b/db/security-manager-setup
new file mode 100644
index 0000000..5675baf
--- /dev/null
+++ b/db/security-manager-setup
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+if test -f "$1"; then exit; fi
+set -e
+dbdir="$(dirname "$1")"
+dbfile="$(basename "$1")"
+test -n "$dbfile"
+test -n "$dbdir"
+mkdir -p "$dbdir"
+cd "$dbdir"
+sqlite3 "$dbfile" << END-OF-CAT
+--DB.SQL--
+END-OF-CAT
+
diff --git a/systemd/security-manager.service.in b/systemd/security-manager.service.in
index 23fd1b2..2bf97d7 100644
--- a/systemd/security-manager.service.in
+++ b/systemd/security-manager.service.in
@@ -3,5 +3,6 @@ Description=Start the security manager
[Service]
Type=notify
+ExecStartPre=@BIN_INSTALL_DIR@/.security-manager-setup @DB_INSTALL_DIR@/@DB_FILENAME@
ExecStart=@BIN_INSTALL_DIR@/security-manager
Sockets=security-manager.socket
--
2.21.0
|