From c7f9d14e38a1b6d40b2fffa01433a3025eff9abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Bollo?= 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 --- 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} .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