#!/bin/sh -e

PREFIX=corridor_

if test "$1" = --init; then
	shift
	exec ipset create "$PREFIX$@" -exist
fi

IPSET=$PREFIX${1?}
TMP=$IPSET.tmp
shift

{
	echo create  $IPSET "$@" -exist
	echo create  $TMP   "$@" -exist
	echo flush   $TMP
	sed "s/^/add $TMP /"
	echo swap    $TMP $IPSET
	echo destroy $TMP
} | ipset restore >&2

echo $IPSET updated. >&2
