scripts

Scripts
git clone git://git.wimdupont.com/scripts.git
Log | Files | Refs | LICENSE

encr (871B)


      1 #!/bin/bash
      2 
      3 #Encrypted file with default symmetric password
      4 readonly SYM_PWD=$HOME/.sym-pwd.gpg
      5 
      6 disable_default_pwd=0
      7 asymmetric=0
      8 
      9 while getopts "da" arg; do
     10   case $arg in
     11     d) disable_default_pwd=1;;
     12     a) asymmetric=1;;
     13   esac
     14 done
     15 
     16 shift $((OPTIND-1))
     17 
     18 file=$1
     19 
     20 #Removes last occurence of "/", gets added when using tab autocomplete
     21 if [[ "$file" == */ ]]; then
     22 	file=$(echo "$file" | sed 's/\(.*\)\/.*/\1/')
     23 fi
     24 
     25 tar -cf "$file".tar "$file"
     26 
     27 #Ensures deletion of unencrypted tar file on exit
     28 trap 'shred -u "$file".tar' EXIT
     29 
     30 if [ $asymmetric -eq 0 ]; then
     31 	if [ $disable_default_pwd -eq 0 ] && [ -f "$SYM_PWD" ]; then
     32 		pwd=$(gpg --decrypt "${SYM_PWD}" 2>/dev/null)
     33 		gpg --passphrase "${pwd}" --batch --yes -c --no-symkey-cache --cipher-algo AES256 "$file".tar
     34 	else
     35 		gpg -c --no-symkey-cache --cipher-algo AES256 "$file".tar
     36 	fi
     37 else
     38 	gpg -e "$file".tar
     39 fi