#!/bin/bash
LOG_PATH="$1"
QUARANTINE_SQLDB_NAME=".quarantine"
QUARANTINE_DB_PATHS="`ls /volume*/${QUARANTINE_SQLDB_NAME}` /var/quarantine/${QUARANTINE_SQLDB_NAME}"
# copy temporarily files if exist, like .report-journal
REPORT_DB_NAME=".report"
REPORT_DB_PATH="`ls /volume*/@AntiVirus*/${REPORT_DB_NAME}`"

if [ "${LOG_PATH}" != "" ]; then
	mkdir -p ${LOG_PATH}
	for db_file in ${QUARANTINE_DB_PATHS};
	do
		volname="`dirname ${db_file} | cut -d'/' -f2`"
		debug_dat_qlist_path="${LOG_PATH}/${volname}_quarantine_list.txt"

		sqlite3 ${db_file} "select * from quarantine" >> ${debug_dat_qlist_path}
		ret=$?
		if [ ${ret} -ne 0 ]; then
			echo "cmd [sqlite3 ${db_file} \"select * from quarantine\"] returned error ${ret}" >> ${debug_dat_qlist_path}
		fi
	done

        for db_file in ${REPORT_DB_PATH};
        do
                cplog="${LOG_PATH}/get_report_error.txt"
                errmsg=`cp ${db_file} ${LOG_PATH} 2>&1`
                ret=$?
                if [ ${ret} -ne 0 ]; then
                        echo "failed to copy ${db_file}: ${errmsg}" >> ${cplog}
                fi
        done
else
	echo "bad parameter"
fi

exit 0
