From 7be3b198fbc1b985db5ba16548442d3988a0a377 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Mon, 8 May 2023 21:49:53 +0200 Subject: [PATCH] Avoid set empty hostname Avaoid situation where we end up with an empty /etc/hostname. --- lib/tiny-cloud/init | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/tiny-cloud/init b/lib/tiny-cloud/init index 580ab2d..8fd06ed 100644 --- a/lib/tiny-cloud/init +++ b/lib/tiny-cloud/init @@ -198,7 +198,16 @@ init__enable_sshd() { init__set_hostname() { local fqdn=$(imds @hostname) + if [ -z "$fqdn" ]; then + log info "No hostname set" + return + fi + local host="${fqdn%%\.*}" + if [ -z "$host" ]; then + log err "$fqdn is not a valid hostname" + return 1 + fi mkdir -p "$ROOT"/etc echo "$host" > "$ROOT"/etc/hostname