Skip to content

Commit a5aac68

Browse files
committed
Fix to through fatal error on sethostname after numerous of tries
1 parent dfa7489 commit a5aac68

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

slib.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -465,24 +465,30 @@ detect_ip () {
465465

466466
# Set the hostname
467467
set_hostname () {
468-
i=0
468+
local i=0
469469
local forcehostname
470470
if [ ! -z "$1" ]; then
471471
forcehostname=$1
472472
fi
473-
while [ $i -eq 0 ]; do
473+
while [ $i -le 3 ]; do
474474
if [ -z "$forcehostname" ]; then
475475
local name
476476
name=$(hostname -f)
477477
log_error "Your system hostname $name is not fully qualified."
478478
printf "Please enter a fully qualified hostname (e.g.: host.example.com): "
479+
stty echo
479480
read -r line
481+
stty -echo
480482
else
481483
log_debug "Setting hostname to $forcehostname"
482484
line=$forcehostname
483485
fi
484486
if ! is_fully_qualified "$line"; then
487+
i=$((i + 1))
485488
log_warning "Hostname $line is not fully qualified."
489+
if [ "$i" = "4" ]; then
490+
fatal "Unable to set fully qualified hostname."
491+
fi
486492
else
487493
hostname "$line"
488494
echo "$line" > /etc/hostname
@@ -496,7 +502,7 @@ set_hostname () {
496502
log_debug "Adding new entry for hostname $line on $address to /etc/hosts."
497503
printf "%s\\t%s\\t%s\\n" "$address" "$line" "$shortname" >> /etc/hosts
498504
fi
499-
i=1
505+
i=4
500506
fi
501507
done
502508
}

0 commit comments

Comments
 (0)