From c95cd8b81c8f595e74453a301b0db800aa99b967 Mon Sep 17 00:00:00 2001 From: Roger Sikorski Date: Mon, 20 Apr 2026 10:06:54 +0200 Subject: [PATCH] talos added --- bin/talos | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 bin/talos diff --git a/bin/talos b/bin/talos new file mode 100644 index 0000000..63ec759 --- /dev/null +++ b/bin/talos @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +### Usage ### +# talos context [optional-nodename] command +# Example: +# talos home dashboard +# talos home dashboard +# talos home talos-nuc-1 dashboard + +# If wrong context or missing this script will output which contexts are available + +CONFIG_FILE="$HOME/.talos/config" + +# Check yq +if ! command -v yq &>/dev/null; then + echo "Error: yq (Go version v4+) not found." + exit 1 +fi + +# Read all contexts +mapfile -t CONTEXTS < <(yq e '.contexts | keys | .[]' "$CONFIG_FILE") + +# Helper: check if value exists in array +function contains() { + local seeking=$1; shift + for element; do + [[ "$element" == "$seeking" ]] && return 0 + done + return 1 +} + +# Require context +if [ -z "$1" ]; then + echo "Error: Context is required." + echo "Usage: talos [node] " + exit 1 +fi + +# Validate context +if ! contains "$1" "${CONTEXTS[@]}"; then + echo "Error: Invalid context '$1'" + echo "Available contexts:" + printf ' - %s\n' "${CONTEXTS[@]}" + exit 1 +fi + +CONTEXT="$1" +shift + +# Load nodes for context +mapfile -t NODES < <(yq e ".contexts.${CONTEXT}.nodes[]" "$CONFIG_FILE") + +NODE="" + +# Check if next arg is a node +if [ -n "$1" ]; then + for n in "${NODES[@]}"; do + if [[ "$n" == "$1" || "${n%%.*}" == "$1" ]]; then + NODE="$n" + shift + break + fi + done +fi + +# Execute +if [ -n "$NODE" ]; then + talosctl --context "$CONTEXT" -n "$NODE" -e "$NODE" "$@" +else + talosctl --context "$CONTEXT" "$@" +fi