refactot encrytion- and decryption scripts.

This commit is contained in:
2026-08-03 15:43:39 +02:00
parent a318e1258c
commit 55f9a6f5b8
8 changed files with 476 additions and 111 deletions
+36 -7
View File
@@ -31,6 +31,9 @@ Modes:
$(basename "$0") vars.yml
$(basename "$0") -o output.yml vars.yml
Force whole-file encryption for a YAML file:
$(basename "$0") --full-file vars.yml
3) String encrypt:
$(basename "$0") 'mySecret'
echo 'mySecret' | $(basename "$0")
@@ -38,6 +41,7 @@ Modes:
Options:
-o FILE Write YAML output to FILE instead of stdout
--full-file Encrypt the given file in-place, even if it is .yml/.yaml
-h, --help Show this help and exit
Notes:
@@ -62,13 +66,37 @@ vencr() {
fi
########################################
# Optionales Output-File (-o)
# Optionen: Ausgabe-Datei und Vollverschluesselung fuer YAML-Dateien.
########################################
local out_file=""
if [[ "${1:-}" == "-o" && -n "${2:-}" ]]; then
out_file="$2"
shift 2
fi
local force_full_file=0
while [[ -n "${1:-}" && "${1:-}" == -* ]]; do
case "$1" in
-o)
if [[ -z "${2:-}" ]]; then
echo "Error: -o requires a file name." >&2
return 1
fi
out_file="$2"
shift 2
;;
--full-file)
force_full_file=1
shift
;;
-h|--help)
show_help
exit 0
;;
--)
shift
break
;;
*)
break
;;
esac
done
########################################
# --- 1) File als Argument ---
@@ -82,8 +110,9 @@ vencr() {
return 0
fi
# Fall B: YAML mit key: value Zeilen
if grep -Eq '^[[:space:]]*[A-Za-z0-9_.-]+:[[:space:]]*[^#].*$' "$f"; then
# Fall B: YAML mit key: value Zeilen nur fuer typische YAML-Dateien
# (damit z.B. README.md als normale Datei komplett verschluesselt wird).
if [[ $force_full_file -eq 0 ]] && [[ "$f" =~ \.(yml|yaml)$ ]] && grep -Eq '^[[:space:]]*[A-Za-z0-9_.-]+:[[:space:]]*[^#].*$' "$f"; then
local tmpout
tmpout="$(mktemp)"