update and change sysrepo persistency

In sysrepo commit c226ab1 (November 2020), some fields in the internal
sysrepo-monitoring module were renamed from pid to cid without a
revision bump of that module. If a post-November sysrepo ever runs on a
system with pre-November YANG module, sysrepo operations fail with this
error:

 Failed to find "cid" as a sibling to "sysrepo-monitoring:datastore".

...and we started hitting just that in our lab. Given that sysrepo
upstream strongly suggests only ever touching the repository content via
`sysrepocfg`, let's make sure that we follow their suggestion and save
data via `sysrepofg -X` and load them via `sysrepocfg -I`.

This required some dance in order to not break Netopeer's
initialization. I split its provisioning setup in two halves, so that it
installs YANG files (and enables all required features) first, then we
can inject the configuration, and then

Right now this means that we regenerate the NETCONF SSH host key during
each and every boot, but that's only a performance penalty since we
immediately overwrite that configuration via the version stored during
last boot. Still, it would be nice to fit that later.

Change-Id: Ib2060ea850d1121d5025183b6c5b17d8962f435b
Bug: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/206
Bug: https://github.com/sysrepo/sysrepo/issues/2280
diff --git a/package/czechlight-rauc/rauc-hook.sh b/package/czechlight-rauc/rauc-hook.sh
index 55d82b9..2899d4f 100755
--- a/package/czechlight-rauc/rauc-hook.sh
+++ b/package/czechlight-rauc/rauc-hook.sh
@@ -10,6 +10,7 @@
             etc \
             journald-remote \
             random-seed \
+            sysrepo \
             ssh-user-auth \
             ; do
           if [[ -d /cfg/${ITEM} || -f /cfg/${ITEM} ]]; then
@@ -34,6 +35,12 @@
   # No more netopeer2-keystored, different config
   rm -rf ${RAUC_SLOT_MOUNT_POINT}/etc/keystored
   echo "sysrepo configuration not preserved"
+elif [[ -d /cfg/etc/sysrepo ]]; then
+  # switch from "persisting whole /etc/sysrepo" to "exporting config via JSON"
+  rm -rf ${RAUC_SLOT_MOUNT_POINT}/etc/sysrepo
+  umask 0077
+  mkdir ${RAUC_SLOT_MOUNT_POINT}/sysrepo
+  sysrepocfg -d startup -f json -X > ${RAUC_SLOT_MOUNT_POINT}/sysrepo/startup.json
 fi
 
 exit 0