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

usage()
{
	echo "fitz $("$dir/fitz-serve" VERSION) usage:" >&2
	echo "fitz mount host[:port] mntpnt [OH] [ENCRYPT] [CIPHER name]" >&2
	echo "           [USE caps] [NEED caps] [HELP] [fuse-args]" >&2
	echo "fitz serve [rootdir] [PORT num] [RO] [IFACE addr[:port]]" >&2
	echo "           [ASKPASS] [ENCRYPT] [HELP]" >&2
	echo "fitz query host[:port]" >&2
	echo "fitz version" >&2
}

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