
# Exercise scripts on ipsec.conf file named $V in current directory.
# Output is logs named *.$V

# V is version (v1 or v2)
V=${V:-v2}

set -u
set -x

# auto(1:version 2:name 3:goal 4:op)
auto() {
	ipsec _confread  --config $1 --varprefix YYZ --search auto $3 >/tmp/list.$2.$1
	. list.$2.$1
	if [ "X$4" != "X-" -a -z "$YYZ_confreadstatus" -a -n "${YYZ_confreadnames:-}" ]
	then
		for i in $YYZ_confreadnames
		do
			ipsec auto --showonly --config $1 --$4 $i
		done >/tmp/auto.$2.$1
	fi
}

ipsec setup --config $V --showonly start >/tmp/setup.start.out.$V
ipsec setup --config $V --showonly stop >/tmp/setup.stop.out.$V
ipsec _confread  --config $V --search auto route >/tmp/confread.search.route.$V

auto $V ignore ignore -
auto $V manual manual -
auto $V add "add route start" add
auto $V route "route start" route
auto $V start start up

