From c751e229a1f8118787954d26bab4c300d114300e Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 11 Jan 2023 19:29:46 +0100 Subject: debvm-create: move functionality into support files The benefit of this change is that we don't have to escape that much. As a consequence, it becomes easier to put more code into the customization hooks, which have access to installed package versions. Thus we can reduce the use of DEBVER and thus improve working with snapshot.d.o. --- share/customize-autologin.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 share/customize-autologin.sh (limited to 'share/customize-autologin.sh') diff --git a/share/customize-autologin.sh b/share/customize-autologin.sh new file mode 100755 index 0000000..5592a03 --- /dev/null +++ b/share/customize-autologin.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# Copyright 2022 Helmut Grohne +# SPDX-License-Identifier: MIT +# +# This is a mmdebstrap customize hook that configures automatic root login on a +# serial console. + +set -eu + +TARGET=$1 + +UNIT=serial-getty@.service + +mkdir "$TARGET/etc/systemd/system/$UNIT.d" + +( + echo '[Service]' + echo 'ExecStart=' + sed -n 's,^ExecStart=-/sbin/agetty ,&-a root ,p' "$TARGET/lib/systemd/system/$UNIT" +) > "$TARGET/etc/systemd/system/$UNIT.d/autologin.conf" -- cgit v1.2.3 From 52202bfc705e433a170e78529558556b0976ae71 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 13 Jan 2023 07:04:28 +0100 Subject: automatically set up agetty TERM when possible * debvm-create will now parse a new kernel cmdline debvm.term and if present will pass its value to agetty as TERM. * debvm-run will now detect whether it is running in a terminal in non-graphic mode and pass its environment TERM variable as debvm.term to the kernel cmdline thus closing the loop. --- bin/debvm-run | 3 +++ share/customize-autologin.sh | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'share/customize-autologin.sh') diff --git a/bin/debvm-run b/bin/debvm-run index c2a3f21..4f7ff44 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -250,6 +250,9 @@ if test -z "$GRAPHICAL"; then KERNEL_CMDLINE="$KERNEL_CMDLINE console=ttyS0" ;; esac + if test -t 0 && test -t 1 && test -n "$TERM"; then + KERNEL_CMDLINE="$KERNEL_CMDLINE debvm.term=$TERM" + fi fi if test -n "$SSHPORT"; then diff --git a/share/customize-autologin.sh b/share/customize-autologin.sh index 5592a03..d7df555 100755 --- a/share/customize-autologin.sh +++ b/share/customize-autologin.sh @@ -3,7 +3,8 @@ # SPDX-License-Identifier: MIT # # This is a mmdebstrap customize hook that configures automatic root login on a -# serial console. +# serial console. It also parses the debvm.term kernel cmdline and passes it as +# TERM to agetty. set -eu @@ -15,6 +16,8 @@ mkdir "$TARGET/etc/systemd/system/$UNIT.d" ( echo '[Service]' + printf '%s\n' 'ExecStartPre=/bin/sed -n -e "s/.*\\(^\\| \\)debvm\\.term=\\([^ ]*\\).*/TERM=\\2/w/run/debvmterm" /proc/cmdline' + echo 'EnvironmentFile=-/run/debvmterm' echo 'ExecStart=' sed -n 's,^ExecStart=-/sbin/agetty ,&-a root ,p' "$TARGET/lib/systemd/system/$UNIT" ) > "$TARGET/etc/systemd/system/$UNIT.d/autologin.conf" -- cgit v1.2.3 From ca2cbf6d84dcc96845fcc6521aebe3b5076cdb32 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 13 Jan 2023 12:55:10 +0100 Subject: change cmdline variable debvm.term to TERM Jochen Sprickerhof found that systemd interprets the TERM variable according to our intended meaning and applies it to pid 1. It doesn't apply it to serial-getty, though so we keep that code for now. --- bin/debvm-run | 2 +- share/customize-autologin.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'share/customize-autologin.sh') diff --git a/bin/debvm-run b/bin/debvm-run index 839653c..6ed47c4 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -268,7 +268,7 @@ if test -z "$GRAPHICAL"; then ;; esac if test -t 0 && test -t 1 && test -n "$TERM"; then - KERNEL_CMDLINE="$KERNEL_CMDLINE debvm.term=$TERM" + KERNEL_CMDLINE="$KERNEL_CMDLINE TERM=$TERM" fi fi diff --git a/share/customize-autologin.sh b/share/customize-autologin.sh index d7df555..b9a4a8b 100755 --- a/share/customize-autologin.sh +++ b/share/customize-autologin.sh @@ -16,7 +16,7 @@ mkdir "$TARGET/etc/systemd/system/$UNIT.d" ( echo '[Service]' - printf '%s\n' 'ExecStartPre=/bin/sed -n -e "s/.*\\(^\\| \\)debvm\\.term=\\([^ ]*\\).*/TERM=\\2/w/run/debvmterm" /proc/cmdline' + printf '%s\n' 'ExecStartPre=/bin/sed -n -e "s/^\\(.* \\)\\?\\(TERM=[^ ]*\\).*/\\2/w/run/debvmterm" /proc/cmdline' echo 'EnvironmentFile=-/run/debvmterm' echo 'ExecStart=' sed -n 's,^ExecStart=-/sbin/agetty ,&-a root ,p' "$TARGET/lib/systemd/system/$UNIT" -- cgit v1.2.3