Skip to content

Commit

Permalink
Final improvements to vars_setup()
Browse files Browse the repository at this point in the history
New standards introduced:
* Use '-e' to test for existence not '-f' file.
* Only use '-z' not '-n', more visually distinct.

Minor code improvement: Use 'if command' to test for success.

Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Apr 6, 2022
1 parent 678cac5 commit 7d1b008
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 12 additions & 9 deletions easyrsa3/easyrsa
Original file line number Diff line number Diff line change
Expand Up @@ -2033,9 +2033,10 @@ vars_setup() {
# vars of last resort - Eventually this file must be removed from EasyRSA
pwd_vars="$PWD/vars"

# Find vars
# Explicit command-line path:
if [ "$EASYRSA_VARS_FILE" ]; then
if [ -f "$EASYRSA_VARS_FILE" ]; then
if [ -e "$EASYRSA_VARS_FILE" ]; then
vars="$EASYRSA_VARS_FILE"
else
# If the --vars option does not point to a file, show helpful error.
Expand Down Expand Up @@ -2104,7 +2105,7 @@ Note: using Easy-RSA configuration from: $vars"
# EASYRSA_NO_VARS is defined or want_init_pki, no vars is required.
: # ok
fi
# END: Find vars 'the new way' followed by 'the old way' ..
# END: Find vars
fi

# Set defaults, preferring existing env-vars if present
Expand Down Expand Up @@ -2181,21 +2182,23 @@ Note: using Easy-RSA configuration from: $vars"

# Upgrade to 306: Create $EASYRSA_SSL_CONF if it does not exist
# but only if $EASYRSA_PKI exists.
if [ -d "$EASYRSA_PKI" ] && [ -f "$EASYRSA/openssl-easyrsa.cnf" ] && \
[ ! -f "$EASYRSA_SSL_CONF" ]
if [ -d "$EASYRSA_PKI" ] && [ -e "$EASYRSA/openssl-easyrsa.cnf" ] && \
[ ! -e "$EASYRSA_SSL_CONF" ]
then
cp "$EASYRSA/openssl-easyrsa.cnf" "$EASYRSA_SSL_CONF"
easyrsa_openssl makesafeconf
fi

else
# If the directory does not exist then we have not run init-pki
mkdir -p "$EASYRSA_TEMP_DIR" || \
if mkdir -p "$EASYRSA_TEMP_DIR"; then
EASYRSA_TEMP_DIR_session="$(
mktemp -du "$EASYRSA_TEMP_DIR/easy-rsa-$$.XXXXXX"
)"
rm -rf "$EASYRSA_TEMP_DIR"
else
die "Cannot create $EASYRSA_TEMP_DIR (permission?)"
EASYRSA_TEMP_DIR_session="$(
mktemp -du "$EASYRSA_TEMP_DIR/easy-rsa-$$.XXXXXX"
)"
rm -rf "$EASYRSA_TEMP_DIR"
fi
fi
fi
} # vars_setup()
Expand Down
2 changes: 2 additions & 0 deletions op-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if [ -e "shellcheck" ] && [ "$EASYRSA_NIX" ]; then
./shellcheck -V
if [ -e easyrsa3/easyrsa ]; then
./shellcheck -s sh -S warning -x easyrsa3/easyrsa
echo "* shellcheck completed *"
else
echo "* easyrsa binary not present, using path, no shellcheck"
fi
Expand All @@ -37,6 +38,7 @@ elif [ "$EASYRSA_NIX" ]; then
./shellcheck -V
if [ -e easyrsa3/easyrsa ]; then
./shellcheck -s sh -S warning -x easyrsa3/easyrsa
echo "* shellcheck completed *"
else
echo "* easyrsa binary not present, using path, no shellcheck"
fi
Expand Down

0 comments on commit 7d1b008

Please sign in to comment.