# vim: set ft=zsh : switchrealm() { local realm principal case ${1:l} in s|sp|securepassage.com) realm=SECUREPASSAGE.COM localdomain=${realm:l} principal=dhatch@${realm} ;; d|dev|dev.cloud.frmn) realm=DEV.CLOUD.FRMN localdomain=${realm:l} principal=dhatch@${realm} ;; t|test|testing|testing.cloud.frmn) realm=TESTING.CLOUD.FRMN localdomain=${realm:l} principal=dhatch@${realm} ;; p|prod|prod.cloud.frmn) realm=PROD.CLOUD.FRMN localdomain=${realm:l} principal=dhatch@${realm} ;; *) realm=${1} localdomain=${3:-${realm:l}} ;; esac if [[ -z ${realm} ]]; then unset KRB5CCNAME unset LOCALDOMAIN else cachefile=/tmp/.krb5cc_$(id -u)_${realm} export KRB5CCNAME=${cachefile} export LOCALDOMAIN=${localdomain} if ! klist -s; then : ${principal:=${2:-${LOGNAME}}} if [[ ! ${principal} = *@* ]]; then principal=${principal}@${realm} fi kinit ${principal} fi fi klist } switchrealm "$@"