93b2e4d264
The previous grep matched lowercase 'loaded' which never appears, so the ready banner always reported '0 databases loaded' even when clamd had 3.8M sigs in memory. Parse the actual 'Loaded N signatures' line. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
47 lines
1.2 KiB
Bash
47 lines
1.2 KiB
Bash
#!/bin/sh
|
|
|
|
start_clamd() {
|
|
clamd --config-file=/etc/clamav/clamd.conf
|
|
echo "Waiting for clamd..."
|
|
attempts=0
|
|
while [ ! -S /tmp/clamd.sock ] && [ "$attempts" -lt 120 ]; do
|
|
sleep 0.5
|
|
attempts=$((attempts + 1))
|
|
done
|
|
if [ ! -S /tmp/clamd.sock ]; then
|
|
echo "ERROR: clamd failed to start"
|
|
cat /tmp/clamd.log 2>/dev/null
|
|
exit 2
|
|
fi
|
|
sigs=$(grep -oE 'Loaded [0-9]+ signatures' /tmp/clamd.log 2>/dev/null | grep -oE '[0-9]+' | tail -1)
|
|
echo "clamd ready (${sigs:-0} signatures loaded)"
|
|
}
|
|
|
|
case "${1}" in
|
|
version )
|
|
echo "stage: ${1}"
|
|
clamscan --version
|
|
clamconf | sed -ne '/Database information/,/^$/p'
|
|
for file in /var/lib/clamav/* ;
|
|
do
|
|
(clamscan -d $file /proc/cmdline > /dev/null 2>&1) && echo "+ ${file}" || echo "Bad Signaturefile ${file}"
|
|
done
|
|
echo "$(sigtool --list-sigs | wc -l) Signatures loaded"
|
|
;;
|
|
scan )
|
|
echo "stage: ${1}"
|
|
start_clamd
|
|
echo "Starting multiscan of /data:"
|
|
clamdscan --multiscan /data
|
|
rc=$?
|
|
exit $rc
|
|
;;
|
|
* )
|
|
echo "stage: ${1}"
|
|
echo "Usage: scan | version | shell"
|
|
echo " scan - multithreaded scan of /data via clamd"
|
|
echo " version - show engine + signature info"
|
|
/bin/sh
|
|
;;
|
|
esac
|