#!/bin/bash
path_script="$(readlink -f "$0")"
path_dir="${path_script%/*}"
source ${1:-$path_dir/az-dev.conf}
fn=`basename "$0"`

if [ -f "$2" ]; then #Local debug credentials in 2nd file not in git
    echo "#$fn: !!!## source second file $2"
    source $2
fi

if [[ "$DebugDeleteKubeConf" != false ]]; then
	echo "#$0: Running cleanup script"

    #set -x

	echo "#$0: run az logout"
	az logout

	echo "#$0: Start deleteting config files";
	ls -l $HOME/.kube/config
	rm -f $HOME/.kube/config
	ls -l $HOME/.kube/config
	rc=$?
	if [[ $rc -ne 0 ]]; then
		echo "#$0: kubeconfig files removed rc=$rc"
		exit 0
	else
		echo "#$0: error removing kubeconfig file rc=$rc"
		exit 1
	fi

else
    echo "#$0: Skip cleanup DebugDeleteKubeConf=\"$DebugDeleteKubeConf\" "
fi
