Skip to content

Commit

Permalink
udhcp.user uci commit only new hostnames
Browse files Browse the repository at this point in the history
Instead of always committing a provided hostname, only commit new hostnames, where
the new hostname doesn't match the current hostname.

Resolves #442
  • Loading branch information
ruebenramirez authored and sarcasticadmin committed Nov 4, 2024
1 parent 42f5a74 commit 2eab0f5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
17 changes: 9 additions & 8 deletions openwrt/files/etc/udhcpc.user
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,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
Expand Down
17 changes: 9 additions & 8 deletions tests/unit/openwrt/golden/ar71xx/etc/udhcpc.user
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions tests/unit/openwrt/golden/ipq806x/etc/udhcpc.user
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2eab0f5

Please sign in to comment.