From 25a1d6a4356f1df04fea4f8ba355733aabc03837 Mon Sep 17 00:00:00 2001 From: Ian Leonard Date: Sat, 25 Mar 2023 04:08:37 +0000 Subject: [PATCH 1/2] systemd: network-base: alter hosts.conf if contents still default add license header and shellcheck change too Signed-off-by: Ian Leonard --- .../systemd/scripts/network-base-setup | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/sysutils/systemd/scripts/network-base-setup b/packages/sysutils/systemd/scripts/network-base-setup index 58b0ec557e..a857c5f47a 100755 --- a/packages/sysutils/systemd/scripts/network-base-setup +++ b/packages/sysutils/systemd/scripts/network-base-setup @@ -1,4 +1,11 @@ #!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2019-present Team LibreELEC (https://libreelec.tv) + +check_hosts() { + grep -v "^#" /run/libreelec/hosts | grep "${1}" +} + # setup hostname if [ -f /storage/.cache/hostname ]; then @@ -9,13 +16,27 @@ fi rm -f /run/libreelec/hosts if [ -f /storage/.config/hosts.conf ]; then cat /storage/.config/hosts.conf > /run/libreelec/hosts + # add localhost to hosts if not present + LOCALHOST_HOSTS=$(check_hosts "localhost") + if [ -z "${LOCALHOST_HOSTS}" ]; then + { + echo "127.0.0.1 localhost" + echo "::1 localhost ip6-localhost ip6-loopback" + } >> /run/libreelec/hosts + fi + # add HOSTNAME to hosts if not present + HOSTNAME=$(cat /proc/sys/kernel/hostname) + HOSTNAME_HOSTS=$(check_hosts "${HOSTNAME}") + if [ -z "${HOSTNAME_HOSTS}" ]; then + echo "127.0.1.1 ${HOSTNAME}" >> /run/libreelec/hosts + fi fi # setup /etc/resolv.conf rm -f /run/libreelec/resolv.conf if [ -f /storage/.config/resolv.conf ]; then cat /storage/.config/resolv.conf > /run/libreelec/resolv.conf -elif [ -f /dev/.kernel_ipconfig -a -f /proc/net/pnp ]; then +elif [ -f /dev/.kernel_ipconfig ] && [ -f /proc/net/pnp ]; then cat /proc/net/pnp > /run/libreelec/resolv.conf else cat << EOF > /run/libreelec/resolv.conf From 95d00c5318641b4d4257ba72b431376b56c92f3e Mon Sep 17 00:00:00 2001 From: Ian Leonard Date: Tue, 28 Mar 2023 00:54:21 +0000 Subject: [PATCH 2/2] systemd: hosts.conf: update comments Signed-off-by: Ian Leonard --- packages/sysutils/systemd/config/hosts.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sysutils/systemd/config/hosts.conf b/packages/sysutils/systemd/config/hosts.conf index 82ec2eea77..d2aa073bb5 100644 --- a/packages/sysutils/systemd/config/hosts.conf +++ b/packages/sysutils/systemd/config/hosts.conf @@ -3,8 +3,8 @@ # This configuration file allows you to manually map hostnames to # IP addresses -# Format: -# Example: 192.168.0.3 libreelec libreelec.mynetwork +# Format: +# Example: 192.168.0.3 libreelec.mynetwork libreelec # NOTE: do not edit /etc/hosts directly # edit /storage/.config/hosts.conf then reboot