diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-29 10:42:29 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-29 10:42:29 +0200 |
| commit | 4645998b64815d15aef6efe00dcbdfc4a045359e (patch) | |
| tree | 89665a54e8afcfc63c6ec4749c041d440432eaa6 /tests/machine-name.sh | |
| parent | dab41433688ff2247020d7a6fe12ac2140a75fb5 (diff) | |
| download | unified-desktop-theme-4645998b64815d15aef6efe00dcbdfc4a045359e.tar.gz unified-desktop-theme-4645998b64815d15aef6efe00dcbdfc4a045359e.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'tests/machine-name.sh')
| -rwxr-xr-x | tests/machine-name.sh | 28 |
1 files changed, 28 insertions, 0 deletions
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. <danix@danix.xyz> +# 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" |
