encrypt-dir (520B)
1 #!/usr/bin/env bash 2 if ! command -v gpg &>/dev/null; then 3 echo "gpg not installed." >&2 4 exit 1 5 fi 6 7 export GPG_TTY=$(tty) 8 9 if [ -f "$1" ]; then 10 elif [ -d "$1" ]; then 11 else 12 echo "File doesn't exist or not supported." 13 fi 14 if [ ! -z "$2" ]; then 15 mkdir -p "$2" 16 (cd "${1%/*}" && tar cz "${1##*/}") | gpg -c --cipher-algo aes256 -o "${2%/}"/"${1##*/}.tgz.gpg" 17 echo "Encrypted $1 into $2" 18 else 19 (cd "${1%/*}" && tar cz "${1##*/}") | gpg -c --cipher-algo aes256 -o "${1##*/}.tgz.gpg" 20 echo "Encrypted $1 into ." 21 fi