diff options
author | U-Z690-A\user <jrayhawk@omgwallhack.org> | 2022-06-29 20:26:01 -0700 |
---|---|---|
committer | U-Z690-A\user <jrayhawk@omgwallhack.org> | 2022-06-29 20:26:01 -0700 |
commit | 585568aa8b851d153fbec0a46769b8f12e1df7f4 (patch) | |
tree | fc4d8daee10acdd48f33de0221a4dd31773f5289 /inimodify.sh | |
parent | 40e0db376ea51384fc2dbb7feb86d6d83408fe9f (diff) | |
download | cash-master.tar.gz cash-master.zip |
ekusub.sh has additionally been generalized into inimodify.sh in case I ever need it in the future for anything else.
Diffstat (limited to 'inimodify.sh')
-rwxr-xr-x | inimodify.sh | 36 |
1 files changed, 36 insertions, 0 deletions
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 |