Skip to content

Commit 6b8d5c9

Browse files
committed
Merge branch 'source_vars-improvements' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-source_vars-improvements
Signed-off-by: Richard T Bonhomme <[email protected]>
2 parents bc30886 + 12ecc1a commit 6b8d5c9

File tree

1 file changed

+18
-38
lines changed

1 file changed

+18
-38
lines changed

easyrsa3/easyrsa

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5558,48 +5558,38 @@ select_vars() {
55585558

55595559
# User specified PKI; if vars exists, use it ONLY
55605560
if [ "$EASYRSA_PKI" ]; then
5561-
if [ -f "$EASYRSA_PKI/vars" ]; then
5561+
if [ -f "$EASYRSA_PKI"/vars ]; then
5562+
set_var EASYRSA_VARS_FILE "$EASYRSA_PKI"/vars
55625563
verbose "select_vars: source EASYRSA_PKI/vars"
5563-
set_var EASYRSA_VARS_FILE "$EASYRSA_PKI/vars"
55645564
fi
55655565
fi
55665566

55675567
# User specified EASYRSA; if vars exists, use it ONLY
55685568
if [ "$EASYRSA" ]; then
5569-
if [ -f "$EASYRSA/vars" ]; then
5569+
if [ -f "$EASYRSA"/vars ]; then
5570+
set_var EASYRSA_VARS_FILE "$EASYRSA"/vars
55705571
verbose "select_vars: EASYRSA/vars"
5571-
set_var EASYRSA_VARS_FILE "$EASYRSA/vars"
55725572
fi
55735573
fi
55745574

55755575
# Default PKI; if vars exists, use it ONLY
5576-
if [ -f "$PWD/pki/vars" ] && \
5576+
if [ -f "$PWD"/pki/vars ] && \
55775577
[ -z "$EASYRSA_PKI" ] && \
55785578
[ -z "$EASYRSA" ]
55795579
then
5580-
# Prevent vars from changing expected PKI.
5580+
# Prevent vars from changing 'expected' PKI.
55815581
# A vars in the PKI MUST always imply EASYRSA_PKI
5582-
# This is NOT backward compatible
5583-
# Use expected value comparison for v3.1.7
5584-
if [ -z "$EASYRSA_VARS_FILE" ]; then
5585-
expected_EASYRSA="$PWD"
5586-
expected_EASYRSA_PKI="$PWD/pki"
5587-
fi
5588-
5589-
# Use this for v3.2.0
5590-
# If the pki/vars sets a different PKI then
5591-
# there will be no PKI in the default /pki
5592-
#set_var EASYRSA "$PWD"
5593-
#set_var EASYRSA_PKI "$EASYRSA/pki"
5582+
expected_EASYRSA="$PWD"
5583+
expected_EASYRSA_PKI="$PWD"/pki
55945584

5585+
set_var EASYRSA_VARS_FILE "$PWD"/pki/vars
55955586
verbose "select_vars: PWD/pki/vars"
5596-
set_var EASYRSA_VARS_FILE "$PWD/pki/vars"
55975587
fi
55985588

55995589
# Default working dir; if vars exists, use it ONLY
5600-
if [ -f "$PWD/vars" ]; then
5590+
if [ -f "$PWD"/vars ]; then
5591+
set_var EASYRSA_VARS_FILE "$PWD"/vars
56015592
verbose "select_vars: PWD/vars"
5602-
set_var EASYRSA_VARS_FILE "$PWD/vars"
56035593
fi
56045594
fi
56055595

@@ -5615,17 +5605,12 @@ source_vars() {
56155605
# File to be sourced
56165606
target_file="$1"
56175607

5618-
# 'vars' MUST not be a directory
5619-
[ -d "$target_file" ] && user_error "\
5620-
Missing vars file:
5621-
* $target_file"
5622-
5623-
# 'vars' now MUST exist
5608+
# target_file MUST exist
56245609
[ -f "$target_file" ] || user_error "\
56255610
Missing vars file:
56265611
* $target_file"
56275612

5628-
# Sanitize vars
5613+
# Sanitize target_file
56295614
if grep -q \
56305615
-e 'EASYRSA_PASSIN' -e 'EASYRSA_PASSOUT' \
56315616
-e '[^(]`[^)]' \
@@ -5685,28 +5670,23 @@ Please, correct these errors and try again."
56855670
verbose "source_vars: CLEAN '$target_file'"
56865671
fi
56875672

5688-
# Enable sourcing 'vars'
5689-
# shellcheck disable=SC2034 # appears unused - source_vars()
5673+
# Enable sourcing target_file
5674+
# shellcheck disable=SC2034 # EASYRSA_CALLER appears unused
56905675
EASYRSA_CALLER=1
5691-
easyrsa_path="$PATH"
5692-
# shellcheck disable=SC2123 # PATH is - source_vars()
5693-
PATH=./
56945676

5695-
# Test sourcing 'vars' in a subshell
5677+
# Test sourcing target_file in a subshell
56965678
# shellcheck disable=1090 # can't follow - source_vars()
56975679
if ( . "$target_file" ); then
5698-
# Source 'vars' now
5680+
# Source target_file now
56995681
# shellcheck disable=1090 # can't follow - source_vars()
57005682
. "$target_file" || \
57015683
die "Failed to source the '$target_file' file."
57025684
else
5703-
PATH="$easyrsa_path"
57045685
die "Failed to dry-run the '$target_file' file."
57055686
fi
57065687

5707-
PATH="$easyrsa_path"
57085688
verbose "source_vars: sourced OK '$target_file'"
5709-
unset -v EASYRSA_CALLER easyrsa_path target_file
5689+
unset -v EASYRSA_CALLER target_file
57105690
} # => source_vars()
57115691

57125692
# Set defaults

0 commit comments

Comments
 (0)