File 80-check-malware-scan-clamav of Package post-build-checks-malwarescan

#!/bin/bash

TARGET=/usr/src/packages
SCANSCRIPT=/var/lib/clamav/.script
export TARGET
export BUILD_ROOT
export SCANSCRIPT

echo '
#!/bin/bash

mkdir /usr/src/packages/BUILD/scan

for r in $( find -L /.build.packages /usr/src/packages -xdev -type f -name "*.rpm" ); do
  F=$(file --brief "$r")
  case $F in
	RPM\ *) ;;
	*) echo "skipping non RPM file $r: $F" ; continue ;;
  esac
  f=${r##*/}
  case "$f" in
	kiwi-test-dummy*) echo "skipping known broken rpm $f" ; continue ;;
  esac
  mkdir -p /usr/src/packages/BUILD/scan/"$f.d"
  pushd . > /dev/null 
  cd /usr/src/packages/BUILD/scan/"$f.d"
  echo "unpacking $r"
  rpm2cpio "$r" | cpio --quiet --extract --unconditional --preserve-modification-time --make-directories > /dev/null
  if [ "$?" -gt 0 ]; then
	echo "unpacking RPM packages does not work on this host.
Is the filesystem is full?

Please have a look.
"
  exit 42
  fi
  popd > /dev/null
done

echo "clamscan -ir /usr/src/packages/BUILD/scan:"
/usr/bin/clamscan -ir /usr/src/packages/BUILD/scan
ret=$?
rm -rf /usr/src/packages/BUILD/scan 
exit $ret
' > $BUILD_ROOT/$SCANSCRIPT


OUT=$( cd $BUILD_ROOT ; chroot . bash $SCANSCRIPT 2>&1 )
ret=$?
rm -f $BUILD_ROOT/$SCANSCRIPT


if [ "$ret" != 0 ]; then
  echo "clamav: positive result about one or more files in the system.
return value: $ret

The output of /usr/bin/clamscan -ir $TARGET was:"
  echo "$OUT"
  echo "

The test has failed. Please check the files mentioned above!

"
  exit 1
else
  echo "clamav: negative malware scan result."
  echo "$OUT"
  echo test passed.
fi
exit 0
openSUSE Build Service is sponsored by