#!/usr/bin/sh

echo "Karspersky commandline scanner by blackPanther Project..."

if [ "$1" = "-h" ];then

echo "
###################################################################################################
##    Karspersky Vírus Scanner 
###################################################################################################

-h                      show help
-d <folder_path>        path to quarantine and reports folder
-accepteula             accept EULA, Privacy Policy and KSN Statement
-trace                  enable trace collection
-tracelevel <level>     set the level of traces:
                             ERR - only error messages
                             WRN - warnings and errors
                             INF - information, warnings and errors
                             DBG - all messages
-processlevel <level>        set the level of danger of object which will be neutralized:
                                0 - skip objects with high, medium and low danger level
                                1 - neutralize objects with high danger level
                                2 - neutralize objects with high and medium danger level
                                3 - neutralize objects with high, medium and low danger level
-dontencrypt            disable encryption of trace files/reports/dump files
-details                enable detailed reports
-proxyconfig <config_file_path>    path to file with proxy config
-silent                 run scan without GUI
-adinsilent             run active disinfection in silent mode
-allvolumes             add all volumes to scan
-custom <folder_path>   path to custom folder for scan
-customlist <file_path> path to file with custom folders for scan
-exclude <folder_path>  exclude path from custom scan
-excludelist <file_path>   path to file with excludes for custom scan
-customonly             run scan of custom folders only
###################################################################################################
"

fi

PASSED=$1

#echo "Scanned dir: $PASSED"
#exit

#-custom %f -customonly

if [ ! -n "$PASSED" ];then
    PASSED=$PWD

elif [ "$1" == "/-" ];then
#echo /tmp/kvrt_list >/tmp/kvrt_list
exit 0

fi

if [[ -d $PASSED ]]; then
    echo "- The $PASSED is a directory"
    echo "Karspersky Folder Scan..."
    kvrt -details -accepteula -silent -custom $PASSED
elif [[ -f $PASSED ]]; then
    echo "- The $PASSED is a file"
    echo "Karspersky Fule Scan..."
    kvrt -details -accepteula -silent -custom $PASSED -customonly
else
    echo "$PASSED is not valid"
    exit 1
fi

exit

if [ -n "$1" ];then
echo "Karspersky Folder Scan..."
kvrt -details -accepteula -silent -custom $1

else

echo "Karspersky Other Scan..."
sleep 3
if [ "$1" == "/-" ];then
#echo /tmp/kvrt_list >/tmp/kvrt_list
exit 0
else
echo /tmp/kvrt_list >/tmp/kvrt_list
#echo "$(readlink -f $1)" >/tmp/kvrt_list
fi

kvrt -details -accepteula -silent -customlist /tmp/kvrt_list
#rm -f /tmp/kvrt_list
#else

#echo "$*" >/tmp/kvrt_list
echo /tmp/kvrt_list >/tmp/kvrt_list
logger -t kvrtscan "F:$(cat /tmp/kvrt_list)"
exit 0
fi
