#!/bin/sh
# fizz-posix - dispatch to fizz-mount or fizz-serve based on first argument.
# Looks for the binaries in the same directory as this script.
dir="$(dirname "$0")"

usage()
{
	echo "fizz $("$dir/fizz-serve" VERSION) usage:" >&2
	echo "fizz mount host[:port] mntpoint [OH] [USE caps] [NEED caps] [fuse-options]" >&2
	echo "fizz serve [rootdir] [PORT num] [RO] [IFACE addr[:port]] [DEBUG]" >&2
	echo "fizz query host[:port]" >&2
	echo "fizz version" >&2
	echo "fizz cmd help for complete argument templates and help" >&2
}

case "$1" in
	mount)
		shift
		exec "$dir/fizz-mount" "$@"
		;;
	serve)
		shift
		exec "$dir/fizz-serve" "$@"
		;;
	query)
		shift
		if [ $# -eq 0 ]
		then
			echo "fizz: query requires a HOST argument" >&2
			usage
			exit 1
		fi
		# Inject a dummy mountpoint and the QUERY keyword; fizz-mount exits
		# before mounting when QUERY is set, so the mountpoint is never used.
		exec "$dir/fizz-mount" "$@" MOUNTPOINT . QUERY
		;;
	version|-v)
		exec "$dir/fizz-serve" VERSION
		;;
	'')
		usage
		exit 1
		;;
	*)
		echo "fizz: unknown command: $1" >&2
		usage
		exit 1
		;;
esac
