#!/bin/bash : ' @vendor Chorke Academia, Inc. @web https://cdn.chorke.org/docs/academia @version 1.0.00 @since 1.0.00 ' :</dev/null #!/bin/bash : ' @vendor Chorke Academia, Inc. @web https://cdn.chorke.org/docs/academia @version 1.0.00 @since 1.0.00 ' USER_TARGET="minikube" function silent_exit(){ exit 0 } function verify_addr(){ printf -v DNS_HOST '%s' \$(sudo -u \${USER_TARGET} minikube ip) if [[ "\${DNS_HOST}" =~ ^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$ ]]; then if [[ "\${DNS_HOST}" == '127.0.0.1' ]]; then silent_exit; fi else silent_exit; fi } function verify_kube(){ printf -v K8S_JSON '%s' \$(sudo -u \${USER_TARGET} minikube status -o 'json') printf -v K8S_REST '%s' \$(echo \${K8S_JSON} | jq -r '.APIServer') printf -v K8S_KUBE '%s' \$(echo \${K8S_JSON} | jq -r '.Kubelet') printf -v K8S_HOST '%s' \$(echo \${K8S_JSON} | jq -r '.Host') if [[ "\${K8S_HOST}" == 'Running' ]]&& [[ "\${K8S_KUBE}" == 'Running' ]]&& [[ "\${K8S_REST}" == 'Running' ]]; then verify_addr else silent_exit; fi } function verify_tool(){ if [[ -x "\$(command -v jq)" ]]; then verify_kube; else silent_exit; fi } function verify_mini(){ if [[ -x "\$(command -v minikube)" ]]; then verify_tool; else silent_exit; fi } function verify_link(){ HOST_ETHERS="\$(ip -j link show | jq -r '.[].ifname'| paste -sd' ' -)" if [[ "\${HOST_ETHERS}" =~ "\${IFACE}" ]]; then verify_mini; else silent_exit; fi } function verify_mode(){ if [[ "\${MODE}" == 'start' ]]; then verify_link; else verify_mini; fi } function verify(){ verify_mode } function amend_nameserver(){ RESOLV_CONF='/etc/resolv.conf' if [[ -f \${RESOLV_CONF} ]]&&[[ "\$(grep -c \${DNS_HOST} \${RESOLV_CONF})" == 0 ]];then cat << CON | sudo tee -a \${RESOLV_CONF} >/dev/null # minikube dns server nameserver \${DNS_HOST} CON else silent_exit; fi } function handle(){ amend_nameserver } function init(){ verify handle } init EXE sudo chmod +x /etc/network/if-{up,post-down}.d/minikube-ifupdown