/cfg: config option for persistent storage of sysrepo's data
Change-Id: Ie29c1488f32b1739d2e6a197041de1883f848fe0
diff --git a/package/czechlight-cfg-fs/Config.in b/package/czechlight-cfg-fs/Config.in
index d44d14a..3974d6c 100644
--- a/package/czechlight-cfg-fs/Config.in
+++ b/package/czechlight-cfg-fs/Config.in
@@ -17,4 +17,14 @@
accommodate all configuration, but small enough to fit within the
corresponding partition.
+if BR2_PACKAGE_SYSREPO
+
+config CZECHLIGHT_CFG_FS_PERSIST_SYSREPO
+ bool "Persist sysrepo configuration into /cfg"
+ default Y
+ help
+ Save sysrepo's YANG files into /cfg upon changes
+
+endif # BR2_PACKAGE_SYSREPO
+
endif # BR2_PACKAGE_CZECHLIGHT_CFG_FS
diff --git a/package/czechlight-cfg-fs/czechlight-cfg-fs.mk b/package/czechlight-cfg-fs/czechlight-cfg-fs.mk
index 6798e68..9f28965 100644
--- a/package/czechlight-cfg-fs/czechlight-cfg-fs.mk
+++ b/package/czechlight-cfg-fs/czechlight-cfg-fs.mk
@@ -24,6 +24,12 @@
$(BR2_EXTERNAL_CZECHLIGHT_PATH)/package/czechlight-cfg-fs/cfg-restore-etc.service \
$(TARGET_DIR)/usr/lib/systemd/system/cfg-restore-etc.service
ln -sf ../cfg-restore-etc.service $(TARGET_DIR)/usr/lib/systemd/system/local-fs.target.wants/
+ $(ifeq ($(CZECHLIGHT_CFG_FS_PERSIST_SYSREPO),y))
+ $(INSTALL) -D -m 0644 \
+ $(BR2_EXTERNAL_CZECHLIGHT_PATH)/package/czechlight-cfg-fs/sysrepo-persistent-cfg.service \
+ $(TARGET_DIR)/usr/lib/systemd/system/
+ ln -sf ../sysrepo-persistent-cfg.service $(TARGET_DIR)/usr/lib/systemd/system/multi-user.target.wants/
+ $(endif)
endef
$(eval $(generic-package))
diff --git a/package/czechlight-cfg-fs/sysrepo-persistent-cfg.service b/package/czechlight-cfg-fs/sysrepo-persistent-cfg.service
new file mode 100644
index 0000000..fcb1d7e
--- /dev/null
+++ b/package/czechlight-cfg-fs/sysrepo-persistent-cfg.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Persisting persistent sysrepo datastores to /cfg
+After=sysrepod.service
+Requires=cfg.mount
+
+[Service]
+Type=simple
+ExecStart=/bin/sh -c 'while true; do inotifywait -e CLOSE_WRITE /etc/sysrepo/data/*.startup && mkdir -p /cfg/etc/sysrepo/data/ && cp -a /etc/sysrepo/data/*.startup /cfg/etc/sysrepo/data/; done'