#!/bin/bash

set -e

CMD_DIR="/usr/lib/openvpn-server/ovs-commands"

cmd_name="$(basename $0)"

if [ -x "${CMD_DIR}/${cmd_name}" ]; then
	# Compatibility wrapper; tell the user about the new behaviour and
	# exec the wrapped command
	echo "Warning: This command has been deprecated."
	echo "         Please use '/usr/sbin/ovs ${cmd_name}' instead."
	exec "${CMD_DIR}/${cmd_name}" "$@"
fi

if [ -z "$1" ]; then
	echo "Error: You must give a subcommand" >&2
	exec "${CMD_DIR}/help" "$@"
	exit 1
fi

cmd="$1"
shift

if [ ! -x "${CMD_DIR}/${cmd}" ]; then
	echo "Error: unknown command '${cmd}'" >&2
	exec "${CMD_DIR}/help" "$@"
	exit 1
fi

exec "${CMD_DIR}/${cmd}" "$@"
