Added first boot service for AGL 07/8507/1
authorRonan Le Martret <ronan.lemartret@iot.bzh>
Wed, 15 Feb 2017 15:34:51 +0000 (16:34 +0100)
committerronan Le Martret <ronan@iot.bzh>
Fri, 17 Feb 2017 10:19:03 +0000 (10:19 +0000)
 * Allow script execution at the end of the boot.
 * Yocto first boot service is install at for "sysinit.target" level.
   AGL need to have a custom service, exec when target service system,
   (SYSTEMD_SERVICE_AFTER), is up.
 * All script inside directory "/etc/agl-postinsts" will be exec at
   the first boot.
 * After the first boot the service "run-agl-postinsts.service"
   is disable.

Change-Id: Ib12b7e11b451b4a41c4a31f5cda3686679fe9c08
Signed-off-by: Ronan Le Martret <ronan.lemartret@iot.bzh>
(cherry picked from commit 67f1d7f631f20dfb4be3765ec32dfcd237d649c5)

meta-agl/recipes-core/packagegroups/packagegroup-core-boot-agl.bb
meta-agl/recipes-devtools/run-agl-postinsts/run-agl-postinsts/run-agl-postinsts [new file with mode: 0755]
meta-agl/recipes-devtools/run-agl-postinsts/run-agl-postinsts/run-agl-postinsts.service [new file with mode: 0644]
meta-agl/recipes-devtools/run-agl-postinsts/run-agl-postinsts_1.0.bb [new file with mode: 0644]

index 7ed4d79..26f572c 100644 (file)
@@ -35,6 +35,7 @@ RDEPENDS_${PN} = "\
     base-files \
     base-passwd \
     busybox \
+    run-agl-postinsts \
     ${@bb.utils.contains("DISTRO_FEATURES", "sysvinit", "${SYSVINIT_SCRIPTS}", "", d)} \
     ${@bb.utils.contains("MACHINE_FEATURES", "keyboard", "${VIRTUAL-RUNTIME_keymaps}", "", d)} \
     netbase \
diff --git a/meta-agl/recipes-devtools/run-agl-postinsts/run-agl-postinsts/run-agl-postinsts b/meta-agl/recipes-devtools/run-agl-postinsts/run-agl-postinsts/run-agl-postinsts
new file mode 100755 (executable)
index 0000000..7c2effa
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# Copyright 2017 IoT.bzh.
+
+# Author: Ronan Le Martret <ronan.lemartret@iot.bzh>
+#
+
+# The following script will run all the scriptlets found in #SYSCONFDIR#/agl-postinsts.
+
+agl_pi_dir="#SYSCONFDIR#/agl-postinsts"
+
+POSTINST_LOGGING=1
+LOGFILE=/var/log/agl-postinstall.log
+
+[ -e $LOGFILE ] && mv ${LOGFILE} ${LOGFILE}.old.$(date +%F--%H%M.%S)
+
+append_log=">>$LOGFILE 2>&1"
+
+exec_postinst_scriptlets() {
+    for i in `ls $agl_pi_dir`; do
+        i=$agl_pi_dir/$i
+        echo "Running postinst $i..."
+        [ "$POSTINST_LOGGING" = "1" ] && eval echo "Running postinst $i..." $append_log
+        if [ -x $i ]; then
+            eval sh -c $i $append_log
+            rm $i
+        else
+            echo "ERROR: postinst $i failed."
+            [ "$POSTINST_LOGGING" = "1" ] && eval echo "ERROR: postinst $i failed." $append_log
+            remove_agl_pi_dir=0
+        fi
+    done
+}
+
+remove_agl_pi_dir=1
+exec_postinst_scriptlets
+
+# since all postinstalls executed successfully, remove the postinstalls directory
+if [ $remove_agl_pi_dir = 1 ]; then
+    rm -rf $agl_pi_dir
+fi
diff --git a/meta-agl/recipes-devtools/run-agl-postinsts/run-agl-postinsts/run-agl-postinsts.service b/meta-agl/recipes-devtools/run-agl-postinsts/run-agl-postinsts/run-agl-postinsts.service
new file mode 100644 (file)
index 0000000..d1b5063
--- /dev/null
@@ -0,0 +1,15 @@
+[Unit]
+Description=Run pending agl postinsts
+DefaultDependencies=no
+After=#SYSTEMD_SERVICE_AFTER#
+ConditionPathExistsGlob=#SYSCONFDIR#/agl-postinsts
+
+[Service]
+Type=oneshot
+ExecStart=#SBINDIR#/run-agl-postinsts
+ExecStartPost=#BASE_BINDIR#/systemctl disable run-agl-postinsts.service
+RemainAfterExit=No
+TimeoutSec=0
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-agl/recipes-devtools/run-agl-postinsts/run-agl-postinsts_1.0.bb b/meta-agl/recipes-devtools/run-agl-postinsts/run-agl-postinsts_1.0.bb
new file mode 100644 (file)
index 0000000..5b5e18a
--- /dev/null
@@ -0,0 +1,44 @@
+SUMMARY = "Runs AGL postinstall scripts on first boot of the target device"
+SECTION = "devel"
+
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
+                    file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
+
+SRC_URI = "file://run-agl-postinsts \
+           file://run-agl-postinsts.service"
+
+S = "${WORKDIR}"
+
+inherit allarch systemd
+
+SYSTEMD_SERVICE_${PN} = "run-agl-postinsts.service"
+
+SYSTEMD_SERVICE_AFTER ?= "dbus.service cynara.service"
+
+do_configure() {
+    :
+}
+
+do_compile () {
+    :
+}
+
+do_install() {
+    install -d ${D}${sbindir}
+    install -m 0755 ${WORKDIR}/run-agl-postinsts ${D}${sbindir}/
+
+    install -d ${D}${systemd_unitdir}/system/
+    install -m 0644 ${WORKDIR}/run-agl-postinsts.service ${D}${systemd_unitdir}/system/
+
+    sed -i -e 's:#SYSCONFDIR#:${sysconfdir}:g' \
+               -e 's:#SBINDIR#:${sbindir}:g' \
+               -e 's:#BASE_BINDIR#:${base_bindir}:g' \
+               -e 's:#LOCALSTATEDIR#:${localstatedir}:g' \
+               ${D}${sbindir}/run-agl-postinsts \
+               ${D}${systemd_unitdir}/system/run-agl-postinsts.service
+    sed -i -e 's:#SYSTEMD_SERVICE_AFTER#:${SYSTEMD_SERVICE_AFTER}:g' \
+               ${D}${systemd_unitdir}/system/run-agl-postinsts.service
+}
+