#!/usr/bin/env bash
set -e

#echo "现在会真正去部署了，请务必带 --limit 运行。"
#echo "现在开放测试的节点：south.mycard.moe,yuzurisa.mycard.moe,hk-hkg-alql2.mycard.moe,ayane.mycard.moe,hk-hkg-alql3.mycard.moe,wg-router.mycard.moe,kuroko.mycard.moe"

#read -p '确认无误后按回车继续'


mkdir -p result
npm run inventory

cd ansible || exit

sed -r -e '/^Address/d' \
                -e '/^Fwmark/d' \
                -e '/^Table/d' \
                -e '/^DNS/d' \
                -e '/^MTU/d' \
                -e '/^PostUp/d' \
                -e '/^PostDown/d' \
                -e '/^PreUp/d' \
                -e '/^PreDown/d' \
                ./protocols/wg/wg.conf.j2 > ./protocols/wg/wg-setconf.conf.j2
sed -r -e '/^Address/d' \
                -e '/^Fwmark/d' \
                -e '/^Table/d' \
                -e '/^DNS/d' \
                -e '/^MTU/d' \
                -e '/^PostUp/d' \
                -e '/^PostDown/d' \
                -e '/^PreUp/d' \
                -e '/^PreDown/d' \
                ./protocols/wgfrp/wgfrp.conf.j2 > ./protocols/wgfrp/wgfrp-setconf.conf.j2

ansible-playbook -i ../result/inventory.yaml "$@" configure.yaml
