From 585568aa8b851d153fbec0a46769b8f12e1df7f4 Mon Sep 17 00:00:00 2001 From: "U-Z690-A\\user" Date: Wed, 29 Jun 2022 20:26:01 -0700 Subject: extendedKeyUsage: decommission ekusub.sh and use environment variables instead ekusub.sh has additionally been generalized into inimodify.sh in case I ever need it in the future for anything else. --- inimodify.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 inimodify.sh (limited to 'inimodify.sh') diff --git a/inimodify.sh b/inimodify.sh new file mode 100755 index 0000000..939e47a --- /dev/null +++ b/inimodify.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Dynamically modifies openssl config file +# ./inimodify.sh [header] [variable] [value] < openssl.cnf +# ./inimodify.sh "usr_cert" "extendedKeyUsage" "clientAuth, serverAuth" < openssl.cnf +#requires bash 4.0 regexes + +set -x +set -e +[ -n "$1" ] && HEADER="$1" || exit 2 +[ -n "$2" ] && VARIABLE="$2" || exit 3 +[ -n "$3" ] && VALUE="$3" || exit 4 + +IFS=$'\n' +HEADER_STANZA=0 +VARIABLE_MODIFIED=0 +while read line; do + if [[ "$line" =~ ^\ *\[\ *"$HEADER"\ *\] ]]; then + HEADER_STANZA=1 + echo "$line" + elif [ "$HEADER_STANZA" == 1 ] && [[ "$line" =~ ^\ *"$VARIABLE"\ *= ]]; then + echo -n "$line" + echo ", $VALUE" + VARIABLE_MODIFIED=1 + elif [ "$HEADER_STANZA" == 1 ] && [[ "$line" =~ ^\ *\[\ .+\ \] ]]; then + if [ "$VARIABLE_MODIFIED" == 0 ]; then + echo "$VARIABLE = $VALUE" + echo + VARIABLE_MODIFIED=1 + fi + HEADER_STANZA=0 + echo "$line" + else + echo "$line" + fi + +done -- cgit v1.2.3