Update docker/clam/docker-entrypoint.sh
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/cron/woodpecker Pipeline was successful Details

This commit is contained in:
colin 2024-10-31 16:05:29 -04:00
parent 176b436a5f
commit 865b5dac80
1 changed files with 31 additions and 15 deletions

View File

@ -4,28 +4,44 @@ MODE=${1:-"scan"}
temp_log_file="/tmp/clamav_scan_$(date +%Y%m%d_%H%M%S).log" temp_log_file="/tmp/clamav_scan_$(date +%Y%m%d_%H%M%S).log"
total_files_estimated=0
total_files_scanned=0
create_temp_log() { create_temp_log() {
local log_file="$1" local log_file="$1"
cat "$log_file" > "$temp_log_file" cat "$log_file" > "$temp_log_file"
} }
scan() { prepare_estimation() {
echo "Running ClamAV scan..." echo "Preparing file count estimation... (Note: This is an estimate and may include files across filesystems or symlinks if not all conditions are respected)"
local retry_count=0 local scan_dirs=$(find /scan -type d -print) # Lists all directories to scan
local max_retries=5
echo "Running scan in optimized mode to reduce resource usage." # Use parallel to count files across directories, matching clamscan criteria and ignoring symlinks
while ! clamscan -r --max-scansize=100M --max-filesize=50M --max-recursion=5 --log=/var/log/clamav/clamav.log /scan; do total_files_estimated=$(echo "$scan_dirs" | parallel -j $(nproc) \
retry_count=$((retry_count + 1)) "find {} -type f -not -type l -size -100M | wc -l" | \
if [ "$retry_count" -ge "$max_retries" ]; then awk '{s+=$1} END {print s}')
echo "Max retries reached. Sending failure report to GlitchTip..."
create_temp_log "/var/log/clamav/clamav.log" echo "Estimated total files to scan: $total_files_estimated"
go-glitch report --dsn "$GLITCHTIP_DSN" "$temp_log_file" || echo "Failed to report scan failure to GlitchTip" }
return
fi scan() {
echo "Scan failed. Retrying... ($retry_count/$max_retries)" prepare_estimation
sleep 5
echo "Running ClamAV scan on each subdirectory sequentially..."
local scan_dirs=$(find /scan -type d -print) # Lists all directories to scan
# Run clamscan on each subdirectory in sequence, ignoring symlinks
for dir in $scan_dirs; do
clamscan -r --max-scansize=100M --max-filesize=50M --max-recursion=0 --follow-dir-symlinks=no --cross-filesystems=no --log=/var/log/clamav/clamav_${dir##*/}.log "$dir"
scanned_files=$(grep -E "^/.*: (OK|FOUND)" /var/log/clamav/clamav_${dir##*/}.log | wc -l)
total_files_scanned=$((total_files_scanned + scanned_files))
remaining_files=$((total_files_estimated - total_files_scanned))
echo "Progress: $total_files_scanned files scanned, $remaining_files files remaining"
done done
# Combine logs
cat /var/log/clamav/clamav_*.log > /var/log/clamav/clamav.log
rm /var/log/clamav/clamav_*.log
} }
report() { report() {