From 4645998b64815d15aef6efe00dcbdfc4a045359e Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 29 Sep 2026 10:42:29 +0200 Subject: feat(bin): udt-machine-name writes PRETTY_HOSTNAME to /etc/machine-info The GRUB theme titles its panel with the machine's pretty name, and on Slackware nothing writes /etc/machine-info: hostnamectl is systemd's. This sets the one key, keeping any others, and with no argument prints it. The value is double-quoted with only \ and " escaped, the escapes systemd's reader and the GRUB build's shlex agree on; control characters are refused. It needs root and is never run by install.sh, which only suggests it in the GRUB output while no name is set. tests/machine-name.sh checks the quoting round-trip against shlex. Co-Authored-By: Claude Opus 5.5 --- tests/machine-name.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 tests/machine-name.sh (limited to 'tests') diff --git a/tests/machine-name.sh b/tests/machine-name.sh new file mode 100755 index 0000000..f8d9f6d --- /dev/null +++ b/tests/machine-name.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Check bin/udt-machine-name: quoting round-trips through shlex, other keys +# survive, a second set replaces rather than appends. +# Copyright (C) 2026 Danilo M. +# Licensed under the GNU General Public License v2 only. +set -euo pipefail + +repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +export UDT_MACHINE_INFO="$tmp/machine-info" + +printf 'ICON_NAME=computer\nPRETTY_HOSTNAME="old"\n' > "$UDT_MACHINE_INFO" +"$repo/bin/udt-machine-name" 'first' >/dev/null +"$repo/bin/udt-machine-name" 'Anne'"'"'s "Box" \ $HOME' >/dev/null + +[ "$(grep -c '^PRETTY_HOSTNAME=' "$UDT_MACHINE_INFO")" = 1 ] +grep -qx 'ICON_NAME=computer' "$UDT_MACHINE_INFO" +python3 - "$UDT_MACHINE_INFO" <<'PY' +import shlex, sys +line = next(l for l in open(sys.argv[1]) if l.startswith("PRETTY_HOSTNAME=")) +got = " ".join(shlex.split(line[len("PRETTY_HOSTNAME="):])) +assert got == 'Anne\'s "Box" \\ $HOME', got +PY +! "$repo/bin/udt-machine-name" $'a\nb' 2>/dev/null +! "$repo/bin/udt-machine-name" '' 2>/dev/null + +echo "machine-name OK" -- cgit v1.2.3