#!/bin/sh
if [ "$1" = v6 ];then
	ipset -N china_v6 hash:net family inet6 2>/dev/null
	awk '!/^$/&&!/^#/{printf("add china_v6 %s'" "'\n",$0)}' /etc/bypass/china_v6.txt > /tmp/china_v6.ipset
	ipset -F china_v6 2>/dev/null
	ipset -R < /tmp/china_v6.ipset 2>/dev/null
else
	ipset -N china_v4 hash:net 2>/dev/null
	awk '!/^$/&&!/^#/{printf("add china_v4 %s'" "'\n",$0)}' /etc/bypass/china.txt > /tmp/china.ipset
	ipset -F china_v4 2>/dev/null
	ipset -R < /tmp/china.ipset 2>/dev/null
fi
rm -f /tmp/china*.ipset
