71 lines
2.3 KiB
Bash
Executable File
71 lines
2.3 KiB
Bash
Executable File
#! /usr/bin/env bash
|
|
if [[ "$0" == "$SHELL" ]]; then
|
|
|
|
if [[ -z "FIX_KUBECTL_RECALL" ]]; then
|
|
unset kubectl 2>/dev/null || unalias kubectl 2>/dev/null || true
|
|
|
|
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
|
|
fi
|
|
|
|
[[ 'function' == $(type -t kubectl-fix) ]] && unset kubectl-fix
|
|
|
|
[[ ! -r "$HOME/.kube/config" ]] \
|
|
|| export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}"
|
|
|
|
if [[ -n "$(type -t 'k3s')" && -z "$(type -t 'kubectl')" ]]; then
|
|
if [[ -r "${KUBECONFIG}" ]]; then
|
|
kubectl() { k3s kubectl "${@}"; }
|
|
elif [[ -n "${KUBECONFIG}" && -e "${KUBECONFIG}" ]]; then
|
|
eval "
|
|
kubectl-fix() {
|
|
mkdir \"$HOME/.kube\" -p
|
|
if [[ -e \"\${KUBECONFIG}\" && ! -r \"$HOME/.kube/config\" ]]; then
|
|
sudo install --mod 600 --owner \"$USER\" \"\${KUBECONFIG}\" \"$HOME/.kube/config\"
|
|
unset KUBECONFIG
|
|
fi
|
|
FIX_KUBECTL_RECALL=1 . \"$BASH_SOURCE\"
|
|
}"
|
|
fi
|
|
fi
|
|
|
|
if [[ -n "$(type -t 'kubectl')" ]]; then
|
|
|
|
. <( kubectl completion ${SHELL##*/} )
|
|
|
|
if [[ -n "$(type -t 'kubectl-cnpg')" ]]; then
|
|
. <( kubectl cnpg completion ${SHELL##*/} )
|
|
else
|
|
CNPG_VER="${CNPG_VER:-1.20.2}"
|
|
GH_URL=https://github.com/cloudnative-pg/cloudnative-pg
|
|
DEB_FILE="kubectl-cnpg_${CNPG_VER}_linux_x86_64.deb"
|
|
URL=${GH_URL}/releases/download/v${CNPG_VER}/${DEB_FILE}
|
|
printf '%s\n' \
|
|
'To download adn install cnpg kubectl plugin, run:' \
|
|
" wget ${URL}" \
|
|
" sudo dpkg -i $DEB_FILE"
|
|
|
|
fi
|
|
|
|
if [[ -n "$(type -t 'k3s')" ]]; then
|
|
. <( k3s completion ${SHELL##*/} )
|
|
fi
|
|
|
|
if [[ -n "$(type -t 'helm')" ]]; then
|
|
. <( helm completion ${SHELL##*/} 2>/dev/null )
|
|
fi
|
|
|
|
kg() {
|
|
kubectl get ${NS:+--namespace=}${NS:---all-namespaces} "${@}" | { sed -u 1q; sort; }
|
|
}
|
|
fi
|
|
elif [[ "$1" == '-' ]]; then
|
|
cat $0
|
|
else
|
|
SCRIPT_NAME="$(basename $0)"
|
|
printf '%s\n' \
|
|
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
|
|
'The easiest way is to call it like this:' \
|
|
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
|
|
''
|
|
fi
|