Last active
January 8, 2017 17:18
-
-
Save pachanka/3ad3b93393eeb01f5f5e to your computer and use it in GitHub Desktop.
A gpg wrapper to decrypt files.
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
#!/bin/bash | |
# | |
# decrypt-with-gpg | |
# | |
usage="$0 path/to/encripted/file.txt" | |
if [ ! $# -eq 0 ] ; then | |
param=$1 | |
error=1 | |
if [ ! -f "$param" ] ; then | |
# No such file | |
error=0 | |
echo "Error: File \"$param\" does not exist" | |
exit 1 | |
fi | |
if ! type gpg > /dev/null ; then | |
# gpg is not present in PATH | |
error=0 | |
echo "Error: gpg is not installed. Please install gpg first." | |
exit 1 | |
fi | |
if [ $error -eq 1 ] ; then | |
# Decrypt | |
TMPFILE="/tmp/${0##*/}-$$" | |
echo "$TMPFILE" | |
gpg --decrypt "$param" > "$TMPFILE" | |
cat "$TMPFILE" | |
if ! type shred > /dev/null ; then | |
rm "$TMPFILE" | |
else | |
# shred is present in PATH | |
shred "$TMPFILE" | |
fi | |
# Prompt for clear terminal | |
echo | |
echo | |
echo "=== End ===" | |
echo | |
read -r -p "Clear terminal? (y/n) : " choice | |
case "$choice" in | |
y|Y ) clear;; | |
* ) exit 1;; | |
esac | |
else | |
echo "Error: There was an unknown error." | |
exit 1 | |
fi | |
else | |
echo "Usage:" | |
echo "$usage" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment