Last active
September 24, 2025 20:35
-
-
Save dwallraff/cd6cedd3d89d9da446165fef8aaffb54 to your computer and use it in GitHub Desktop.
Convert scanned jpeg's to pdf/a with OCR and encrypts them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env bash | |
| #-- Dave Wallraff | |
| # First things first, I'm the realest... | |
| ### convert scans to OCR'd PDF/A, and encrypt them | |
| # curl -sL dwallraff.com/scanned | bash | |
| # wrap in a function for curl|bash | |
| do_stuff() { | |
| echo "Setting up..." | |
| echo "-------------" | |
| echo | |
| MY_OP_SESSION="${!OP_SESSION_*}" | |
| TODAY=$(date "+%Y%m%d") | |
| TEMPDIR=$(mktemp -d) | |
| mkdir -p "$TEMPDIR"/"$TODAY"_1password_backup/files || exit 1 | |
| BACKUPDIR="$TEMPDIR"/"$TODAY"_1password_backup | |
| # Check if op is installed | |
| if [ ! "$(command -v op)" ]; then | |
| echo "The op cli is not installed. Aborting..." | |
| exit 1 | |
| fi | |
| # Check if gpg is installed | |
| if [ ! "$(command -v gpg)" ]; then | |
| echo "gpg is not installed. Aborting..." | |
| exit 1 | |
| fi | |
| # Check if gpg is installed | |
| if [ ! "$(command -v img2pdf)" ]; then | |
| echo "gpg is not installed. Aborting..." | |
| exit 1 | |
| fi | |
| # Check if gpg is installed | |
| if [ ! "$(command -v ocrmypdf)" ]; then | |
| echo "gpg is not installed. Aborting..." | |
| exit 1 | |
| fi | |
| # Check to ee if we need to log in | |
| if [ "$MY_OP_SESSION" = "" ]; then | |
| echo "You're not logged into op" | |
| echo "eval \$(op signin)" | |
| exit 1 | |
| fi | |
| # Loop over jpegs, convert to pdf, and encrypt | |
| if ! exec 3<<<"$(op read op://Personal/secure_tarball_passphrase/password)"; then | |
| echo "Couldn't get tarball passphrase. Cleaning up and aborting..." | |
| rm -r "$TEMPDIR" | |
| exit 1 | |
| fi | |
| for i in *.jpeg; do | |
| echo "Converting $i..." | |
| img2pdf "$i" | ocrmypdf -j1 -q --output-type pdfa --pdfa-image-compression jpeg --optimize 3 --deskew --clean - "$TODAY"_"${i%%.*}".pdf | |
| exec 3<<<"$(op read op://Personal/secure_tarball_passphrase/password" | |
| gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output "$TODAY"_"${i%%.*}".pdf.enc "$TODAY"_"${i%%.*}".pdf | |
| done | |
| } | |
| do_stuff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment