From nobody Sun Jun 1 13:07:20 2025 X-Original-To: dev-commits-src-main@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 4b9HLw5ZGsz5xf3y; Sun, 01 Jun 2025 13:07: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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b9HLw4gXpz49y0; Sun, 01 Jun 2025 13:07:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748783240; 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=aanBzAwn/X1QPE5ZDWT1PtIOkx4R8ZTraA6CP3qRB1U=; b=rdmzsKgYG9BX3xh3pvthiToxT8ELGENXMye1XBWcK5iiOnGKrIB7+60EZso5LQdHcdSgn9 WDaowMucOpTh5G1nUPD25xsJHFh3r2G6SywQC5tadwIQFyrghYAUksL3J/5qIPJVmwnup/ LzoGQGfrtDrTRCt+v5V3Krb3mHwnftSvNuj2fTOYADRSyX8txvTOZUJyh1tqLMHjitU/Cu VMNYnUOhgC4KvXsjIni5CxRhoPiKl38fPCe+UFAF5CJGgE1pQMUWzyPfLPRse9kY6K7l6i ZGVgbzZdto4O2VySzfCpBuxf3PRGTAU7/dWorsSU1VIDCy9nBcfbdUsBEQUw/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748783240; 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=aanBzAwn/X1QPE5ZDWT1PtIOkx4R8ZTraA6CP3qRB1U=; b=H3BnvELiik2Kr0UyfEOK88vQ3Jq8b9dbOsnQUJrnr32v4dqaKoWKHhaslN6ujCEQHPzitd 145Eo7DDX9IuClhjlGkV4GU0JrHRFk9TXxJlDPAn7VWZW6ZJpkNTK5TjUQi1dMGoTsJVlJ f/DxsBMguGTVTUjqKO7LY8OQB9ZQ99fhwlGNAAIrTuhnbPTLBQPYoLhhWHUrqLYf16Qo1m qUxY9AZdTOGHNMoa93NIcyKsW9TXg3Dbu7nH1uHaJTK6jpcIVP59XDfgwF9LF5zCJsR6XP B/HWpZJTLhuMl/H/ljXFu5R9zhade3Ffu3SueWJmkdfgqjC2UueSulb/cRKMQQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1748783240; a=rsa-sha256; cv=none; b=BgHXAw76SurBIAJf/MqObeBsUvrYMjcay5oyMvoVY8m6NADkFM/b/kp2gI0gbasiarzy85 aRZ2eiwJcmldKN20GyC+8FBpk/k0MFBKkSezrYc8S+LRE8+LKuqGTdYLwkSLroC6DAtWKp w1PZp3fxHEHA0pZx4XDXBfb2vrbf1xJxpax58PC14peUcuZhouLEPz3wnJEvyP4mLNukqN IiRgGAGfUojpXlHOyh+/6G9vEzQIKrle/hjFw1S5O3W6O+lFOmBFZ261em8gtgGzDuGZgb seH2/2MpAN+bCyn55817sf+SS/uSOH8V5J95enUIvoMsOdThON6C0HzlpTAs8w== 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 4b9HLw3g07z7rQ; Sun, 01 Jun 2025 13:07:20 +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 551D7KOT066417; Sun, 1 Jun 2025 13:07:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 551D7Kt9066414; Sun, 1 Jun 2025 13:07:20 GMT (envelope-from git) Date: Sun, 1 Jun 2025 13:07:20 GMT Message-Id: <202506011307.551D7Kt9066414@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Pierre Pronchery Subject: git: 9de72af2cceb - main - bsdinstall: restore the environment when restarting List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 9de72af2cceb6fc4aead0990cccdf565531bc248 Auto-Submitted: auto-generated The branch main has been updated by khorben: URL: https://cgit.FreeBSD.org/src/commit/?id=9de72af2cceb6fc4aead0990cccdf565531bc248 commit 9de72af2cceb6fc4aead0990cccdf565531bc248 Author: Pierre Pronchery AuthorDate: 2025-05-23 15:50:42 +0000 Commit: Pierre Pronchery CommitDate: 2025-06-01 12:53:16 +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 --- usr.sbin/bsdinstall/scripts/auto | 33 ++++++++++++++++++++++++++ usr.sbin/bsdinstall/scripts/jail | 50 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/usr.sbin/bsdinstall/scripts/auto b/usr.sbin/bsdinstall/scripts/auto index fa67dbf671cc..d5ac14864d6b 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 641c9f8a22bc..4b2882dad477 100755 --- a/usr.sbin/bsdinstall/scripts/jail +++ b/usr.sbin/bsdinstall/scripts/jail @@ -31,12 +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 )" +############################################################ 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 @@ -48,7 +59,7 @@ error() { if [ $? -ne $BSDDIALOG_OK ]; then exit else - [ -z "$MIRROR_BUTTON" ] || unset BSDINSTALL_DISTSITE + environment_restore exec $0 $BSDINSTALL_CHROOT fi } @@ -111,11 +122,42 @@ distbase() { bsdinstall distextract || error "Distribution extract failed" } +# 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 )" + if [ -z "$1" ]; then error "Directory can not be empty\n\nUsage:\nbsdinstall jail directory" fi export BSDINSTALL_CHROOT=$1 +environment_save + rm -rf $BSDINSTALL_TMPETC mkdir $BSDINSTALL_TMPETC mkdir -p $1 || error "mkdir failed for $1"