#!/bin/bash
# set -eu
### --help Info: запуск kinit, общая ручка.
### --help Usage: /opt/bin/krb_init.sh
### --help Example: /opt/bin/krb_init.sh
# . /opt/fox_utils/crab_sys.sh

declare KRB5_PRINCIPAL KRB5_PRINCIPAL_KEYTAB
source /opt/CONFIG

if ! [[ ${KRB5_PRINCIPAL:-} && ${KRB5_PRINCIPAL_KEYTAB:-} ]]; then
	echo "KRB5_PRINCIPAL or KRB5_PRINCIPAL_KEYTAB is not set." >&2
	exit 1
fi

if ! [[ -r $KRB5_PRINCIPAL_KEYTAB ]]; then
	echo "$KRB5_PRINCIPAL_KEYTAB is not available." >&2
	exit 1
fi

kinit -k -t "$KRB5_PRINCIPAL_KEYTAB" "$KRB5_PRINCIPAL"

exit 0
