]> git.kernelconcepts.de Git - meta-kc-bsp.git/commitdiff
custom-firststart: add sysvinit service to run scripts on first boot
authorFlorian Boor <florian@kernelconcepts.de>
Fri, 17 Aug 2018 14:08:18 +0000 (16:08 +0200)
committerFlorian Boor <florian@kernelconcepts.de>
Fri, 17 Aug 2018 14:11:06 +0000 (16:11 +0200)
recipes-bsp/startup/custom-firststart/banner.sh [new file with mode: 0755]
recipes-bsp/startup/custom-firststart/firststart.init [new file with mode: 0755]
recipes-bsp/startup/custom-firststart/firststart.sh [new file with mode: 0644]
recipes-bsp/startup/custom-firststart_1.0.bb [new file with mode: 0644]

diff --git a/recipes-bsp/startup/custom-firststart/banner.sh b/recipes-bsp/startup/custom-firststart/banner.sh
new file mode 100755 (executable)
index 0000000..0ee9fb6
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo Running firststart tasks
diff --git a/recipes-bsp/startup/custom-firststart/firststart.init b/recipes-bsp/startup/custom-firststart/firststart.init
new file mode 100755 (executable)
index 0000000..1d7e7d5
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+firststart.sh
diff --git a/recipes-bsp/startup/custom-firststart/firststart.sh b/recipes-bsp/startup/custom-firststart/firststart.sh
new file mode 100644 (file)
index 0000000..06aecb5
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+
+DIR="/#SYSCONFDIR#/firststart.d"
+DIR_OVERLAY_LOWER="/media/rfs/ro"
+
+remove_startup_link () {
+       if [ -n "`which update-rc.d`" ]; then
+               update-rc.d -f firststart remove
+       fi
+}
+
+if ! [ -d $DIR ]; then
+       remove_startup_link
+       exit 0
+fi
+
+echo "Running first boot tasks...."
+
+run-parts $DIR
+
+# check if we have a ro overlay or if we can write changes directly
+if [ -e "/media/rfs/ro" ]; then
+# using meta-readonly-rootfs-overlay
+       mount $DIR_OVERLAY_LOWER -o remount,rw
+       rm -r $DIR_OVERLAY_LOWER/$DIR
+       rm $DIR_OVERLAY_LOWER/#SYSCONFDIR#/rc*.d/S*firststart
+       rm $DIR_OVERLAY_LOWER/#SYSCONFDIR#/init.d/firststart
+       mount $DIR_OVERLAY_LOWER -o remount,ro
+else 
+       rm -rf $DIR
+       remove_startup_link
+fi
+
diff --git a/recipes-bsp/startup/custom-firststart_1.0.bb b/recipes-bsp/startup/custom-firststart_1.0.bb
new file mode 100644 (file)
index 0000000..1cc19c7
--- /dev/null
@@ -0,0 +1,40 @@
+SUMMARY = "Runs custom scripts on first boot of the target device"
+SECTION = "devel"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
+
+SRC_URI = " \
+       file://firststart.init \
+       file://firststart.sh \
+       file://banner.sh \
+"
+
+S = "${WORKDIR}"
+
+inherit allarch update-rc.d
+
+INITSCRIPT_NAME = "firststart"
+INITSCRIPT_PARAMS = "start 99 S ."
+
+do_configure() {
+       :
+}
+
+do_compile () {
+       :
+}
+
+do_install() {
+       install -d ${D}${sysconfdir}/firststart.d/
+       install -m 0755 ${WORKDIR}/banner.sh ${D}/${sysconfdir}/firststart.d/01banner
+       install -d ${D}${sysconfdir}/init.d/
+       install -m 0755 ${WORKDIR}/firststart.init ${D}${sysconfdir}/init.d/firststart
+       install -d ${D}${sbindir}
+       install -m 0755 ${WORKDIR}/firststart.sh ${D}${sbindir}/firststart.sh
+
+       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}/firststart.sh
+}