#!/bin/sh
##
##  cockroach.sh -- CockroachDB CLI Wrapper
##

if [ ".$COCKROACH_HOST" = . ]; then
    COCKROACH_HOST="`grep '^host=' @l_prefix@/etc/cockroach/cockroach.conf | sed -e 's;^[^=]*=;;'`"
    export COCKROACH_HOST
fi
if [ ".$COCKROACH_PORT" = . ]; then
    COCKROACH_PORT="`grep '^port=' @l_prefix@/etc/cockroach/cockroach.conf | sed -e 's;^[^=]*=;;'`"
    export COCKROACH_PORT
fi
if [ ! -d "$HOME/.cockroach-certs" -a ".$COCKROACH_CERTS_DIR" = . ]; then
    COCKROACH_CERTS_DIR="`grep '^certs-dir=' @l_prefix@/etc/cockroach/cockroach.conf | sed -e 's;^[^=]*=;;'`"
    export COCKROACH_CERTS_DIR
fi

exec @l_prefix@/libexec/cockroach/cockroach ${1+"$@"}

