]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
classes: rootfs-postcommands: autologin root on serial-getty
authorJohannes Schneider <johannes.schneider@leica-geosystems.com>
Tue, 2 Aug 2022 09:40:19 +0000 (11:40 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 12 Aug 2022 14:45:45 +0000 (15:45 +0100)
when empty-root-password AND serial-autologin-root are part of the
IMAGE_FEATURES, save some of the developers time by not having to type
the (then still sole) 'root' username on the serial console after each
and every reboot

this is done by inserting '--autologin root' into the command line of
the responsible 'getty' service

Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-recipe/core-image.bbclass
meta/classes-recipe/image.bbclass
meta/classes-recipe/rootfs-postcommands.bbclass
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty

index 7ef7d0739096a559cce9da047975dc5ef3d10a19..4b5f2c99c4beab352a057430396a6526ff206be1 100644 (file)
@@ -31,6 +31,7 @@
 #   - allow-empty-password
 #   - allow-root-login
 #   - post-install-logging
+# - serial-autologin-root - with 'empty-root-password': autologin 'root' on the serial console
 # - dev-pkgs            - development packages (headers, etc.) for all installed packages in the rootfs
 # - dbg-pkgs            - debug symbol packages for all installed packages in the rootfs
 # - lic-pkgs            - license packages for all installed pacakges in the rootfs, requires
index 433172378a8ea6a68f415d053057bfb8f7ac3dfc..e387645503adea51feef314c268927b9e2b234a6 100644 (file)
@@ -39,7 +39,7 @@ INHIBIT_DEFAULT_DEPS = "1"
 # IMAGE_FEATURES may contain any available package group
 IMAGE_FEATURES ?= ""
 IMAGE_FEATURES[type] = "list"
-IMAGE_FEATURES[validitems] += "debug-tweaks read-only-rootfs read-only-rootfs-delayed-postinsts stateless-rootfs empty-root-password allow-empty-password allow-root-login post-install-logging overlayfs-etc"
+IMAGE_FEATURES[validitems] += "debug-tweaks read-only-rootfs read-only-rootfs-delayed-postinsts stateless-rootfs empty-root-password allow-empty-password allow-root-login serial-autologin-root post-install-logging overlayfs-etc"
 
 # Generate companion debugfs?
 IMAGE_GEN_DEBUGFS ?= "0"
index d40adf5f0e9d2c8e0838448d4e6317e8b0f750ac..bf1e992bb275cff5f470e1c247eed40cfd2bc5a0 100644 (file)
@@ -13,6 +13,9 @@ ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'deb
 # Allow dropbear/openssh to accept root logins if debug-tweaks or allow-root-login is enabled
 ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-root-login' ], "ssh_allow_root_login; ", "",d)}'
 
+# Autologin the root user on the serial console, if empty-root-password and serial-autologin-root are active
+ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", [ 'empty-root-password', 'serial-autologin-root' ], "serial_autologin_root; ", "",d)}'
+
 # Enable postinst logging if debug-tweaks or post-install-logging is enabled
 ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'post-install-logging' ], "postinst_enable_logging; ", "",d)}'
 
@@ -201,6 +204,23 @@ ssh_allow_root_login () {
        fi
 }
 
+#
+# Autologin the 'root' user on the serial terminal,
+# if empty-root-password' AND 'serial-autologin-root are enabled
+#
+serial_autologin_root () {
+       if ${@bb.utils.contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then
+               # add autologin option to util-linux getty only
+               sed -i 's/options="/&--autologin root /' \
+                       "${IMAGE_ROOTFS}${base_bindir}/start_getty"
+       elif ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then
+               if [ -e ${IMAGE_ROOTFS}${systemd_system_unitdir}/serial-getty@.service ]; then
+                       sed -i '/^\s*ExecStart\b/ s/getty /&--autologin root /' \
+                               "${IMAGE_ROOTFS}${systemd_system_unitdir}/serial-getty@.service"
+               fi
+       fi
+}
+
 python sort_passwd () {
     import rootfspostcommands
     rootfspostcommands.sort_passwd(d.expand('${IMAGE_ROOTFS}${sysconfdir}'))
index 699a1ead1a402a5f50576db4fd23942837185de4..7106fb72fb5e9d2a1f45c6a78b4748e15eddc99d 100644 (file)
@@ -9,9 +9,10 @@ case $(readlink -f "${getty}") in
         if [ -x "/usr/bin/setsid" ] ; then
             setsid="/usr/bin/setsid"
         fi
+        options=""
         ;;
 esac
 
 if [ -e /sys/class/tty/$2 -a -c /dev/$2 ]; then
-       ${setsid:-} ${getty} -L $1 $2 $3
+       ${setsid:-} ${getty} ${options:-} -L $1 $2 $3
 fi