diff --git a/release/Makefile b/release/Makefile --- a/release/Makefile +++ b/release/Makefile @@ -250,11 +250,17 @@ echo loader_brand=\"install\" >> ${.TARGET}/boot/loader.conf echo loader_menu_multi_user_prompt=\"Installer\" >> ${.TARGET}/boot/loader.conf cp ${.CURDIR}/rc.local ${.TARGET}/etc + ln -fs /tmp/bsdinstall_tz/etc/localtime ${.TARGET}/etc/localtime + ln -fs /tmp/bsdinstall_tz/etc/wall_cmos_clock ${.TARGET}/etc/wall_cmos_clock + ln -fs /tmp/bsdinstall_tz/var/db/zoneinfo ${.TARGET}/var/db/zoneinfo echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG + echo "./etc/localtime type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_tz/etc/localtime" >> ${.TARGET}/METALOG + echo "./etc/wall_cmos_clock type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_tz/etc/wall_cmos_clock" >> ${.TARGET}/METALOG + echo "./var/db/zoneinfo type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_tz/var/db/zoneinfo" >> ${.TARGET}/METALOG touch ${.TARGET} bootonly: @@ -291,11 +297,17 @@ echo loader_brand=\"install\" >> ${.TARGET}/boot/loader.conf echo loader_menu_multi_user_prompt=\"Installer\" >> ${.TARGET}/boot/loader.conf cp ${.CURDIR}/rc.local ${.TARGET}/etc + ln -fs /tmp/bsdinstall_tz/etc/localtime ${.TARGET}/etc/localtime + ln -fs /tmp/bsdinstall_tz/etc/wall_cmos_clock ${.TARGET}/etc/wall_cmos_clock + ln -fs /tmp/bsdinstall_tz/var/db/zoneinfo ${.TARGET}/var/db/zoneinfo echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG + echo "./etc/localtime type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_tz/etc/localtime" >> ${.TARGET}/METALOG + echo "./etc/wall_cmos_clock type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_tz/etc/wall_cmos_clock" >> ${.TARGET}/METALOG + echo "./var/db/zoneinfo type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_tz/var/db/zoneinfo" >> ${.TARGET}/METALOG dvd: ${PKGBASE_REPO} # Install system @@ -347,11 +359,17 @@ echo loader_brand=\"install\" >> ${.TARGET}/boot/loader.conf echo loader_menu_multi_user_prompt=\"Installer\" >> ${.TARGET}/boot/loader.conf cp ${.CURDIR}/rc.local ${.TARGET}/etc + ln -fs /tmp/bsdinstall_tz/etc/localtime ${.TARGET}/etc/localtime + ln -fs /tmp/bsdinstall_tz/etc/wall_cmos_clock ${.TARGET}/etc/wall_cmos_clock + ln -fs /tmp/bsdinstall_tz/var/db/zoneinfo ${.TARGET}/var/db/zoneinfo echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG + echo "./etc/localtime type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_tz/etc/localtime" >> ${.TARGET}/METALOG + echo "./etc/wall_cmos_clock type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_tz/etc/wall_cmos_clock" >> ${.TARGET}/METALOG + echo "./var/db/zoneinfo type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_tz/var/db/zoneinfo" >> ${.TARGET}/METALOG touch ${.TARGET} disc1-disc1 disc1-memstick: disc1 diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc --- a/tools/build/mk/OptionalObsoleteFiles.inc +++ b/tools/build/mk/OptionalObsoleteFiles.inc @@ -422,9 +422,11 @@ OLD_FILES+=usr/libexec/bsdinstall/pkgbase OLD_FILES+=usr/libexec/bsdinstall/rootpass OLD_FILES+=usr/libexec/bsdinstall/runconsoles +OLD_FILES+=usr/libexec/bsdinstall/savetz OLD_FILES+=usr/libexec/bsdinstall/script OLD_FILES+=usr/libexec/bsdinstall/scriptedpart OLD_FILES+=usr/libexec/bsdinstall/services +OLD_FILES+=usr/libexec/bsdinstall/settime OLD_FILES+=usr/libexec/bsdinstall/startbsdinstall OLD_FILES+=usr/libexec/bsdinstall/time OLD_FILES+=usr/libexec/bsdinstall/umount diff --git a/usr.sbin/bsdinstall/bsdinstall b/usr.sbin/bsdinstall/bsdinstall --- a/usr.sbin/bsdinstall/bsdinstall +++ b/usr.sbin/bsdinstall/bsdinstall @@ -42,6 +42,7 @@ : ${TMPDIR:="/tmp"}; export TMPDIR : ${BSDINSTALL_TMPETC="${TMPDIR}/bsdinstall_etc"}; export BSDINSTALL_TMPETC +: ${BSDINSTALL_TMPTZ="${TMPDIR}/bsdinstall_tz"}; export BSDINSTALL_TMPTZ : ${BSDINSTALL_TMPBOOT="${TMPDIR}/bsdinstall_boot"}; export BSDINSTALL_TMPBOOT : ${PATH_FSTAB="$BSDINSTALL_TMPETC/fstab"}; export PATH_FSTAB : ${BSDINSTALL_DISTDIR="/usr/freebsd-dist"}; export BSDINSTALL_DISTDIR @@ -63,6 +64,7 @@ VERB="${1:-auto}"; shift [ -d "$BSDINSTALL_TMPETC" ] || mkdir -p "$BSDINSTALL_TMPETC" +[ -d "$BSDINSTALL_TMPTZ" ] || mkdir -p "$BSDINSTALL_TMPTZ" [ -d "$BSDINSTALL_TMPBOOT" ] || mkdir -p "$BSDINSTALL_TMPBOOT" # Only enable debugging if debugFile is non-NULL and can be initialized diff --git a/usr.sbin/bsdinstall/scripts/Makefile b/usr.sbin/bsdinstall/scripts/Makefile --- a/usr.sbin/bsdinstall/scripts/Makefile +++ b/usr.sbin/bsdinstall/scripts/Makefile @@ -21,7 +21,9 @@ netconfig_ipv6 \ pkgbase \ rootpass \ + savetz \ script \ + settime \ services \ time \ umount \ 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 @@ -194,6 +194,10 @@ trap error SIGINT # Catch cntrl-C here if [ -z "$BSDINSTALL_SKIP_HOSTNAME" ]; then bsdinstall hostname || error "Set hostname failed"; fi +if [ -z "$BSDINSTALL_SKIP_TIME" ]; then + bsdinstall settime || error "Failed to set current time" +fi + if [ -f /usr/freebsd-packages/repos/FreeBSD-base-offline.conf ]; then HAVE_BASE_PACKAGES=yes PKGBASE_DEFAULT_BUTTON=--default-no @@ -434,6 +438,10 @@ bsdinstall distextract || error "Distribution extract failed" fi +if [ -z "$BSDINSTALL_SKIP_TIME" ]; then + bsdinstall savetz || error "Failed to save time zone config" +fi + # Set up boot loader bsdinstall bootconfig || error "Failed to configure bootloader" @@ -445,7 +453,6 @@ if [ "$NETCONFIG_DONE" != yes ]; then bsdinstall netconfig # Don't check for errors -- the user may cancel fi -[ -z "$BSDINSTALL_SKIP_TIME" ] && bsdinstall time [ -z "$BSDINSTALL_SKIP_SERVICES" ] && bsdinstall services [ -z "$BSDINSTALL_SKIP_HARDENING" ] && bsdinstall hardening [ -z "$BSDINSTALL_SKIP_FIRMWARE" ] && bsdinstall firmware diff --git a/usr.sbin/bsdinstall/scripts/savetz b/usr.sbin/bsdinstall/scripts/savetz new file mode 100755 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/savetz @@ -0,0 +1,15 @@ +#!/bin/sh +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2025 Jessica Clarke +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +cp -P "${BSDINSTALL_TMPTZ}/etc/localtime" "${BSDINSTALL_CHROOT}/etc/localtime" +cp "${BSDINSTALL_TMPTZ}/var/db/zoneinfo" "${BSDINSTALL_CHROOT}/var/db/zoneinfo" +if [ -f "${BSDINSTALL_TMPTZ}/etc/wall_cmos_clock" ]; then + cp "${BSDINSTALL_TMPTZ}/etc/wall_cmos_clock" "${BSDINSTALL_CHROOT}/etc/wall_cmos_clock" +fi diff --git a/usr.sbin/bsdinstall/scripts/time b/usr.sbin/bsdinstall/scripts/settime copy from usr.sbin/bsdinstall/scripts/time copy to usr.sbin/bsdinstall/scripts/settime --- a/usr.sbin/bsdinstall/scripts/time +++ b/usr.sbin/bsdinstall/scripts/settime @@ -2,6 +2,7 @@ #- # Copyright (c) 2011 Nathan Whitehorn # All rights reserved. +# Copyright (c) 2025 Jessica Clarke # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -28,12 +29,23 @@ BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 +error() +{ + bsddialog --backtitle "$OSNAME Installer" --title "Error" --msgbox "$1" 0 0 + exit 1 +} + +mkdir -p "${BSDINSTALL_TMPTZ}/etc" || error "Could not create directory ${BSDINSTALL_TMPTZ}/etc" +mkdir -p "${BSDINSTALL_TMPTZ}/var/db" || error "Could not create directory ${BSDINSTALL_TMPTZ}/var/db" +ln -fs /usr "${BSDINSTALL_TMPTZ}/usr" || error "Could not create symlink ${BSDINSTALL_TMPTZ}/usr" + # Select timezone -chroot $BSDINSTALL_CHROOT tzsetup -s +tzsetup -s -C "${BSDINSTALL_TMPTZ}" -# Switch to target timezone +# Switch to target timezone whilst setting the date and time, even if not run +# from installation media (where /etc/localtime will be a symlink to this). saved_TZ="$TZ" -TZ="${BSDINSTALL_CHROOT}/etc/localtime" +TZ="${BSDINSTALL_TMPTZ}/etc/localtime" export TZ # Set date 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 @@ -1,69 +1,18 @@ #!/bin/sh #- -# Copyright (c) 2011 Nathan Whitehorn -# All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause # -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. +# Copyright (c) 2025 Jessica Clarke # BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 -# Select timezone -chroot $BSDINSTALL_CHROOT tzsetup -s - -# Switch to target timezone -saved_TZ="$TZ" -TZ="${BSDINSTALL_CHROOT}/etc/localtime" -export TZ - -# 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 -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>&- +error() +{ + bsddialog --backtitle "$OSNAME Installer" --title "Error" --msgbox "$1" 0 0 + exit 1 +} -# Switch back -if [ -n "$saved_TZ" ]; then - TZ="$saved_TZ" -else - unset TZ -fi -unset saved_TZ +bsdinstall settime || error "Failed to set current time" +bsdinstall savetz || error "Failed to save time zone config"