Skip to content

Instantly share code, notes, and snippets.

@dwallraff
Last active September 24, 2025 20:35
Show Gist options
  • Save dwallraff/cd6cedd3d89d9da446165fef8aaffb54 to your computer and use it in GitHub Desktop.
Save dwallraff/cd6cedd3d89d9da446165fef8aaffb54 to your computer and use it in GitHub Desktop.

Revisions

  1. dwallraff revised this gist Sep 24, 2025. 2 changed files with 68 additions and 38 deletions.
    68 changes: 68 additions & 0 deletions convert_scanned_jpg_to_pdf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    #! /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
    38 changes: 0 additions & 38 deletions convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -1,38 +0,0 @@
    #! /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() {

    # Check if op is installed
    if [ ! "$(command -v op)" ]; then
    echo "The op cli is not installed. Aborting..."
    exit 1
    fi

    # Check if op is logged in
    if ! op whoami > /dev/null 2>&1; then
    echo "Not logged into 1password"
    echo "Please run: eval \"\$(op account add --account my.1password.comn --email [email protected] --address my.1password.com --signin)\""
    exit 1
    fi

    # Needed vars
    TODAY=$(date "+%Y%m%d")

    # Loop over jpegs, convert to pdf, and encrypt
    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 item get encrypted_tar_password --format json | jq -r '.fields[] | select(.id=="password") | .value')"
    gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output "$TODAY"_"${i%%.*}".pdf.enc "$TODAY"_"${i%%.*}".pdf
    done

    }

    do_stuff
  2. dwallraff revised this gist Nov 12, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ do_stuff() {
    # Loop over jpegs, convert to pdf, and encrypt
    for i in *.jpeg; do
    echo "Converting $i..."
    img2pdf "$i" | ocrmypdf -q --output-type pdfa --pdfa-image-compression jpeg --optimize 3 --deskew --clean - "$TODAY"_"${i%%.*}".pdf
    img2pdf "$i" | ocrmypdf -j1 -q --output-type pdfa --pdfa-image-compression jpeg --optimize 3 --deskew --clean - "$TODAY"_"${i%%.*}".pdf
    exec 3<<<"$(op item get encrypted_tar_password --format json | jq -r '.fields[] | select(.id=="password") | .value')"
    gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output "$TODAY"_"${i%%.*}".pdf.enc "$TODAY"_"${i%%.*}".pdf
    done
  3. dwallraff revised this gist Nov 12, 2023. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -17,9 +17,9 @@ do_stuff() {

    # Check if op is logged in
    if ! op whoami > /dev/null 2>&1; then
    echo "Not logged into 1password"
    echo "Please run: eval \"\$(op account add --account my.1password.comn --email [email protected] --address my.1password.com --signin)\""
    exit 1
    echo "Not logged into 1password"
    echo "Please run: eval \"\$(op account add --account my.1password.comn --email [email protected] --address my.1password.com --signin)\""
    exit 1
    fi

    # Needed vars
  4. dwallraff revised this gist Nov 12, 2023. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -16,10 +16,10 @@ do_stuff() {
    fi

    # Check if op is logged in
    if ! op user list > /dev/null 2>&1; then
    echo "Not logged into 1password"
    echo "Please run: eval \"\$(op signin)\""
    exit 1
    if ! op whoami > /dev/null 2>&1; then
    echo "Not logged into 1password"
    echo "Please run: eval \"\$(op account add --account my.1password.comn --email [email protected] --address my.1password.com --signin)\""
    exit 1
    fi

    # Needed vars
  5. dwallraff revised this gist Jul 30, 2022. No changes.
  6. dwallraff revised this gist Jul 30, 2022. 1 changed file with 36 additions and 17 deletions.
    53 changes: 36 additions & 17 deletions convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,38 @@
    #! /usr/bin/env bash
    #-- Dave Wallraff

    export TODAY=$(date "+%Y%m%d")

    # Check if op is logged in
    echo "Checking if op is logged in"
    op user list > /dev/null 2>&1
    # if not, log in or die trying
    if [ $? -ne 0 ]; then
    echo "Logging into op..."
    eval $(op signin)
    fi

    for i in $(ls *.jpeg); do
    echo "Converting $i..."
    img2pdf $i | ocrmypdf -q --output-type pdfa --pdfa-image-compression jpeg --optimize 3 --deskew --clean - "$TODAY"_${i%%.*}.pdf
    exec 3<<<"$(op item get encrypted_tar_password --format json | jq -r '.fields[] | select(.id=="password") | .value')"
    gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output "$TODAY"_${i%%.*}.pdf.enc "$TODAY"_${i%%.*}.pdf
    done
    # 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() {

    # Check if op is installed
    if [ ! "$(command -v op)" ]; then
    echo "The op cli is not installed. Aborting..."
    exit 1
    fi

    # Check if op is logged in
    if ! op user list > /dev/null 2>&1; then
    echo "Not logged into 1password"
    echo "Please run: eval \"\$(op signin)\""
    exit 1
    fi

    # Needed vars
    TODAY=$(date "+%Y%m%d")

    # Loop over jpegs, convert to pdf, and encrypt
    for i in *.jpeg; do
    echo "Converting $i..."
    img2pdf "$i" | ocrmypdf -q --output-type pdfa --pdfa-image-compression jpeg --optimize 3 --deskew --clean - "$TODAY"_"${i%%.*}".pdf
    exec 3<<<"$(op item get encrypted_tar_password --format json | jq -r '.fields[] | select(.id=="password") | .value')"
    gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output "$TODAY"_"${i%%.*}".pdf.enc "$TODAY"_"${i%%.*}".pdf
    done

    }

    do_stuff
  7. dwallraff revised this gist Jul 24, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ fi

    for i in $(ls *.jpeg); do
    echo "Converting $i..."
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - "$TODAY"_${i%%.*}.pdf
    img2pdf $i | ocrmypdf -q --output-type pdfa --pdfa-image-compression jpeg --optimize 3 --deskew --clean - "$TODAY"_${i%%.*}.pdf
    exec 3<<<"$(op item get encrypted_tar_password --format json | jq -r '.fields[] | select(.id=="password") | .value')"
    gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output "$TODAY"_${i%%.*}.pdf.enc "$TODAY"_${i%%.*}.pdf
    done
  8. dwallraff revised this gist Jul 23, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -15,5 +15,5 @@ for i in $(ls *.jpeg); do
    echo "Converting $i..."
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - "$TODAY"_${i%%.*}.pdf
    exec 3<<<"$(op item get encrypted_tar_password --format json | jq -r '.fields[] | select(.id=="password") | .value')"
    tar hcz ${i%%.*}.pdf | gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output "$TODAY"_${i%%.*}.pdf.tar.gz.enc
    gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output "$TODAY"_${i%%.*}.pdf.enc "$TODAY"_${i%%.*}.pdf
    done
  9. dwallraff revised this gist Jul 23, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ fi

    for i in $(ls *.jpeg); do
    echo "Converting $i..."
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - $TODAY_${i%%.*}.pdf
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - "$TODAY"_${i%%.*}.pdf
    exec 3<<<"$(op item get encrypted_tar_password --format json | jq -r '.fields[] | select(.id=="password") | .value')"
    tar hcz ${i%%.*}.pdf | gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output $TODAY_${i%%.*}.pdf.tar.gz.enc
    tar hcz ${i%%.*}.pdf | gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output "$TODAY"_${i%%.*}.pdf.tar.gz.enc
    done
  10. dwallraff revised this gist Jul 23, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ export TODAY=$(date "+%Y%m%d")

    # Check if op is logged in
    echo "Checking if op is logged in"
    op list users > /dev/null 2>&1
    op user list > /dev/null 2>&1
    # if not, log in or die trying
    if [ $? -ne 0 ]; then
    echo "Logging into op..."
  11. dwallraff revised this gist Jul 23, 2022. 1 changed file with 16 additions and 4 deletions.
    20 changes: 16 additions & 4 deletions convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,19 @@
    #! /usr/bin/env bash

    export TODAY=$(date "+%Y%m%d")

    # Check if op is logged in
    echo "Checking if op is logged in"
    op list users > /dev/null 2>&1
    # if not, log in or die trying
    if [ $? -ne 0 ]; then
    echo "Logging into op..."
    eval $(op signin)
    fi

    for i in $(ls *.jpeg); do
    echo "Converting $i..."
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - ${i%%.*}.pdf
    done

    # tar hcz *.pdf | gpg --batch --cipher-algo AES256 --symmetric --output "$TODAY"_scanned_mail.tar.gz.enc
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - $TODAY_${i%%.*}.pdf
    exec 3<<<"$(op item get encrypted_tar_password --format json | jq -r '.fields[] | select(.id=="password") | .value')"
    tar hcz ${i%%.*}.pdf | gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output $TODAY_${i%%.*}.pdf.tar.gz.enc
    done
  12. dwallraff renamed this gist Jul 22, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion convert_to_pdf.sh → convert_to_pdf
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,6 @@
    for i in $(ls *.jpeg); do
    echo "Converting $i..."
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - ${i%%.*}.pdf
    done
    done

    # tar hcz *.pdf | gpg --batch --cipher-algo AES256 --symmetric --output "$TODAY"_scanned_mail.tar.gz.enc
  13. dwallraff revised this gist Jul 22, 2022. 1 changed file with 2 additions and 7 deletions.
    9 changes: 2 additions & 7 deletions convert_to_pdf.sh
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,5 @@
    #! /usr/bin/env bash
    export TODAY=$(date "+%Y%m%d")

    cd ~/images || die
    for i in $(ls *.jpeg); do
    echo "Converting $i..."
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - "$TODAY"_${i%%.*}.pdf
    done

    tar hcz *.pdf | gpg --batch --cipher-algo AES256 --symmetric --output "$TODAY"_scanned_mail.tar.gz.enc
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - ${i%%.*}.pdf
    done
  14. dwallraff revised this gist Jul 20, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion convert_to_pdf.sh
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,6 @@ cd ~/images || die
    for i in $(ls *.jpeg); do
    echo "Converting $i..."
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - "$TODAY"_${i%%.*}.pdf
    done
    done

    tar hcz *.pdf | gpg --batch --cipher-algo AES256 --symmetric --output "$TODAY"_scanned_mail.tar.gz.enc
  15. dwallraff revised this gist Jul 20, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion convert_to_pdf.sh
    Original file line number Diff line number Diff line change
    @@ -4,5 +4,5 @@ export TODAY=$(date "+%Y%m%d")
    cd ~/images || die
    for i in $(ls *.jpeg); do
    echo "Converting $i..."
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - "$TODAY"_$i.pdf
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - "$TODAY"_${i%%.*}.pdf
    done
  16. dwallraff created this gist Jul 20, 2022.
    8 changes: 8 additions & 0 deletions convert_to_pdf.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    #! /usr/bin/env bash
    export TODAY=$(date "+%Y%m%d")

    cd ~/images || die
    for i in $(ls *.jpeg); do
    echo "Converting $i..."
    img2pdf $i | ocrmypdf -q --output-type pdfa --deskew --clean - "$TODAY"_$i.pdf
    done