From 2c9c42b4142ab3e1089a1b1aa5980bbe4088b451 Mon Sep 17 00:00:00 2001 From: Rueben Ramirez Date: Tue, 8 Oct 2024 04:21:19 -0500 Subject: [PATCH] udhcp.user uci commit only new hostnames Instead of always committing a provided hostname, only commit new hostnames, where the new hostname doesn't match the current hostname. Resolves #442 --- openwrt/files/etc/udhcpc.user | 17 +++++++++-------- .../unit/openwrt/golden/ar71xx/etc/udhcpc.user | 17 +++++++++-------- .../unit/openwrt/golden/ipq806x/etc/udhcpc.user | 17 +++++++++-------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/openwrt/files/etc/udhcpc.user b/openwrt/files/etc/udhcpc.user index ce3b7424..5cd71567 100644 --- a/openwrt/files/etc/udhcpc.user +++ b/openwrt/files/etc/udhcpc.user @@ -21,17 +21,18 @@ case "$1" in /root/bin/apinger-pop.sh "$router" fi - if [ ! -z "$hostname" ]; then + if [ ! -z "$hostname" ] && [ `echo "$HOSTNAME" | tr '[A-Z]' '[a-z]'` != `echo "$hostname" | tr '[A-Z]' '[a-z]'` ]; then + # set new hostname uci set 'system.@system[0].hostname'="$hostname" uci commit - if [ `echo "$HOSTNAME" | tr '[A-Z]' '[a-z]'` != `echo "$hostname" | tr '[A-Z]' '[a-z]'` ]; then - # reload/restart whatever needs the hostname updated - /etc/init.d/system reload - service zabbix_agentd restart - service rsyslog restart - service lldpd restart - fi + + # reload/restart whatever needs the hostname updated + /etc/init.d/system reload + service zabbix_agentd restart + service rsyslog restart + service lldpd restart fi + if [ ! -z "$opt226" ]; then /root/bin/config-version.sh -c $(printf %d "0x$opt226") fi diff --git a/tests/unit/openwrt/golden/ar71xx/etc/udhcpc.user b/tests/unit/openwrt/golden/ar71xx/etc/udhcpc.user index ce3b7424..5cd71567 100644 --- a/tests/unit/openwrt/golden/ar71xx/etc/udhcpc.user +++ b/tests/unit/openwrt/golden/ar71xx/etc/udhcpc.user @@ -21,17 +21,18 @@ case "$1" in /root/bin/apinger-pop.sh "$router" fi - if [ ! -z "$hostname" ]; then + if [ ! -z "$hostname" ] && [ `echo "$HOSTNAME" | tr '[A-Z]' '[a-z]'` != `echo "$hostname" | tr '[A-Z]' '[a-z]'` ]; then + # set new hostname uci set 'system.@system[0].hostname'="$hostname" uci commit - if [ `echo "$HOSTNAME" | tr '[A-Z]' '[a-z]'` != `echo "$hostname" | tr '[A-Z]' '[a-z]'` ]; then - # reload/restart whatever needs the hostname updated - /etc/init.d/system reload - service zabbix_agentd restart - service rsyslog restart - service lldpd restart - fi + + # reload/restart whatever needs the hostname updated + /etc/init.d/system reload + service zabbix_agentd restart + service rsyslog restart + service lldpd restart fi + if [ ! -z "$opt226" ]; then /root/bin/config-version.sh -c $(printf %d "0x$opt226") fi diff --git a/tests/unit/openwrt/golden/ipq806x/etc/udhcpc.user b/tests/unit/openwrt/golden/ipq806x/etc/udhcpc.user index ce3b7424..5cd71567 100644 --- a/tests/unit/openwrt/golden/ipq806x/etc/udhcpc.user +++ b/tests/unit/openwrt/golden/ipq806x/etc/udhcpc.user @@ -21,17 +21,18 @@ case "$1" in /root/bin/apinger-pop.sh "$router" fi - if [ ! -z "$hostname" ]; then + if [ ! -z "$hostname" ] && [ `echo "$HOSTNAME" | tr '[A-Z]' '[a-z]'` != `echo "$hostname" | tr '[A-Z]' '[a-z]'` ]; then + # set new hostname uci set 'system.@system[0].hostname'="$hostname" uci commit - if [ `echo "$HOSTNAME" | tr '[A-Z]' '[a-z]'` != `echo "$hostname" | tr '[A-Z]' '[a-z]'` ]; then - # reload/restart whatever needs the hostname updated - /etc/init.d/system reload - service zabbix_agentd restart - service rsyslog restart - service lldpd restart - fi + + # reload/restart whatever needs the hostname updated + /etc/init.d/system reload + service zabbix_agentd restart + service rsyslog restart + service lldpd restart fi + if [ ! -z "$opt226" ]; then /root/bin/config-version.sh -c $(printf %d "0x$opt226") fi