From nobody Thu Jul 24 23:40:19 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bp6tr1XVXz625P0; Thu, 24 Jul 2025 23:40:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bp6tr0cYDz3WJj; Thu, 24 Jul 2025 23:40:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753400420; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sJZviwnWxXKr1io9bxZVQ53C5mOr1CRudtnwIXfkaEo=; b=u4QAIA7yZitPnPiFwcp+nHReFDyXK+I8taWdGh2cIPlvyUHxH8CG5NO7Gs00TNSEr4rJcY scoeqPg39PoBY0EYB2p9cjgEtLRTuGfBcOYZqIU7iDNOR/+mld4knQ0bWPaX/CGDbr0+8S zSBvd6Igtqhh4gPklGCCABDes+1M+stmi6cuGxCC/gCznEKcnRnddaxqQVmxqm/UgqJJVs azbMkLAP9t5DEFo1SQc1LZJLuw9u7lOwqheUZCnOTF6s3KtavrSqEh0qzbZMo9oYbQ7swP 2hYI8XNWnFqYy+NONgDKrZL1FUaQT/2Ut7reh6g11ZdtasdfmELpFMOovWCjDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753400420; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sJZviwnWxXKr1io9bxZVQ53C5mOr1CRudtnwIXfkaEo=; b=w4dnzUIZSaGP3FsNPUwFNycB8Sxvs9I3TXi/YrdAdm9N7O7B9kc8t+yG4AlD8GXHR44OOR LVhrUfNSZfS4L6b7xeVH4rl+hVB9z/1GQ0346cnDCRXAGp1FTRWXmholpVpwKAy2PtPvaf 2FydVOb4hGpDXTjJc+1L6Bb/Px246KfXPVTaHTDcR6K9qCQxTWiuco7lE78kAdMyvLuJKT TjdO9HfCS2KcqTxbY/lDbpuli88Xgv5fsVoVjT5X9EuEh/dvMwRMbGC2pBUJAcn4B5WFRU i1I1mPsHOqzLlz+GjXe+pMNaPEpyVq9E16SzeHkVjErNWC8GkrQnBwXN+2stXA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753400420; a=rsa-sha256; cv=none; b=gpyO1ww+/5uFrT1So5Aii5+QMYCMon7wQSLDROmfoApBjZSDXGY3CfcJYm4vfg0mo9InlJ meZ0enKB+/WD4ZObd3RtRIjZGW+yIeyRoNdb2ckINUPVjdNciEgKQOZFm+tZ+eSrRYYGJ5 VL4gwgdBRLTuvY/JqNIW6sn7ugcITFSlfXzDysibyg0zS/zmGB0uMxlWvvWjJkjQXcGI/H 1BmYDZ9gPouiEYvn7124KVQH7ua0cjwSMsGB2QgX7gCselUe62rnCsDrEeTKUVdXXYmuLJ 5oXHLOHYR06hxOD5qLfcV841O3vQqkPboGh4wXchdZUpRDG+0djOFydZqYIjWg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bp6tq6rrVz4Xv; Thu, 24 Jul 2025 23:40:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56ONeJXu097955; Thu, 24 Jul 2025 23:40:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56ONeJ96097952; Thu, 24 Jul 2025 23:40:19 GMT (envelope-from git) Date: Thu, 24 Jul 2025 23:40:19 GMT Message-Id: <202507242340.56ONeJ96097952@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Pierre Pronchery Subject: git: d0d92b35d540 - stable/14 - bsdinstall: restore the environment when restarting List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: khorben X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: d0d92b35d5404243dc25dee8cf12b75288e0eacb Auto-Submitted: auto-generated The branch stable/14 has been updated by khorben: URL: https://cgit.FreeBSD.org/src/commit/?id=d0d92b35d5404243dc25dee8cf12b75288e0eacb commit d0d92b35d5404243dc25dee8cf12b75288e0eacb Author: Pierre Pronchery AuthorDate: 2025-05-23 15:50:42 +0000 Commit: Pierre Pronchery CommitDate: 2025-07-24 23:37:49 +0000 bsdinstall: restore the environment when restarting It is possible to restart the installation process upon errors, when installing normally through the `auto` script, or when installing a jail with the `jail` script. However, some values obtained interactively from the user or guessed by some scripts were kept in the environment when restarting the process; this made it impossible to re-run some steps as expected after the restart. For instance, if a bad choice of mirror was made in the `mirrorselect` phase, restarting the installer remembered the choice made, and would never prompt for a different one again. Rebooting was then the only easy way out of this situation. This change restores a pre-defined list of environment variables when restarting the installation process. PR: 266987 Reviewed by: emaste Approved by: philip (mentor) Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D42281 (cherry picked from commit 9de72af2cceb6fc4aead0990cccdf565531bc248) --- usr.sbin/bsdinstall/scripts/auto | 33 ++++++++++++++++++++++++++ usr.sbin/bsdinstall/scripts/jail | 51 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/usr.sbin/bsdinstall/scripts/auto b/usr.sbin/bsdinstall/scripts/auto index abd445282316..ab0191feea17 100755 --- a/usr.sbin/bsdinstall/scripts/auto +++ b/usr.sbin/bsdinstall/scripts/auto @@ -34,6 +34,13 @@ f_include $BSDCFG_SHARE/dialog.subr ############################################################ GLOBALS +# +# List of environment variables that may be defined by the user, but modified +# during the installation process. They are then restored when restarting this +# script. +# +user_env_vars="BSDINSTALL_DISTSITE DISTRIBUTIONS WORKAROUND_GPTACTIVE WORKAROUND_LENOVO ZFSBOOT_PARTITION_SCHEME" + # # Strings that should be moved to an i18n file and loaded with f_include_lang() # @@ -90,6 +97,7 @@ error() --yes-label "$msg_restart" \ --yesno "$prompt" $height $width then + environment_restore exec $0 # NOTREACHED fi @@ -138,10 +146,35 @@ dialog_workaround() --yesno "$prompt" $height $width } +# environment_restore +# +# Restore a list of environment variables when this script is restarted. +# +environment_restore() +{ + for var in $user_env_vars; do + eval "if [ -n \"\${ORIG_$var}\" -o -z \"\${ORIG_$var-z}\" ]; then $var=\${ORIG_$var}; else unset $var; fi" + done +} + +# environment_save +# +# Save any user-defined environment variable that may be modified during the +# installation process. They are then restored when restarting this script. +# +environment_save() +{ + for var in $user_env_vars; do + eval "if [ -n \"\${$var}\" -o -z \"\${$var-z}\" ]; then ORIG_$var=\${$var}; else unset ORIG_$var; fi" + done +} + ############################################################ MAIN f_dprintf "Began Installation at %s" "$( date )" +environment_save + rm -rf $BSDINSTALL_TMPETC mkdir $BSDINSTALL_TMPETC diff --git a/usr.sbin/bsdinstall/scripts/jail b/usr.sbin/bsdinstall/scripts/jail index e5822087e97b..191cc5e89563 100755 --- a/usr.sbin/bsdinstall/scripts/jail +++ b/usr.sbin/bsdinstall/scripts/jail @@ -31,13 +31,23 @@ BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 -############################################################ MAIN +############################################################ GLOBALS -: ${BSDDIALOG_OK=0} +# +# List of environment variables that may be defined by the user, but modified +# during the installation process. They are then restored when restarting this +# script. +# +user_env_vars="BSDINSTALL_DISTSITE DISTRIBUTIONS" -f_dprintf "Began Installation at %s" "$( date )" -export BSDINSTALL_CHROOT=$1 +############################################################ FUNCTIONS +# error [$msg] +# +# Display generic error message when a script fails. An optional message +# argument can preceed the generic message. User is given the choice of +# restarting the installer or exiting. +# error() { local msg if [ -n "$1" ]; then @@ -49,10 +59,43 @@ error() { if [ $? -ne $BSDDIALOG_OK ]; then exit else + environment_restore exec $0 $BSDINSTALL_CHROOT fi } +# environment_restore +# +# Restore a list of environment variables when this script is restarted. +# +environment_restore() +{ + for var in $user_env_vars; do + eval "if [ -n \"\${ORIG_$var}\" -o -z \"\${ORIG_$var-z}\" ]; then $var=\${ORIG_$var}; else unset $var; fi" + done +} + +# environment_save +# +# Save any user-defined environment variable that may be modified during the +# installation process. They are then restored when restarting this script. +# +environment_save() +{ + for var in $user_env_vars; do + eval "if [ -n \"\${$var}\" -o -z \"\${$var-z}\" ]; then ORIG_$var=\${$var}; else unset ORIG_$var; fi" + done +} + +############################################################ MAIN + +: ${BSDDIALOG_OK=0} + +f_dprintf "Began Installation at %s" "$( date )" +export BSDINSTALL_CHROOT=$1 + +environment_save + rm -rf $BSDINSTALL_TMPETC mkdir $BSDINSTALL_TMPETC mkdir -p $1 || error "mkdir failed for $1"