From: Steven Baltakatei Sandoval Date: Sat, 6 Jan 2024 22:31:03 +0000 (+0000) Subject: feat(user/gpg_encrypt_batch.sh):Add gpg batch encryption script X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/4402ce96643b39688f2c4f5a9fc22b7cc2ff9b52?ds=inline;hp=--cc feat(user/gpg_encrypt_batch.sh):Add gpg batch encryption script --- 4402ce96643b39688f2c4f5a9fc22b7cc2ff9b52 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);