From 9a6a2e4b7d203fe9c5ea4f335564f4797bb29a01 Mon Sep 17 00:00:00 2001 From: ykla Date: Sun, 18 May 2025 08:19:06 +0800 Subject: [PATCH] Warn if hostname is empty Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1700 --- usr.sbin/bsdinstall/scripts/hostname | 33 ++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/usr.sbin/bsdinstall/scripts/hostname b/usr.sbin/bsdinstall/scripts/hostname index 19df8885893..ec58ad5dfe6 100755 --- a/usr.sbin/bsdinstall/scripts/hostname +++ b/usr.sbin/bsdinstall/scripts/hostname @@ -54,7 +54,7 @@ msg_freebsd_installer="$OSNAME Installer" msg_ok="OK" msg_please_choose_a_hostname="Please choose a hostname for this machine.\n\nIf you are running on a managed network, please ask\nyour network administrator for an appropriate name." msg_set_hostname="Set Hostname" - +msg_empty_hostname_warning="The hostname is currently empty. This is not recommended, as many network services rely on a valid hostname. Are you sure you want to continue?" # # Command strings for various tasks # @@ -97,10 +97,35 @@ f_dialog_title "$msg_set_hostname" f_dialog_backtitle "$msg_freebsd_installer" # -# Get user input +# Get user input and Warn if hostname is empty # -HOSTNAME=$( dialog_hostname "$HOSTNAME" ) -[ $? -eq $DIALOG_CANCEL ] && exit 1 +while :; do + HOSTNAME=$(dialog_hostname "$HOSTNAME") + [ $? -eq $DIALOG_CANCEL ] && exit 1 + + if [ -z "$HOSTNAME" ]; then + if [ "$USE_XDIALOG" ]; then + yes=yes no=no defaultno=defaultno + extra_args="--wrap --left" + else + yes=yes no=no defaultno=defaultno + extra_args="--colors --cr-wrap" + fi + + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --defaultno \ + --yes-label "$yes" \ + --no-label "$no" \ + $extra_args \ + --yesno "$msg_empty_hostname_warning" 0 0 + + [ $? -ne 0 ] && continue + fi + + break +done # # Store the user's choice