#!/bin/sh
#

EXT=xt_geoip_LE_IPv4
TCZ=/tmp/$EXT/TCZ

sudo rm -rf /tmp/$EXT

DEPS="xtables-addons-KERNEL tcl8.6"

NOTFOUND=""
for a in compiletc bash file squashfs-tools $DEPS
         do tce-load -i $a || tce-load -iwl $a || NOTFOUND=x
done
test -z "$NOTFOUND" || exit

mkdir -p $TCZ/usr/local/share/xt_geoip
mkdir LE

# IPv4
rm -f GeoIPCountryCSV.zip GeoIPCountryWhois.csv
wget http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
unzip GeoIPCountryCSV.zip

#tclsh /usr/local/libexec/xtables-addons/xt_geoip_build.tcl
tclsh /mnt/sda1/lamp/contrib/xt_geoip_build.tcl

cp -r LE $TCZ/usr/local/share/xt_geoip

sudo chown -R root.root $TCZ

mksquashfs $TCZ /tmp/$EXT/$EXT.tcz -noappend

