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 --- bin/udt-machine-name | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 bin/udt-machine-name (limited to 'bin/udt-machine-name') diff --git a/bin/udt-machine-name b/bin/udt-machine-name new file mode 100755 index 0000000..1a677eb --- /dev/null +++ b/bin/udt-machine-name @@ -0,0 +1,40 @@ +#!/bin/bash +# Set or show this machine's pretty hostname, PRETTY_HOSTNAME in +# /etc/machine-info. hostnamectl is systemd's writer; Slackware has neither, +# and the GRUB theme reads the name for its panel title. +# Copyright (C) 2026 Danilo M. +# Licensed under the GNU General Public License v2 only. +# +# udt-machine-name print the current name +# sudo udt-machine-name "My Box" set it +set -euo pipefail + +file="${UDT_MACHINE_INFO:-/etc/machine-info}" + +if [ $# -eq 0 ]; then + [ -f "$file" ] && sed -n 's/^PRETTY_HOSTNAME=//p' "$file" + exit 0 +fi +if [ $# -ne 1 ] || [ -z "$1" ]; then + echo "usage: $(basename "$0") [NAME]" >&2 + exit 2 +fi +case "$1" in + *[[:cntrl:]]*) echo "name must not contain control characters" >&2; exit 2 ;; +esac + +# Double-quoted, with only \ and " escaped: the escapes both systemd's reader +# and the GRUB build's shlex understand the same way. +value="$1" +value="${value//\\/\\\\}" +value="${value//\"/\\\"}" +line="PRETTY_HOSTNAME=\"$value\"" + +# Every other key in the file (ICON_NAME, CHASSIS, ...) is kept as it was. +tmp="$(mktemp "$file.XXXXXX")" +trap 'rm -f "$tmp"' EXIT +{ [ -f "$file" ] && grep -v '^PRETTY_HOSTNAME=' "$file" || true; echo "$line"; } > "$tmp" +chmod 644 "$tmp" +mv "$tmp" "$file" +trap - EXIT +echo "$line" -- cgit v1.2.3