summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml8
-rw-r--r--README.md2
-rwxr-xr-xbin/debvm-create (renamed from debvm-create)34
-rwxr-xr-xbin/debvm-run (renamed from debvm-run)3
-rwxr-xr-xbin/debvm-waitssh (renamed from debvm-waitssh)0
-rwxr-xr-xshare/customize-autologin.sh23
-rwxr-xr-xshare/customize-dpkgavailable.sh12
-rwxr-xr-xshare/customize-networkd.sh37
-rwxr-xr-xshare/customize-resolved.sh26
9 files changed, 113 insertions, 32 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 456e8d9..29e0783 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,14 +5,14 @@ shellcheck:
- apt-get update
- apt-get dist-upgrade --yes
- apt-get --no-install-recommends --yes install shellcheck
- - shellcheck -P tests debvm-* tests/*.sh
+ - shellcheck -P tests bin/* share/*.sh tests/*.sh
codespell:
script:
- apt-get update
- apt-get dist-upgrade --yes
- apt-get --no-install-recommends --yes install codespell
- - codespell debvm-* tests/*.sh
+ - codespell bin/* share/*.sh tests/*.sh
release_test:
parallel:
@@ -28,7 +28,7 @@ release_test:
- apt-get update
- apt-get dist-upgrade --yes
- apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client qemu-kvm
- - PATH=.:$PATH ./tests/create-and-run.sh $(dpkg --print-architecture) "$RELEASE"
+ - PATH=$(pwd)/bin:$PATH ./tests/create-and-run.sh $(dpkg --print-architecture) "$RELEASE"
arch_test:
parallel:
@@ -46,4 +46,4 @@ arch_test:
- apt-get update
- apt-get dist-upgrade --yes
- apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client qemu-system binfmt-support arch-test qemu-user-static
- - PATH=.:$PATH ./tests/create-and-run.sh "$ARCHITECTURE" sid
+ - PATH=$(pwd)/bin:$PATH ./tests/create-and-run.sh "$ARCHITECTURE" sid
diff --git a/README.md b/README.md
index 5ccbf12..6f042d7 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ invocation.
The following two invocations will give you a shell inside a qemu virtual
machine of the native architecture, leaving all the settings at their defaults:
- ./debvm-create && ./debvm-run
+ ./bin/debvm-create && ./bin/debvm-run
What do I need?
===============
diff --git a/debvm-create b/bin/debvm-create
index d21fd7b..59811e8 100755
--- a/debvm-create
+++ b/bin/debvm-create
@@ -130,6 +130,8 @@ SSHKEY=
SUITE=unstable
VMNAME=testvm
+SHARE_DIR="${0%/*}/../share"
+
nth_arg() {
shift "$1"
printf "%s" "$1"
@@ -296,17 +298,8 @@ fi
if ! check_skip systemdnetwork; then
# add a DNS resolver
- if test "$DEBVER" -ge 9; then
- INCLUDE_PACKAGES="$INCLUDE_PACKAGES,libnss-resolve"
- fi
- if test "$DEBVER" -le 11; then
- set -- '--customize-hook=chroot "$1" systemctl enable systemd-resolved.service' "$@"
- fi
- if test "$DEBVER" -le 9; then
- set -- '--customize-hook=ln -fs ../run/systemd/resolve/resolv.conf "$1/etc/resolv.conf"' "$@"
- elif test "$DEBVER" -le 11; then
- set -- '--customize-hook=ln -fs ../run/systemd/resolve/stub-resolv.conf "$1/etc/resolv.conf"' "$@"
- fi
+ INCLUDE_PACKAGES="$INCLUDE_PACKAGES,?exact-name(libnss-resolve)"
+ set -- "--customize-hook=$SHARE_DIR/customize-resolved.sh" "$@"
fi
# construct mmdebstrap options as $@:
@@ -331,15 +324,7 @@ set -- '--customize-hook=chroot "$1" passwd --delete root' "$@"
if ! check_skip systemdnetwork; then
# dhcp on all network interfaces
- SYSD_NET_MATCH='Name=en*\n'
- test "$DEBVER" -le 8 && SYSD_NET_MATCH="${SYSD_NET_MATCH}Name=eth*\\n"
- SYSD_NET_NET='DHCP=yes\n'
- # This anchor is included by default since bullseye. Fails DNSSEC validation when missing.
- test "$DEBVER" -le 11 && SYSD_NET_NET="${SYSD_NET_NET}DNSSECNegativeTrustAnchors=home.arpa\\n"
- set -- \
- '--customize-hook=chroot "$1" systemctl enable systemd-networkd.service' \
- "--customize-hook=printf \"[Match]\\n$SYSD_NET_MATCH\\n[Network]\\n$SYSD_NET_NET"'\n[DHCP]\nUseDomains=yes\n" > "$1/etc/systemd/network/20-wired.network"' \
- "$@"
+ set -- "--customize-hook=$SHARE_DIR/customize-networkd.sh" "$@"
fi
# add ssh key for root
@@ -352,9 +337,7 @@ fi
if ! check_skip packagelists; then
set -- --skip=cleanup/apt/lists "$@"
-
- # We need /var/lib/dpkg/available for dpkg --set-selections to work.
- set -- '--customize-hook=chroot "$1" apt-cache dumpavail | chroot "$1" dpkg --update-avail' "$@"
+ set -- "--customize-hook=$SHARE_DIR/customize-dpkgavailable.sh" "$@"
fi
if test "$DEBVER" -le 8; then
@@ -369,10 +352,7 @@ if test "$DEBVER" -ge 12 && ! check_skip usrmerge; then
set -- --hook-dir=/usr/share/mmdebstrap/hooks/merged-usr "$@"
fi
-set -- \
- '--customize-hook=mkdir "$1/etc/systemd/system/serial-getty@.service.d"' \
- "--customize-hook=sed -n -e '1i[Service]' -e '1iExecStart=' -e 's,^ExecStart=-/sbin/agetty ,&-a root ,p'"' "$1/lib/systemd/system/serial-getty@.service" > "$1/etc/systemd/system/serial-getty@.service.d/autologin.conf"' \
- "$@"
+set -- "--customize-hook=$SHARE_DIR/customize-autologin.sh" "$@"
# suite target mirror
set -- "$@" "$SUITE" "$IMAGE" "deb $MIRROR $SUITE main"
diff --git a/debvm-run b/bin/debvm-run
index 6f48089..839653c 100755
--- a/debvm-run
+++ b/bin/debvm-run
@@ -267,6 +267,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/debvm-waitssh b/bin/debvm-waitssh
index 82eb14d..82eb14d 100755
--- a/debvm-waitssh
+++ b/bin/debvm-waitssh
diff --git a/share/customize-autologin.sh b/share/customize-autologin.sh
new file mode 100755
index 0000000..d7df555
--- /dev/null
+++ b/share/customize-autologin.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+# Copyright 2022 Helmut Grohne <helmut@subdivi.de>
+# SPDX-License-Identifier: MIT
+#
+# This is a mmdebstrap customize hook that configures automatic root login on a
+# serial console. It also parses the debvm.term kernel cmdline and passes it as
+# TERM to agetty.
+
+set -eu
+
+TARGET=$1
+
+UNIT=serial-getty@.service
+
+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"
diff --git a/share/customize-dpkgavailable.sh b/share/customize-dpkgavailable.sh
new file mode 100755
index 0000000..f35b81f
--- /dev/null
+++ b/share/customize-dpkgavailable.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+# Copyright 2022 Helmut Grohne <helmut@subdivi.de>
+# SPDX-License-Identifier: MIT
+#
+# This is a mmdebstrap customize hook that initializes dpkg's available
+# database from an updated apt package list cache.
+#
+# Without the available database, dpkg --set-selections won't work.
+
+set -eu
+
+APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-cache dumpavail | dpkg --root "$1" --update-avail
diff --git a/share/customize-networkd.sh b/share/customize-networkd.sh
new file mode 100755
index 0000000..c89aae2
--- /dev/null
+++ b/share/customize-networkd.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+# Copyright 2022 Helmut Grohne <helmut@subdivi.de>
+# SPDX-License-Identifier: MIT
+#
+# This is a mmdebstrap customize hook that enables and configures
+# systemd-networkd on various Debian releases.
+
+set -eu
+
+TARGET=$1
+
+SYSTEMD_VERSION=$(dpkg-query --root "$TARGET" -f '${Version}' -W systemd)
+
+if test "${MMDEBSTRAP_MODE:-}" = chrootless; then
+ systemctl --root "$TARGET" enable systemd-networkd.service
+else
+ chroot "$TARGET" systemctl enable systemd-networkd.service
+fi
+
+{
+ echo '[Match]'
+ echo 'Name=en*'
+ if dpkg --compare-versions "$SYSTEMD_VERSION" lt 220-7~; then
+ echo 'Name=eth*'
+ fi
+
+ echo '[Network]'
+ echo 'DHCP=yes'
+
+ if dpkg --compare-versions "$SYSTEMD_VERSION" lt 249; then
+ # This anchor is included by default since bullseye. Fails DNSSEC
+ # validation when missing.
+ echo 'DNSSECNegativeTrustAnchors=home.arpa'
+ fi
+ echo '[DHCP]'
+ echo 'UseDomains=yes'
+} >"$TARGET/etc/systemd/network/20-wired.network"
diff --git a/share/customize-resolved.sh b/share/customize-resolved.sh
new file mode 100755
index 0000000..e8fe248
--- /dev/null
+++ b/share/customize-resolved.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Copyright 2022 Helmut Grohne <helmut@subdivi.de>
+# SPDX-License-Identifier: MIT
+#
+# This is a mmdebstrap customize hook that enables systemd-resolved on various
+# Debian releases.
+
+set -eu
+
+TARGET=$1
+
+LIBNSS_RESOLVE_VERSION=$(dpkg-query --root "$TARGET" -f '${Version}' -W libnss-resolve 2>/dev/null) || :
+
+if dpkg --compare-versions "$LIBNSS_RESOLVE_VERSION" lt 251.3-2~exp1; then
+ if test "${MMDEBSTRAP_MODE:-}" = chrootless; then
+ systemctl --root "$TARGET" enable systemd-resolved.service
+ else
+ chroot "$TARGET" systemctl enable systemd-resolved.service
+ fi
+
+ if test -z "$LIBNSS_RESOLVE_VERSION"; then
+ ln -fs ../run/systemd/resolve/resolv.conf "$TARGET/etc/resolv.conf"
+ else
+ ln -fs ../run/systemd/resolve/stub-resolv.conf "$TARGET/etc/resolv.conf"
+ fi
+fi