From 4402ce96643b39688f2c4f5a9fc22b7cc2ff9b52 Mon Sep 17 00:00:00 2001
From: Steven Baltakatei Sandoval <baltakatei@gmail.com>
Date: Sat, 6 Jan 2024 22:31:03 +0000
Subject: [PATCH 1/1] feat(user/gpg_encrypt_batch.sh):Add gpg batch encryption
 script

---
 user/gpg_encrypt_batch.sh | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 user/gpg_encrypt_batch.sh

diff --git a/user/gpg_encrypt_batch.sh b/user/gpg_encrypt_batch.sh
new file mode 100644
index 0000000..1f82290
--- /dev/null
+++ b/user/gpg_encrypt_batch.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# Desc: Encrypts a batch of files in the current working directory according to a find pattern.
+# Usage: gpg_encrypt_batch.sh [PATH key] [PATTERN]
+# Example: gpg_encrypt_batch.sh "/tmp/key.txt" "*.tar.xz"
+# Depends: Bash 5.1.16, gpg (GnuPG) 2.2.27, libgcrypt 1.9.4
+# Version: 0.0.1
+
+PATH_KEY="$1"; # symmetric encryption passphrase is first line of this file
+FIND_PATTERN="$2"; # adjust me (e.g. "*.tar.xz")
+
+passphrase="$(head -n1 "$PATH_KEY")"; # first line
+
+while read -r line; do
+    printf "STATUS:Beginning encryption of:%s\n" "$line"; sleep 1;
+    time gpg --symmetric --no-symkey-cache \
+         --passphrase "$passphrase" \
+         --pinentry-mode loopback \
+         --cipher-algo AES256 --no-armor \
+         --batch --yes \
+         --output "$line".gpg \
+         "$line" && \
+        printf "STATUS:Finished encrypting:%s\n" "$line" 1>&2 &
+done < <(find . -maxdepth 1 -type f -name "$FIND_PATTERN" | sort);
-- 
2.39.5