Skip to content

Commit

Permalink
Set default EASYRSA_PKI to $EASYRSA/pki and some minor improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Apr 13, 2022
1 parent c18d7f2 commit 1d6a5f8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
40 changes: 21 additions & 19 deletions easyrsa3/easyrsa
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ warn() {
notice() {
[ "$EASYRSA_SILENT" ] && return
[ "$EASYRSA_BATCH" ] && return
print "* Notice: $1"
print "* Notice:
$1
"
} # => notice()

# yes/no case-insensitive match (operates on stdin pipe)
Expand Down Expand Up @@ -2087,7 +2089,7 @@ vars_setup() {
0)
unset -v found_vars
;;
1) : ;; #ok
1) : ;; # ok
*)
[ "$e_pki_vars" ] && print "Found: $pki_vars"
[ "$e_easy_vars" ] && print "Found: $easy_vars"
Expand Down Expand Up @@ -2156,7 +2158,7 @@ Sourcing the vars file will probably fail ..
# Set defaults, preferring existing env-vars if present
set_var EASYRSA "$PWD"
set_var EASYRSA_OPENSSL openssl
set_var EASYRSA_PKI "$PWD/pki"
set_var EASYRSA_PKI "$EASYRSA/pki"
set_var EASYRSA_DN cn_only
set_var EASYRSA_REQ_COUNTRY "US"
set_var EASYRSA_REQ_PROVINCE "California"
Expand Down Expand Up @@ -2237,6 +2239,22 @@ Sourcing the vars file will probably fail ..
fi
fi
fi

# Detect Windows
case "$OS" in
'') unset -v EASYRSA_WIN ;;
*) EASYRSA_WIN="$OS"
esac

# Detect Windows git/bash
case "${EXEPATH##*\\}" in
Git)
EASYRSA_WIN_GIT_BASH=Git-bash
[ -e /usr/bin/openssl ] && set_var EASYRSA_OPENSSL /usr/bin/openssl
;;
'') unset -v EASYRSA_WIN_GIT_BASH ;;
*) EASYRSA_WIN_GIT_BASH="$EXEPATH"
esac
} # vars_setup()

# variable assignment by indirection when undefined; merely exports
Expand Down Expand Up @@ -2958,22 +2976,6 @@ init-pki|clean-all) want_init_pki=1 ;;
*) unset -v want_init_pki
esac

# Detect Windows
case "$OS" in
'') unset -v EASYRSA_WIN ;;
*) EASYRSA_WIN="$OS"
esac

# Detect Windows git/bash
case "${EXEPATH##*\\}" in
Git)
EASYRSA_WIN_GIT_BASH=Git-bash
[ -e /usr/bin/openssl ] && set_var EASYRSA_OPENSSL /usr/bin/openssl
;;
'') unset -v EASYRSA_WIN_GIT_BASH ;;
*) EASYRSA_WIN_GIT_BASH="$EXEPATH"
esac

# Intelligent env-var detection and auto-loading:
vars_setup

Expand Down
21 changes: 18 additions & 3 deletions op-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ clean_up () {
if [ "$no_delete" ]; then
log "saved final state.."
else
log "op-test: clean_up"
if [ "$EASYRSA_NIX" ]; then
[ "$keep_eut" ] || rm -f "$utest_bin"
[ "$keep_sc" ] || rm -f "$sc_bin"
Expand Down Expand Up @@ -181,7 +182,7 @@ download_unit_test () {
# Run shellcheck
run_shellcheck () {
if [ "$enable_shellcheck" ] && [ "$sc_bin_ok" ] && [ "$EASYRSA_NIX" ]; then
# shellcheck easyrsa3/easyrsa
# shell-check easyrsa3/easyrsa
if [ -e easyrsa3/easyrsa ]; then
if "${sc_bin}" -s sh -S warning -x easyrsa3/easyrsa; then
log "shellcheck easyrsa3/easyrsa completed - ok"
Expand All @@ -192,7 +193,7 @@ run_shellcheck () {
log "easyrsa binary not present, not using shellcheck"
fi

# shellcheck easyrsa-unit-tests.sh
# shell-check easyrsa-unit-tests.sh
if [ -e easyrsa-unit-tests.sh ]; then
if "${sc_bin}" -s sh -S warning -x easyrsa-unit-tests.sh; then
log "shellcheck easyrsa-unit-tests.sh completed - ok"
Expand Down Expand Up @@ -239,7 +240,7 @@ download_shellcheck () {
else
log "version check failed: ${ERSA_UT}/${target_file}"
fi

log "shellcheck enabled"
else
log "curl_it ${target_file} - failed"
fi
Expand Down Expand Up @@ -307,12 +308,24 @@ download_opensslv3 () {

################################################################################

# Register clean_up on EXIT
#trap "exited 0" 0
# When SIGHUP, SIGINT, SIGQUIT, SIGABRT and SIGTERM,
# explicitly exit to signal EXIT (non-bash shells)
trap "clean_up" 1
trap "clean_up" 2
trap "clean_up" 3
trap "clean_up" 6
trap "clean_up" 15


unset -v disable_log verb enable_unit_test enable_shellcheck enable_openssl3 \
keep_sc keep_ssl keep_eut no_delete

# Set by default
enable_unit_test=1
enable_curl=1
EASYRSA_NIX=1

while [ -n "$1" ]; do
case "$1" in
Expand All @@ -326,6 +339,7 @@ while [ -n "$1" ]; do
-nt|--no-test) unset -v enable_unit_test ;;
-nc|--no-curl) unset -v enable_curl ;;
-nd|--no-delete) no_delete=1 ;;
-w|--windows) export EASYRSA_WIN=1; unset -v EASYRSA_NIX ;;
*)
log "Unknown option: $1"
exit 9
Expand Down Expand Up @@ -362,6 +376,7 @@ download_unit_test
run_shellcheck
run_unit_test

# No trap required..
clean_up

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion wop-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ echo "Invoke './easyrsa' to call the program. Without commands, help is displaye

cd ..

./op-test.sh -v
./op-test.sh -w -v

0 comments on commit 1d6a5f8

Please sign in to comment.