From fa146c51a79128b9d4f32a08792be1cb28657efb Mon Sep 17 00:00:00 2001 From: TKE Date: Wed, 15 Apr 2020 20:04:05 +0200 Subject: [PATCH] fixed bugs in shrink_nsrl --- nsrl/shrink_nsrl.sh | 50 ++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/nsrl/shrink_nsrl.sh b/nsrl/shrink_nsrl.sh index a084f17..3bfb9c1 100755 --- a/nsrl/shrink_nsrl.sh +++ b/nsrl/shrink_nsrl.sh @@ -1,15 +1,24 @@ #!/bin/sh +#set -x -rds_url=$(cat /nsrl/nsrl.conf | grep -Pio '(?<=rds_url = )\S+') -version_url=$(cat /nsrl/nsrl.conf | grep -Pio '(?<=version_url = )\S+') -ERROR_RATE=$(cat /nsrl/nsrl.conf | grep -Pio '(?<=error_rate = )\S+') -rds_name=$(cat /nsrl/nsrl.conf | grep -Pio '(?<=rds_name = ).+') -hashfile_name=$(cat /nsrl/nsrl.conf | grep -Pio '(?<=hashfile_name = ).+') +#read information from config +rds_url=$(cat /nsrl/nsrl.conf | grep 'rds_url' | cut -f2- -d= | grep -o -E '\S+.*') +echo "rds_url=${rds_url}" +version_url=$(cat /nsrl/nsrl.conf | grep 'version_url' | cut -f2- -d= | grep -o -E '\S+.*') +echo "version_url=${version_url}" +error_rate=$(cat /nsrl/nsrl.conf | grep 'error_rate' | cut -f2- -d=| grep -o -E '\S+.*' ) +echo "error_rate=${error_rate}" +rds_name=$(cat /nsrl/nsrl.conf | grep 'rds_name' | cut -f2- -d= | grep -o -E '\S+.*') +echo "rds_name=${rds_name}" +hashfile_name=$(cat /nsrl/nsrl.conf | grep 'hashfile_name' | cut -f2- -d= | grep -o -E '\S+.*') +echo "hashfile_name=${hashfile_name}" build_date=$(date +%Y%M%d_%H%M) +echo "build_date=${build_date}" +#check if a zipfile was provided if [ -f /nsrl/*.zip ]; then zip_filename=$(ls /nsrl/*.zip | head -n1) - echo "[INFO] ZIP-File Exists > ${zip_filename}" + echo "[INFO] ZIP-File Exists : ${zip_filename}" zip_md5=$(md5sum "${zip_filename}" | cut -f1 -d" ") rds_version=$(stat -c %y "${zip_filename}" ) else @@ -18,33 +27,32 @@ else echo "[INFO] URL: ${rds_url}" #Downloading and Hashing at the same time zip_md5=$(wget -O - "${rds_url}" 2>/dev/null | tee "/nsrl/${zip_filename}" | md5sum | cut -f1 -d" ") - wget -O /nsrl/.version "${version_url}" 2>/dev/null - rds_version=$(grep -F "${zip_md5}" /nsrl/.version | cut -f2 -d, | tr -d '"' ) + rds_version=$(wget -O - "${version_url}" 2>/dev/null | tee "/nsrl/.version" | head -n1 ) fi -#update config -echo "build_date = ${build_date}" >> /nsrl/nsrl.conf -echo "zip_filename = ${zip_filename}" >> /nsrl/nsrl.conf -echo "zip_md5 = ${zip_md5}" >> /nsrl/nsrl.conf -echo "rds_version = ${rds_version}" >> /nsrl/nsrl.conf - echo "[INFO] Unzip NSRL Database zip to /nsrl/ ..." -7za x -o/nsrl/ "${zip_filename}" +7z x -o/nsrl/ "/nsrl/${zip_filename}" echo "[INFO] Counting Hashes in /nsrl/${hashfile_name} ..." -hash_count=$(wc -l "/nsrl/${hashfile_name}") -#remove headline from count -(( hash_count=hash_count - 1 )) +#counting lines in hashfile without headline +let hash_count=$(cat "/nsrl/${hashfile_name}"|wc -l )-1 echo "[INFO] /nsrl/${hashfile_name} contains ${hash_count} Hashes" -echo "hash_count = ${hash_count}" >> /nsrl/nsrl.conf - echo "[INFO] Build bloomfilter from NSRL Database ..." -cd /nsrl && python /nsrl/build.py $ERROR_RATE +cd /nsrl && python /nsrl/build.py $error_rate echo "[INFO] Listing created files ..." ls -lah /nsrl echo "[INFO] Deleting all unused files ..." rm -f /nsrl/*.zip /nsrl/*.txt ls -lah /nsrl + +#update config +echo "[INFO] Update Config ..." +echo "build_date = ${build_date}" >> /nsrl/nsrl.conf +echo "zip_filename = ${zip_filename}" >> /nsrl/nsrl.conf +echo "zip_md5 = ${zip_md5}" >> /nsrl/nsrl.conf +echo "rds_version = ${rds_version}" >> /nsrl/nsrl.conf +echo "hash_count = ${hash_count}" >> /nsrl/nsrl.conf +cat /nsrl/nsrl.conf