#!/bin/sh

# Global variables and functions

if [ -z "${LAN_IF}" ]; then

	# There are two uplinks.
	# First uplink is via LAN, gateway is 10.1.5.254
	# Second is via PPPoE from this box.
	LAN_IF="igb0"
	LAN="10.1.5.0/24"
	GATE1_IP="10.1.5.254"
	GATE2_IP="10.1.5.2"
	WAN_D_IF="ng0" # FIXME
	WAN_D_GATEWAY_IP="10.85.20.1"
	# All traffic from/to nets listed in this table will be dropped.
	BADNETS_TID=3
	# TODO: This script should also be called by cron
	UPDATE_TABLES=/opt/etc/update-tables.sh

	try_uplink=/opt/etc/try-uplink-mpd5
	good_host=8.8.8.8
	lockfile=/opt/etc/heartbeat-lock
	logfile=/opt/etc/heartbeat-log

	ovpn_configs="/opt/etc/openvpn/nocnt-server.conf \
		/opt/etc/openvpn/nocntru-client.conf \
		/opt/etc/openvpn/lac/conf.lacserver-tcp \
		/opt/etc/openvpn/lac/conf.lacserver-udp"

	pptp_config_dir="/opt/etc/pptpsrv"

	fw="/sbin/ipfw -q"
	ic=/sbin/ifconfig
	rm=/bin/rm
	cat=/bin/cat
	kill=/bin/kill
	sleep=/bin/sleep
	ping=/sbin/ping
	route=/sbin/route
	grep=/usr/bin/grep
	pgrep=/bin/pgrep
	ps=/bin/ps
	awk=/usr/bin/awk
	wc=/usr/bin/wc
	touch=/usr/bin/touch
	tee=/usr/bin/tee
	tr=/usr/bin/tr
	head=/usr/bin/head
	tail=/usr/bin/tail
	basename=/usr/bin/basename
	mpd5=/usr/local/sbin/mpd5
	ovpn=/usr/local/sbin/openvpn

	targetvms="master node01"

	powerhost=nasbox
	# absence of this file will prevent VMS from starting
	powerflag=/tmp/powergood
	apcaccess=/usr/local/sbin/apcaccess
	vmuser=vladimir
	su=/usr/bin/su
	daemon=/usr/sbin/daemon
	chown=/usr/sbin/chown
	vboxmanage=/usr/local/bin/VBoxManage

	# Obviously, $1 should be unique
	# FIXME: buggy dangerous beast! Once I had sent sigterm to /sbin/init ...
	get_pid_by_arg () {
		return `$ps axww | $grep $1 | $grep -v $grep | $awk '{print $1;}'`
	}

	xzfile () {
		cat "$1" | xz - > "$2".xz
	}

	if [ -f /opt/etc/targetvms ]; then
		. /opt/etc/targetvms
	fi

fi

