tinydns/update_ipv4_adress_space.sh
2017-02-21 02:35:57 +01:00

60 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
update_url="http://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.txt"
base_dnscache_dir=/opt/dnscache
dnscache_ip_dir=${base_dnscache_dir}/root/ip
if [ ! -d $base_dnscache_dir -o ! -d $dnscache_ip_dir ]; then
echo
echo "[ ERROR ]: Installtion directory for dnscache not found"
echo " exiting now.."
echo
exit 1
fi
tmp_file="/tmp/ipv4_addresss_space.$$.lst"
wget $update_url -O $tmp_file > /dev/null 2>&1
if [ $? -gt 0 ];then
echo
echo "[ ERROR ]: cannot fetch $update_url "
echo " exiting now.."
echo
rm -f $tmp_file
exit 2
fi
adress_spaces=`grep -e " \(ALLOCATED\)$\|\(LEGACY\)$" $tmp_file | awk '{print$1}' | cut -d "/" -f 1 | sed -e's/^0*\(.*\)$/\1/'`
if [ -z "$adress_spaces" ] ; then
echo
echo "[ ERROR ]: No adress space data found $update_url "
echo " exiting now.."
echo
rm -f $tmp_file
exit 3
fi
## - delete old entries..
## -
rm -rf $dnscache_ip_dir/*
cd $dnscache_ip_dir
for i in $adress_spaces; do
touch ${i}
done
## - send the servive a HUP signal
## -
svc -h $base_dnscache_dir
rm -f $tmp_file
exit 0