cryptdir.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. # Use zip to encrypt all single files CRYPTDIR with PASSWORD
  3. # this is bash; be safe
  4. set -e
  5. set -u
  6. # Set up logging functions (die, warn, info ...)
  7. source $HOME/lib/bash/bashutils.sh
  8. # Get the encryption password from the CRYPTDIR_PASS environment variable
  9. password=${CRYPTDIR_PASS:-"NONE"}
  10. # Check if password is defined
  11. if [ $password == "NONE" ]; then
  12. die "ERROR: CRYPTDIR_PASS environment variable not defined"
  13. fi
  14. cryptdir=${CRYPTDIR:-"NONE"}
  15. # Check if password is defined
  16. if [ $cryptdir == "NONE" ]; then
  17. die "ERROR: CRYPTDIR environment variable not defined"
  18. fi
  19. cd $cryptdir || die "Can't cd to $cryptdir"
  20. info "encrypting files in $cryptdir"
  21. # Loop through all files in the current directory
  22. for file in *; do
  23. # Check if the file is not a directory and is not already a zip file
  24. if [ ! -d "$file" ] && [[ "$file" != *.zip ]]; then
  25. # Create a zip file with the same name as the original file with .zip extension
  26. info "Encrypting $file ..."
  27. zip --encrypt --password "$password" "$file.zip" "$file"
  28. fi
  29. done
  30. info done