Created
May 4, 2020 15:30
-
-
Save theonelucas/5d5775123386b2846d950d0b670d0b1e to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Configurations | |
PASSPHRASE='' | |
LOG_FILE='./log' | |
# Helper functions | |
start_message() | |
{ | |
echo -n $(date +'%Y-%m-%d %H:%M:%S: ') "${1}... " | |
} | |
end_message() | |
{ | |
echo 'Finished' | |
} | |
# Exit if not root | |
if [[ `id -u` != 0 ]]; then | |
echo 'Error: You should run this script as super user' | |
exit | |
fi | |
# Exit if no backup file was passed | |
[ -z "$1" ] && echo 'No file supplied!' && exit 1 | |
fullname=$1 # Full file name | |
filename=`basename $1` # Extracts file name from path | |
filename="${filename%.*}" # Remove file extension from file name | |
# Decrypt the file | |
start_message "Decrypting '${filename}'" | |
echo $PASSPHRASE | gpg --batch --passphrase-fd 0 --output "./${filename}.tar.gz" --decrypt ${fullname} &>> "$LOG_FILE" | |
end_message | |
# Extract decrypted file | |
start_message 'Extracting decrypted file' | |
[ -d "./${filename}" ] || mkdir "./${filename}" # Create extraction target directory | |
tar -xzf "./${filename}.tar.gz" -C "./${filename}" &>> "$LOG_FILE" # Extract decrypted file | |
end_message | |
# Delete compressed file | |
#rm "./${filename}.tar.gz" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment