#!/bin/bash

ips()
{
	if [ -x /sbin/ipset ]; then
		IPSCMD=/sbin/ipset
	elif [ -x /usr/sbin/ipset ]; then
		IPSCMD=/usr/sbin/ipset
	fi

	if ! (${IPSCMD} $@);then
		echo "CMD: ipset $@"
	fi
}

DROPDIR=/var/lib/droplist

[ -d $DROPDIR ] || mkdir $DROPDIR

DROPLIST=$DROPDIR/3gdrop.txt
[ -f $DROPLIST ] && rm $DROPLIST
wget "https://pub.3gteam.hu/droplist/drop.txt" -q -O $DROPLIST

[ -f $DROPLIST ] || exit 124

ips flush dropset4-local

cat "$DROPLIST" \
 | sed -e 's/;.*//' \
 | grep -v '^ *$' \
 | sort \
 | uniq \
 | while read NB ; do
	ips add dropset4-local "$NB"
done

DROPLIST6=$DROPDIR/3gdrop6.txt
[ -f $DROPLIST6 ] && rm $DROPLIST6
wget "https://pub.3gteam.hu/droplist/drop6.txt" -q -O $DROPLIST6

[ -f $DROPLIST6 ] || exit 126

ips flush dropset6-local

cat "$DROPLIST6" \
 | sed -e 's/;.*//' \
 | grep -v '^ *$' \
 | sort \
 | uniq \
 | while read NB ; do
	ips add dropset6-local "$NB"
done
