Files
q-tools/files/gpg-decrypt
2024-11-26 20:09:34 +02:00

32 lines
553 B
Bash
Executable File

#!/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