From e514c8f46ce6a6df30d5f796d66a45c6babcb71c Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Thu, 19 Oct 2023 21:29:08 +0530 Subject: [PATCH] fix: making script usable on linux --- functions/kubernetes/generate_certs.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/functions/kubernetes/generate_certs.sh b/functions/kubernetes/generate_certs.sh index 59ee052d..7b24b3e1 100755 --- a/functions/kubernetes/generate_certs.sh +++ b/functions/kubernetes/generate_certs.sh @@ -1,6 +1,16 @@ #!/bin/bash +# Check if ifconfig is present and use it to get the default IP +if command -v ifconfig &> /dev/null; then + default_ip=$(ifconfig | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2}') +# Check if ip is present and use it if ifconfig is not available +elif command -v ip &> /dev/null; then + default_ip=$(ip addr show | grep -oP 'inet \K[\d.]+' | sed -n '2p') +# If both tools are not available, error out +else + echo "Error: Neither ifconfig nor ip command found in the machine. Exiting.." + exit 1 +fi -default_ip=$(ifconfig | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2}') read -p "Enter your node IP to use for cert generation (default is $default_ip): " custom_ip # Use localhost as the default value