Update: folder support

This commit is contained in:
hyzen
2026-01-17 01:44:06 +05:30
parent 7963b74d0c
commit eb124bf968

View File

@@ -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