From 22d4dc15cee20b287f26f2d0d8498ea91d515a7b Mon Sep 17 00:00:00 2001 From: Paul Payne Date: Fri, 15 Aug 2025 03:32:18 -0700 Subject: [PATCH] Backup env config setup. Add `--check` flag to wild-config and wild-set. --- bin/wild-config | 20 +++++++++++++++++++- bin/wild-secret | 20 +++++++++++++++++++- setup/home-scaffold/env.sh | 14 ++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/bin/wild-config b/bin/wild-config index 428355b..a240690 100755 --- a/bin/wild-config +++ b/bin/wild-config @@ -5,7 +5,7 @@ set -o pipefail # Usage function usage() { - echo "Usage: wild-config " + echo "Usage: wild-config [--check] " echo "" echo "Read a value from \$WC_HOME/config.yaml using a YAML key path." echo "" @@ -13,18 +13,25 @@ usage() { echo " wild-config 'cluster.name' # Get cluster name" echo " wild-config 'apps.myapp.replicas' # Get app replicas count" echo " wild-config 'services[0].name' # Get first service name" + echo " wild-config --check 'cluster.name' # Exit 1 if key doesn't exist" echo "" echo "Options:" + echo " --check Exit 1 if key doesn't exist (no output)" echo " -h, --help Show this help message" } # Parse arguments +CHECK_MODE=false while [[ $# -gt 0 ]]; do case $1 in -h|--help) usage exit 0 ;; + --check) + CHECK_MODE=true + shift + ;; -*) echo "Unknown option $1" usage @@ -61,6 +68,9 @@ fi CONFIG_FILE="${WC_HOME}/config.yaml" if [ ! -f "${CONFIG_FILE}" ]; then + if [ "${CHECK_MODE}" = true ]; then + exit 1 + fi echo "Error: config file not found at ${CONFIG_FILE}" >&2 echo "" exit 0 @@ -71,9 +81,17 @@ result=$(yq eval ".${KEY_PATH}" "${CONFIG_FILE}" 2>/dev/null || echo "null") # Check if result is null (key not found) if [ "${result}" = "null" ]; then + if [ "${CHECK_MODE}" = true ]; then + exit 1 + fi echo "Error: Key path '${KEY_PATH}' not found in ${CONFIG_FILE}" >&2 echo "" exit 0 fi +# In check mode, exit 0 if key exists (don't output value) +if [ "${CHECK_MODE}" = true ]; then + exit 0 +fi + echo "${result}" \ No newline at end of file diff --git a/bin/wild-secret b/bin/wild-secret index b170aed..879c0bf 100755 --- a/bin/wild-secret +++ b/bin/wild-secret @@ -5,7 +5,7 @@ set -o pipefail # Usage function usage() { - echo "Usage: wild-secret " + echo "Usage: wild-secret [--check] " echo "" echo "Read a value from ./secrets.yaml using a YAML key path." echo "" @@ -13,18 +13,25 @@ usage() { echo " wild-secret 'database.password' # Get database password" echo " wild-secret 'api.keys.github' # Get GitHub API key" echo " wild-secret 'credentials[0].token' # Get first credential token" + echo " wild-secret --check 'api.keys.github' # Exit 1 if key doesn't exist" echo "" echo "Options:" + echo " --check Exit 1 if key doesn't exist (no output)" echo " -h, --help Show this help message" } # Parse arguments +CHECK_MODE=false while [[ $# -gt 0 ]]; do case $1 in -h|--help) usage exit 0 ;; + --check) + CHECK_MODE=true + shift + ;; -*) echo "Unknown option $1" usage @@ -61,6 +68,9 @@ fi SECRETS_FILE="${WC_HOME}/secrets.yaml" if [ ! -f "${SECRETS_FILE}" ]; then + if [ "${CHECK_MODE}" = true ]; then + exit 1 + fi echo "Error: secrets file not found at ${SECRETS_FILE}" >&2 echo "" exit 0 @@ -71,9 +81,17 @@ result=$(yq eval ".${KEY_PATH}" "${SECRETS_FILE}" 2>/dev/null || echo "null") # Check if result is null (key not found) if [ "${result}" = "null" ]; then + if [ "${CHECK_MODE}" = true ]; then + exit 1 + fi echo "Error: Key path '${KEY_PATH}' not found in ${SECRETS_FILE}" >&2 echo "" exit 0 fi +# In check mode, exit 0 if key exists (don't output value) +if [ "${CHECK_MODE}" = true ]; then + exit 0 +fi + echo "${result}" \ No newline at end of file diff --git a/setup/home-scaffold/env.sh b/setup/home-scaffold/env.sh index f03054f..a2651a3 100644 --- a/setup/home-scaffold/env.sh +++ b/setup/home-scaffold/env.sh @@ -76,3 +76,17 @@ else fi fi fi + + +# Backup configuration. +if `wild-config cloud.backup.root --check`; then + export RESTIC_REPOSITORY="$(wild-config cloud.backup.root)" +else + echo "WARNING: Could not get cloud backup root." +fi + +if `wild-secret cloud.backupPassword --check`; then + export RESTIC_PASSWORD="$(wild-secret cloud.backupPassword)" +else + echo "WARNING: Could not get cloud backup secret." +fi