From 17946f39b27a288bc861139056d577ce98093c4a Mon Sep 17 00:00:00 2001 From: Richard T Bonhomme Date: Tue, 10 Oct 2023 20:32:00 +0100 Subject: [PATCH] Improve select_vars() and source_vars() Allow reuse of select_vars() by not also calling source_vars(). Minor improvement to error detection in source_vars(). Signed-off-by: Richard T Bonhomme --- easyrsa3/easyrsa | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/easyrsa3/easyrsa b/easyrsa3/easyrsa index 31636e985..c26d21c4f 100755 --- a/easyrsa3/easyrsa +++ b/easyrsa3/easyrsa @@ -1376,6 +1376,8 @@ A vars file has not been created in your new PKI because conflicting vars files have been found elsewhere." prefer_vars_in_pki_msg else + unset -v EASYRSA_VARS_FILE + select_vars information " Using Easy-RSA configuration: * ${EASYRSA_VARS_FILE:-undefined}" @@ -5678,9 +5680,6 @@ select_vars() { No Easy-RSA 'vars' configuration file exists!" EASYRSA_NO_VARS=1 fi - - # source the vars file - source_vars "$EASYRSA_VARS_FILE" } # => select_vars() # Source a vars file @@ -5754,13 +5753,15 @@ Remove 'unset' ('force_set_var' may also work)." # Test sourcing 'vars' in a subshell # shellcheck disable=1090 # can't follow .. vars - ( . "$target_file" ) || \ + if ( . "$target_file" ); then + # Source 'vars' now + # shellcheck disable=1090 # can't follow .. vars + . "$target_file" || \ + die "Failed to source the '$target_file' file." + else + PATH="$easyrsa_path" die "Failed to dry-run the '$target_file' file." - - # Source 'vars' now - # shellcheck disable=1090 # can't follow .. vars - . "$target_file" || \ - die "Failed to source the '$target_file' file." + fi PATH="$easyrsa_path" verbose "source_vars: sourced OK '$target_file'" @@ -7218,8 +7219,12 @@ case "$cmd" in esac # Intelligent env-var detection and auto-loading: -# Select and source vars file +# Select vars file as EASYRSA_VARS_FILE select_vars + +# source the vars file +source_vars "$EASYRSA_VARS_FILE" + # then set defaults default_vars