Page MenuHomeFreeBSD

D52250.id161215.diff
No OneTemporary

D52250.id161215.diff

diff --git a/usr.sbin/bsdinstall/scripts/auto b/usr.sbin/bsdinstall/scripts/auto
--- a/usr.sbin/bsdinstall/scripts/auto
+++ b/usr.sbin/bsdinstall/scripts/auto
@@ -265,6 +265,20 @@
fi
fi
+#
+# If we ran netconfig just now, it means we're going to download
+# something, so we need to set the clock, or we may fail to validate
+# server certificates.
+#
+if [ "$NETCONFIG_DONE" = yes ]; then
+ if [ -z "$BSDINSTALL_SKIP_TIME" ]; then
+ bsdinstall time
+ if [ -f /var/db/zoneinfo ]; then
+ export TZ=$(cat /var/db/zoneinfo)
+ fi
+ fi
+fi
+
rm -f $PATH_FSTAB
touch $PATH_FSTAB
@@ -445,6 +459,7 @@
if [ "$NETCONFIG_DONE" != yes ]; then
bsdinstall netconfig # Don't check for errors -- the user may cancel
fi
+# We may already have run this pre-install, re-run to install /etc/localtime
[ -z "$BSDINSTALL_SKIP_TIME" ] && bsdinstall time
[ -z "$BSDINSTALL_SKIP_SERVICES" ] && bsdinstall services
[ -z "$BSDINSTALL_SKIP_HARDENING" ] && bsdinstall hardening
diff --git a/usr.sbin/bsdinstall/scripts/time b/usr.sbin/bsdinstall/scripts/time
--- a/usr.sbin/bsdinstall/scripts/time
+++ b/usr.sbin/bsdinstall/scripts/time
@@ -2,6 +2,7 @@
#-
# Copyright (c) 2011 Nathan Whitehorn
# All rights reserved.
+# Copyright (c) 2025 Dag-Erling Smørgrav <des@FreeBSD.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -28,42 +29,112 @@
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
-# Select timezone
-chroot $BSDINSTALL_CHROOT tzsetup -s
+#
+# Strings that should be moved to an i18n file and loaded with f_include_lang()
+#
+msg_freebsd_installer="$OSNAME Installer"
+msg_time_date="Time & Date"
+msg_ok="OK"
+msg_skip="Skip"
+msg_set_date="Set Date"
+msg_set_time="Set Time"
+msg_please_enter_ntp_server="Please choose a time server to use."
+
+select_time_zone()
+{
+ if [ -d "$BSDINSTALL_CHROOT"/usr/share/zoneinfo ]; then
+ # post-install, check if we already ran pre-install
+ if [ -f /var/db/zoneinfo ]; then
+ # we did, install the timezone that was selected
+ cp -p /var/db/zoneinfo "$BSDINSTALL_CHROOT"/var/db/zoneinfo
+ tzsetup -C $BSDINSTALL_CHROOT -r
+ exit 0
+ else
+ # we did not, ask the user
+ tzsetup -C $BSDINSTALL_CHROOT -s
+ fi
+ export TZ=$(cat "$BSDINSTALL_CHROOT"/var/db/zoneinfo)
+ else
+ # pre-install, ask the user
+ # tzsetup will fail to create /etc/localtime but will create
+ # /var/db/zoneinfo which we can use in the interim.
+ tzsetup -Ns
+ export TZ=$(cat /var/db/zoneinfo)
+ fi
+}
+
+set_datetime_auto()
+{
+ if ! f_yesno "Attempt to set the date and time automatically?"; then
+ return 1
+ fi
+ local ntpserv=freebsd.pool.ntp.org
+ exec 5>&1
+ if ! ntpserv=$(bsddialog --backtitle "$msg_freebsd_installer" \
+ --title "$msg_time_date" \
+ --ok-label "$msg_ok" \
+ --cancel-label "$msg_skip" \
+ --inputbox "$msg_please_enter_ntp_server" \
+ 0 40 "$ntpserv" \
+ 2>&1 1>&5) || [ -z "$ntpserv" ]; then
+ exec 5>&-
+ return 1
+ fi
+ exec 5>&-
+ local ntperr
+ bsddialog --backtitle "$msd_freebsd_installer" \
+ --title "$msg_time_date" \
+ --infobox "Querying NTP server..." \
+ 0 40
+ if ! ntperr=$(ntpdate "$ntpserv" 2>&1); then
+ bsddialog --backtitle "$msd_freebsd_installer" \
+ --title "$msg_time_date" \
+ --msgbox "Failed to set the date and time:
+
+$(echo "${ntperr}" | sed 's/^.*\]: //')" \
+ 0 60
+ return 1
+ fi
+ bsddialog --backtitle "$msd_freebsd_installer" \
+ --title "$msg_time_date" \
+ --msgbox "The date and time were successfully set." \
+ 0 40
+ return 0
+}
-# Switch to target timezone
-saved_TZ="$TZ"
-TZ="${BSDINSTALL_CHROOT}/etc/localtime"
-export TZ
+set_datetime_manual()
+{
+ # Set date
+ exec 5>&1
+ local date
+ if date=$(bsddialog --backtitle "$msg_freebsd_installer" \
+ --title "$msg_time_date" \
+ --ok-label "$msg_set_date" \
+ --cancel-label "$msg_skip" \
+ --default-no \
+ --date-format '%Y%m%d%H%M.%S' \
+ --calendar '' 0 40 \
+ 2>&1 1>&5); then
+ date ${date}
+ fi
+ exec 5>&-
-# Set date
-exec 5>&1
-DATE=$(bsddialog --backtitle "$OSNAME Installer" \
- --title 'Time & Date' \
- --ok-label 'Set Date' \
- --cancel-label 'Skip' \
- --default-no \
- --date-format '%Y%m%d%H%M.%S' \
- --calendar '' 0 40 \
-2>&1 1>&5) && date $DATE
-exec 5>&-
+ # Set time
+ exec 5>&1
+ local time
+ if time=$(bsddialog --backtitle "$msg_freebsd_installer" \
+ --title "$msg_time_date" \
+ --ok-label "$msg_set_time" \
+ --cancel-label "$msg_skip" \
+ --default-no \
+ --time-format '%H%M.%S' \
+ --timebox '' 0 40 \
+ 2>&1 1>&5); then
+ date ${time}
+ fi
+ exec 5>&-
+}
-# Set time
-exec 5>&1
-TIME=$(bsddialog --backtitle "$OSNAME Installer" \
- --title 'Time & Date' \
- --ok-label 'Set Time' \
- --cancel-label 'Skip' \
- --default-no \
- --time-format '%H%M.%S' \
- --timebox '' 0 40 \
-2>&1 1>&5) && date $TIME
-exec 5>&-
+select_time_zone
-# Switch back
-if [ -n "$saved_TZ" ]; then
- TZ="$saved_TZ"
-else
- unset TZ
-fi
-unset saved_TZ
+set_datetime_auto || set_datetime_manual

File Metadata

Mime Type
text/plain
Expires
Wed, Jul 22, 6:30 PM (12 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35376475
Default Alt Text
D52250.id161215.diff (4 KB)

Event Timeline