# -*- mode: sh; -*- # # $HeadURL: https://tstotts.net/pubvc/bash-snippets/gpg.sh $ # $Id: gpg.sh 624 2007-07-07 02:08:52Z tas $ # # Dependencies: # sys-apps/coreutils # app-arch/tar # app-crypt/gnupg # app-arch/par2cmdline # Fix issues with gpg using agent in GNU Screen # and other terminal emulators that confuse the # the TTY device. export GPG_TTY=`tty` # Signal all `gpg-agent' processes to discard their passphrase cache. t_gpg_flush() { kill -1 `pgrep gpg-agent` } # create an encrypted tar archive (with datestamp in file name) # and generate MD5 checksum and PAR-2 integrity codecs t_gpg_bkup() { prefix="$1" shift; if [[ -z "$prefix" && -z "$1" ]]; then echo "${FUNCNAME[0]} DIR [...]"; return 1; fi DATESTAMP=`date +%Y_%m_%d_%H%M%S` o="${prefix}.`hostname -s`.${DATESTAMP}.tar.gpg" ( tar -cO "$@" | \ gpg --quiet \ --compress-algo bzip2 \ --bzip2-compress-level 6 \ --cipher-algo AES256 \ --symmetric \ > "${o}" \ || return $?; ) ( b=`basename ${o}` d=`dirname ${o}` cd ${d} md5sum ${b} > ${b}.md5 || return $?; par2 create -q -q ${b} || return $?; ) } # encrypt a file and generate MD5 checksum and PAR-2 integrity codecs t_gpg_file() { if [[ -z "$1" ]]; then echo "${FUNCNAME[0]}: FILE [...]"; return 1; fi for i in "$@"; do o="${i}.gpg" cat "${i}" | \ gpg --quiet \ --compress-algo bzip2 \ --bzip2-compress-level 6 \ --cipher-algo AES256 \ --symmetric \ > "${o}" \ || return $?; ( b=`basename ${o}` d=`dirname ${o}` cd ${d} md5sum ${b} > ${b}.md5 || return $?; par2 create -q -q ${b} || return $?; ) done return 0 } t_bkup_mail() { cd $HOME && \ t_gpg_bkup backups/mail/`id -u -n`_mail Mail/ } alias shred='shred -u'