Blame public/fs/etc/openvpn/hostvpn-conf.sh

root@culturestrings 76b152
#!/bin/sh
root@culturestrings 76b152
root@culturestrings 76b152
set -eu
root@culturestrings 76b152
root@culturestrings 0a05a5
sitezone="$1"
root@culturestrings c2ee4c
vpn_type="$2"
root@culturestrings 0a05a5
root@culturestrings 0a05a5
cfg_script="$0"
root@culturestrings 0a05a5
cfg_srcdir=$(cd -- "${cfg_script%/*}/" ; pwd -P)
root@culturestrings 0a05a5
root@culturestrings b0963f
source /root/config/private/config/server.ports
root@culturestrings 0a05a5
source /root/config/private/config/hostinfo/${sitezone}
root@culturestrings 76b152
root@culturestrings c2ee4c
if [ ${vpn_type} = 'primary' ]; then
root@culturestrings c2ee4c
	vpn_tunnel=tun0
root@culturestrings c2ee4c
	ipv6_subnet=8000
root@culturestrings c2ee4c
root@culturestrings c2ee4c
	if [ ${vpn_route_all} = 'yes' ]; then
root@culturestrings c2ee4c
		vpn_route_all_subst='s/^@vpn_route_all@ //g'
root@culturestrings c2ee4c
	else
root@culturestrings c2ee4c
		vpn_route_all_subst='/^@vpn_route_all@ /d'
root@culturestrings c2ee4c
	fi
root@culturestrings c2ee4c
root@culturestrings c2ee4c
	sed -e 's/@vpn_tunnel@/'${vpn_tunnel}'/g' \
root@culturestrings c2ee4c
		-e 's/@vpn_type@/'${vpn_type}'/g'  \
root@culturestrings c2ee4c
		-e 's/@vpn_port@/'${vpn_port}'/g'   \
root@culturestrings c2ee4c
		-e 's/@hostname@/'${hostname}'/g'    \
root@culturestrings c2ee4c
		-e 's/@vpn_net4@/'${vpn_net4}'/g'     \
root@culturestrings c2ee4c
		-e 's/@vpn_ipv4@/'${vpn_ipv4}'/g'      \
root@culturestrings c2ee4c
		-e 's/@host_ipv4@/'${host_ipv4}'/g'     \
root@culturestrings c2ee4c
		-e 's/@host_ipv6@/'${host_ipv6}'/g'      \
root@culturestrings c2ee4c
		-e 's/@ipv6_subnet@/'${ipv6_subnet}'/g'   \
root@culturestrings c2ee4c
		-e "${vpn_route_all_subst}"                \
root@culturestrings c2ee4c
		"${cfg_srcdir}/hostvpn.conf.in"
root@culturestrings c2ee4c
root@culturestrings c2ee4c
elif [ ${vpn_type} = 'secondary' ]; then
root@culturestrings c2ee4c
	vpn_tunnel=tun1
root@culturestrings c2ee4c
	ipv6_subnet=c000
root@culturestrings c2ee4c
root@culturestrings c2ee4c
	if [ ${avpn_route_all} = 'yes' ]; then
root@culturestrings c2ee4c
		vpn_route_all_subst='s/^@vpn_route_all@ //g'
root@culturestrings c2ee4c
	else
root@culturestrings c2ee4c
		vpn_route_all_subst='/^@vpn_route_all@ /d'
root@culturestrings c2ee4c
	fi
root@culturestrings c2ee4c
root@culturestrings c2ee4c
	sed -e 's/@vpn_tunnel@/'${vpn_tunnel}'/g' \
root@culturestrings c2ee4c
		-e 's/@vpn_type@/'${vpn_type}'/g'  \
root@culturestrings c2ee4c
		-e 's/@vpn_port@/'${avpn_port}'/g'  \
root@culturestrings c2ee4c
		-e 's/@hostname@/'${hostname}'/g'    \
root@culturestrings c2ee4c
		-e 's/@vpn_net4@/'${avpn_net4}'/g'    \
root@culturestrings c2ee4c
		-e 's/@vpn_ipv4@/'${avpn_ipv4}'/g'     \
root@culturestrings c2ee4c
		-e 's/@host_ipv4@/'${host_ipv4}'/g'     \
root@culturestrings c2ee4c
		-e 's/@host_ipv6@/'${host_ipv6}'/g'      \
root@culturestrings c2ee4c
		-e 's/@ipv6_subnet@/'${ipv6_subnet}'/g'   \
root@culturestrings c2ee4c
		-e "${vpn_route_all_subst}"                \
root@culturestrings c2ee4c
		"${cfg_srcdir}/hostvpn.conf.in"
root@culturestrings c2ee4c
root@culturestrings a75d12
else
root@culturestrings c2ee4c
	printf '%s\n' 'usage: ./hostvpn-conf.sh sitezone {primary|secondary}'
root@culturestrings c2ee4c
	exit 2
root@culturestrings a75d12
fi