fixed bugs in shrink_nsrl
This commit is contained in:
@@ -1,15 +1,24 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
#set -x
|
||||||
|
|
||||||
rds_url=$(cat /nsrl/nsrl.conf | grep -Pio '(?<=rds_url = )\S+')
|
#read information from config
|
||||||
version_url=$(cat /nsrl/nsrl.conf | grep -Pio '(?<=version_url = )\S+')
|
rds_url=$(cat /nsrl/nsrl.conf | grep 'rds_url' | cut -f2- -d= | grep -o -E '\S+.*')
|
||||||
ERROR_RATE=$(cat /nsrl/nsrl.conf | grep -Pio '(?<=error_rate = )\S+')
|
echo "rds_url=${rds_url}"
|
||||||
rds_name=$(cat /nsrl/nsrl.conf | grep -Pio '(?<=rds_name = ).+')
|
version_url=$(cat /nsrl/nsrl.conf | grep 'version_url' | cut -f2- -d= | grep -o -E '\S+.*')
|
||||||
hashfile_name=$(cat /nsrl/nsrl.conf | grep -Pio '(?<=hashfile_name = ).+')
|
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)
|
build_date=$(date +%Y%M%d_%H%M)
|
||||||
|
echo "build_date=${build_date}"
|
||||||
|
|
||||||
|
#check if a zipfile was provided
|
||||||
if [ -f /nsrl/*.zip ]; then
|
if [ -f /nsrl/*.zip ]; then
|
||||||
zip_filename=$(ls /nsrl/*.zip | head -n1)
|
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" ")
|
zip_md5=$(md5sum "${zip_filename}" | cut -f1 -d" ")
|
||||||
rds_version=$(stat -c %y "${zip_filename}" )
|
rds_version=$(stat -c %y "${zip_filename}" )
|
||||||
else
|
else
|
||||||
@@ -18,33 +27,32 @@ else
|
|||||||
echo "[INFO] URL: ${rds_url}"
|
echo "[INFO] URL: ${rds_url}"
|
||||||
#Downloading and Hashing at the same time
|
#Downloading and Hashing at the same time
|
||||||
zip_md5=$(wget -O - "${rds_url}" 2>/dev/null | tee "/nsrl/${zip_filename}" | md5sum | cut -f1 -d" ")
|
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=$(wget -O - "${version_url}" 2>/dev/null | tee "/nsrl/.version" | head -n1 )
|
||||||
rds_version=$(grep -F "${zip_md5}" /nsrl/.version | cut -f2 -d, | tr -d '"' )
|
|
||||||
fi
|
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/ ..."
|
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} ..."
|
echo "[INFO] Counting Hashes in /nsrl/${hashfile_name} ..."
|
||||||
hash_count=$(wc -l "/nsrl/${hashfile_name}")
|
#counting lines in hashfile without headline
|
||||||
#remove headline from count
|
let hash_count=$(cat "/nsrl/${hashfile_name}"|wc -l )-1
|
||||||
(( hash_count=hash_count - 1 ))
|
|
||||||
echo "[INFO] /nsrl/${hashfile_name} contains ${hash_count} Hashes"
|
echo "[INFO] /nsrl/${hashfile_name} contains ${hash_count} Hashes"
|
||||||
echo "hash_count = ${hash_count}" >> /nsrl/nsrl.conf
|
|
||||||
|
|
||||||
|
|
||||||
echo "[INFO] Build bloomfilter from NSRL Database ..."
|
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 ..."
|
echo "[INFO] Listing created files ..."
|
||||||
ls -lah /nsrl
|
ls -lah /nsrl
|
||||||
|
|
||||||
echo "[INFO] Deleting all unused files ..."
|
echo "[INFO] Deleting all unused files ..."
|
||||||
rm -f /nsrl/*.zip /nsrl/*.txt
|
rm -f /nsrl/*.zip /nsrl/*.txt
|
||||||
ls -lah /nsrl
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user