#!/usr/bin/env bash # stops the execution if a command or pipeline has an error set -eu if command -v tput >/dev/null && tput setaf 1 >/dev/null 2>&1; then # color codes RED="$(tput setaf 1)" RESET="$(tput sgr0)" fi ERR="${RED:-}ERROR:${RESET:-}" source ./current_versions.sh err() ( if [[ -z ${1:-} ]]; then cat >&2 else echo "$ERR " "$@" >&2 fi ) candidate_interfaces() ( ip -o link show | awk -F': ' '{print $2}' | sed 's/[ \t].*//;/^\(lo\|bond0\|\|\)$/d' | sort ) validate_tinkerbell_network_interface() ( local tink_interface=$1 if ! candidate_interfaces | grep -q "^$tink_interface$"; then err "Invalid interface ($tink_interface) selected, must be one of:" candidate_interfaces | err return 1 else return 0 fi ) generate_password() ( head -c 12 /dev/urandom | sha256sum | cut -d' ' -f1 ) generate_env() ( local tink_interface=$1 validate_tinkerbell_network_interface "$tink_interface" local tink_password tink_password=$(generate_password) local registry_password registry_password=$(generate_password) cat < .env" exit 1 fi generate_env "$1" ) main "$@"