feat(unitproc/bkt-replace_contractions):Add Bash function
[BK-2020-03.git] / user / gpg_encrypt_batch.sh
... / ...
CommitLineData
1#!/bin/bash
2# Desc: Encrypts a batch of files in the current working directory according to a find pattern.
3# Usage: gpg_encrypt_batch.sh [PATH key] [PATTERN]
4# Example: gpg_encrypt_batch.sh "/tmp/key.txt" "*.tar.xz"
5# Depends: Bash 5.1.16, gpg (GnuPG) 2.2.27, libgcrypt 1.9.4
6# Version: 0.0.1
7
8PATH_KEY="$1"; # symmetric encryption passphrase is first line of this file
9FIND_PATTERN="$2"; # adjust me (e.g. "*.tar.xz")
10
11passphrase="$(head -n1 "$PATH_KEY")"; # first line
12
13while read -r line; do
14 printf "STATUS:Beginning encryption of:%s\n" "$line"; sleep 1;
15 time gpg --symmetric --no-symkey-cache \
16 --passphrase "$passphrase" \
17 --pinentry-mode loopback \
18 --cipher-algo AES256 --no-armor \
19 --batch --yes \
20 --output "$line".gpg \
21 "$line" && \
22 printf "STATUS:Finished encrypting:%s\n" "$line" 1>&2 &
23done < <(find . -maxdepth 1 -type f -name "$FIND_PATTERN" | sort);