Created
May 4, 2020 15:29
-
-
Save theonelucas/aeb8c97d3f89f4f287482dad9fe415f6 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 directory was passed | |
[ -z "$1" ] && echo 'No directory supplied!' && exit 1 | |
fullname=$1 # Directory name | |
basename=`basename ${fullname}` | |
# Compress | |
start_message 'Compressing directory' | |
tar -czf "./${basename}.tar.gz" -C "${fullname}" . | |
end_message | |
# Encrypt | |
start_message 'Encrypting compressed file' | |
gpg -c --batch --passphrase "$PASSPHRASE" -o "${basename}.gpg" "${basename}.tar.gz" | |
end_message | |
# Delete compressed file | |
rm "./${basename}.tar.gz" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment