From eb124bf96814561d74f5158dfbd12e4ba0c89b68 Mon Sep 17 00:00:00 2001 From: hyzen Date: Sat, 17 Jan 2026 01:44:06 +0530 Subject: [PATCH] Update: folder support --- encryptall.sh | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/encryptall.sh b/encryptall.sh index 3aaeb5c..8f4df6f 100755 --- a/encryptall.sh +++ b/encryptall.sh @@ -9,18 +9,49 @@ echo "" PASSFILE=$(mktemp) echo "$PASSWORD" > "$PASSFILE" -for file in *; do - if [ -f "$file" ] && [ "$file" != "Encrypted" ] && [ "$file" != "encryptall.sh" ] && [ "$file" != "encryptall" ]; then +for item in *; do + # Skip the Encrypted folder and the script itself + if [ "$item" = "Encrypted" ] || [ "$item" = "encryptall.sh" ] || [ "$item" = "encryptall" ]; then + continue + fi + + # For folders, archive first + if [ -d "$item" ]; then + archive_name="${item}.tar.xz" # Check if already encrypted previously - if [ -f "Encrypted/${file}.gpg" ]; then - echo "Skipping (already encrypted): $file" + if [ -f "Encrypted/${archive_name}.gpg" ]; then + echo "Skipping (already encrypted): $item/ (folder)" else - echo "Encrypting: $file" - gpg --batch --yes --passphrase-file "$PASSFILE" --symmetric --cipher-algo AES256 -o "Encrypted/${file}.gpg" "$file" + echo "Archiving folder: $item/" + tar -cJf "$archive_name" "$item" + if [ $? -eq 0 ]; then - echo "✓ Success: $file" + echo "Encrypting archive: $archive_name" + gpg --batch --yes --passphrase-file "$PASSFILE" --symmetric --cipher-algo AES256 -o "Encrypted/${archive_name}.gpg" "$archive_name" + + if [ $? -eq 0 ]; then + echo "✓ Success: $item/ (folder)" + # Remove the temporary archive file + rm -f "$archive_name" + else + echo "✗ Failed to encrypt: $archive_name" + fi else - echo "✗ Failed: $file" + echo "✗ Failed to archive: $item/" + fi + fi + # For files + elif [ -f "$item" ]; then + # Check if already encrypted previously + if [ -f "Encrypted/${item}.gpg" ]; then + echo "Skipping (already encrypted): $item" + else + echo "Encrypting: $item" + gpg --batch --yes --passphrase-file "$PASSFILE" --symmetric --cipher-algo AES256 -o "Encrypted/${item}.gpg" "$item" + if [ $? -eq 0 ]; then + echo "✓ Success: $item" + else + echo "✗ Failed: $item" fi fi fi