Minor changes to /etc/hosts file handling.

This commit is contained in:
Tom Mortensen
2025-12-05 12:17:26 -08:00
parent 01b0e024a9
commit d0e94e4a40
2 changed files with 13 additions and 10 deletions

View File

@@ -225,10 +225,10 @@ if [[ -r /boot/config/ident.cfg ]]; then
. <(/usr/bin/fromdos </boot/config/ident.cfg)
NAME=${NAME//[^a-zA-Z\-\.0-9]/\-}
fi
hostname "$NAME"
hostname -s >/etc/hostname
/bin/hostname "$NAME"
/bin/hostname -s >/etc/hostname
/bin/echo "# Generated" >/etc/hosts
/bin/echo "127.0.0.1 $NAME localhost" >>/etc/hosts
/bin/echo "127.0.0.1 $NAME localhost" >>/etc/hosts
# LimeTech - restore the configured timezone
if [[ $timeZone == custom ]]; then

View File

@@ -51,19 +51,19 @@ disable(){
sed -ri "s/^#?(use-$1)=.*/\1=no/" $CONF
}
# when starting avahidaemon, add name.local to the hosts file
# add name.local to the hosts file
add_local_to_hosts(){
local OLD="^127\.0\.0\.1.*"
local NEW="127.0.0.1 $NAME $NAME.local localhost"
sed -i "s/$OLD/$NEW/gm;t" $HOSTS
local NEW="127.0.0.1 $NAME $NAME.local localhost"
sed -i "s/$OLD/$NEW/" $HOSTS
return 0
}
# when stopping avahidaemon, remove name.local from the hosts file
# remove name.local from the hosts file
remove_local_from_hosts(){
local OLD="^127\.0\.0\.1.*"
local NEW="127.0.0.1 $NAME localhost"
sed -i "s/$OLD/$NEW/gm;t" $HOSTS
local NEW="127.0.0.1 $NAME localhost"
sed -i "s/$OLD/$NEW/" $HOSTS
return 0
}
@@ -113,7 +113,10 @@ avahid_restart(){
}
avahid_reload(){
$AVAHI --reload 2>/dev/null
if avahid_running; then
add_local_to_hosts
$AVAHI --reload 2>/dev/null
fi
}
avahid_update(){