#!/bin/bash if [[ -z "$1" ]]; then echo "File missing or use -" exit 1 fi if [[ "$1" = "-" ]]; then pv "$1" | gpg -d exit $? fi if [[ -e "${1%.gpg}" ]]; then echo "Target already exists" exit 1 fi echo Creating "${1%.gpg}" if [[ -z "$GPGPASS" ]]; then pv "$1" | gpg -d -o "${1%.gpg}" || { echo "" echo "If agent doesnt work, then:" echo "Give password with env GPGPASS ( GPGPASS=secret gpg-decrypt $1 )" } else { echo "$GPGPASS"; pv "$1"; } | \ gpg -o "${1%.gpg}" -d --passphrase-fd 0 --batch --yes fi