#!/bin/bash # # junkview-update-database 2006-04-02, last edit 2008-08-17 # # script to update junkview database files # # Copyright (C) 2006 Grant Coady GPLv2 # # home site: ME="junkview-update-database" CONF="/etc/junkview.conf" printf "\n$ME:\n\n" # check we have a .conf file [ ! -r $CONF ] && echo "fatal: cannot read $CONF" && exit 1 # read data location from /etc/junkview.conf data_dir=$(awk '/^datapath/ {print $2}' $CONF) printf "\tusing data directory: $data_dir\n\n" # read data source filenames and urls ip2c_url=$(awk '/^ip2c_url/ {print $2}' $CONF) ip2c_src=$(awk '/^ip2c_src/ {print $2}' $CONF) ip2cfile=$(awk '/^ip2cfile/ {print $2}' $CONF) response="" check_yes_no() # prompt { printf "$1 " read response } # check we have data directory if [ ! -d $data_dir ] then check_yes_no "$data_dir does not exist, create it?" case $response in y|Y) mkdir --parents --verbose $data_dir ;; *) echo "exit at user request" exit ;; esac fi # report if we have database file cd $data_dir printf "database file is " if [ -r "$ip2cfile" ] then echo "present:" ls -lh $ip2cfile else echo "missing!" fi check_yes_no "\ndownload fresh data source file now?" case $response in y|Y) rm -f $ip2c_src wget -O $ip2c_src.gz $ip2c_url gunzip $ip2c_src.gz # check we got data file to play with if [ ! -r $ip2c_src ] then echo "$ME: fatal, missing data source file: $ip2c_src" exit 1 fi # extract database from source file printf "extracting database... " printf "junkview\tip2c-data\t1.00\t$ip2c_src" > $ip2cfile awk -F: '/^#/{next};{gsub(/","/,":");gsub(/"/,"");$1=$1;print $1,$2,$5}' \ $ip2c_src >> $ip2cfile echo "Done!" ;; esac prompt="start"; cmd="start" [ -r /var/run/ip2cn-server.pid ] && prompt="signal reload to" && cmd="reload" check_yes_no "\n$prompt the ip2cn-server?" case $response in y|Y) [ $(id -u) -ne 0 ] && echo -n "requires Superuser " su -c "/etc/rc.d/rc.junkview $cmd" || exit 1 echo -e "\ntesting: 'ccfind 123.2.0.0', please wait..." ccfind 123.2.0.0 ;; esac #end