dustin
/
zdotdir
Archived
1
0
Fork 0
This repository has been archived on 2023-11-14. You can view files and clone it, but cannot push or open issues/pull-requests.
zdotdir/functions/switchrealm

52 lines
961 B
Bash

# 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 "$@"