Update docker/clam/docker-entrypoint.sh
This commit is contained in:
parent
176b436a5f
commit
865b5dac80
|
@ -4,28 +4,44 @@ MODE=${1:-"scan"}
|
|||
|
||||
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() {
|
||||
local log_file="$1"
|
||||
cat "$log_file" > "$temp_log_file"
|
||||
}
|
||||
|
||||
scan() {
|
||||
echo "Running ClamAV scan..."
|
||||
local retry_count=0
|
||||
local max_retries=5
|
||||
prepare_estimation() {
|
||||
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 scan_dirs=$(find /scan -type d -print) # Lists all directories to scan
|
||||
|
||||
echo "Running scan in optimized mode to reduce resource usage."
|
||||
while ! clamscan -r --max-scansize=100M --max-filesize=50M --max-recursion=5 --log=/var/log/clamav/clamav.log /scan; do
|
||||
retry_count=$((retry_count + 1))
|
||||
if [ "$retry_count" -ge "$max_retries" ]; then
|
||||
echo "Max retries reached. Sending failure report to GlitchTip..."
|
||||
create_temp_log "/var/log/clamav/clamav.log"
|
||||
go-glitch report --dsn "$GLITCHTIP_DSN" "$temp_log_file" || echo "Failed to report scan failure to GlitchTip"
|
||||
return
|
||||
fi
|
||||
echo "Scan failed. Retrying... ($retry_count/$max_retries)"
|
||||
sleep 5
|
||||
# Use parallel to count files across directories, matching clamscan criteria and ignoring symlinks
|
||||
total_files_estimated=$(echo "$scan_dirs" | parallel -j $(nproc) \
|
||||
"find {} -type f -not -type l -size -100M | wc -l" | \
|
||||
awk '{s+=$1} END {print s}')
|
||||
|
||||
echo "Estimated total files to scan: $total_files_estimated"
|
||||
}
|
||||
|
||||
scan() {
|
||||
prepare_estimation
|
||||
|
||||
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
|
||||
|
||||
# Combine logs
|
||||
cat /var/log/clamav/clamav_*.log > /var/log/clamav/clamav.log
|
||||
rm /var/log/clamav/clamav_*.log
|
||||
}
|
||||
|
||||
report() {
|
||||
|
|
Loading…
Reference in New Issue