From c29eb2fb23d54a8d4dd254cb0a7ce15620e8ee31 Mon Sep 17 00:00:00 2001 From: downtownallday Date: Mon, 23 Aug 2021 14:31:31 -0400 Subject: [PATCH] add 127.0.1.1 if it does not exist --- tests/lib/system.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/lib/system.sh b/tests/lib/system.sh index 10059f25..552ab86a 100644 --- a/tests/lib/system.sh +++ b/tests/lib/system.sh @@ -61,7 +61,14 @@ set_system_hostname() { # PRIMARY_HOSTNAME if no FQDN was given local fqdn="${1:-$PRIMARY_HOSTNAME}" local host="$(awk -F. '{print $1}' <<< "$fqdn")" - sed -i 's/^127\.0\.1\.1[ \t].*/127.0.1.1 '"$fqdn $host ip4-loopback/" /etc/hosts || return 1 + if ! grep '^127.0.1.1' /etc/hosts >/dev/null; then + # add it + echo "127.0.1.1 $fqdn $host" >> /etc/hosts || return 1 + else + # set it + sed -i 's/^127\.0\.1\.1[ \t].*/127.0.1.1 '"$fqdn $host ip4-loopback/" /etc/hosts || return 1 + fi + # ensure name is resolvable if ! /usr/bin/getent hosts "$fqdn" >/dev/null; then return 2 fi