diff --git a/encode-k3s-yaml.sh b/encode-k3s-yaml.sh index e4d0e1f..ffbcf79 100755 --- a/encode-k3s-yaml.sh +++ b/encode-k3s-yaml.sh @@ -1,9 +1,24 @@ #!/usr/bin/env bash -echo "Provide the public DNS name or IP address of the k3s server:" -read -r server_url +# Define a function to read from the terminal +read_from_terminal() { + # Check if a tty is available + if [[ -t 0 ]]; then + # Use 'read -p' if standard input is an interactive terminal + read -p "$1" user_input + else + printf "\n" > /dev/tty + # If not interactive (e.g. piped), read from /dev/tty + # The '< /dev/tty' redirects input for 'read' to the terminal device + read -p "$1" user_input < /dev/tty + fi + echo "$user_input" +} + +server_url=$(read_from_terminal "Server URL (public DNS name or IP address for the k3s server): ") + +workdir=$(mktemp -d /tmp/encode-k3s-yaml.XXXXXX) -workdir = $(mktemp -d /tmp/encode-k3s-yaml.XXXXXX) cd $workdir echo "Working directory: $workdir" pwd