From 34a8199902df3b02069db63d81b1d9570b8ba693 Mon Sep 17 00:00:00 2001 From: "Lockszmith (@kateryna)" Date: Tue, 24 Dec 2024 15:28:51 -0500 Subject: [PATCH] Move system specific values into _templates Added szetup.sh to link to the system specific templates --- .gitignore | 20 +++++++---- .../mw.fwd-auth-sysmgr.yml.shefet | 0 .../mw.fwd-auth-sysmgr.yml.sz | 0 .../dynamic/{ => _templates}/rt.ha.yml.shefet | 2 +- .../dynamic/{ => _templates}/rt.ha.yml.sz | 2 +- szetup.sh | 35 +++++++++++++++++++ 6 files changed, 50 insertions(+), 9 deletions(-) rename _traefik/dynamic/{ => _templates}/mw.fwd-auth-sysmgr.yml.shefet (100%) rename _traefik/dynamic/{ => _templates}/mw.fwd-auth-sysmgr.yml.sz (100%) rename _traefik/dynamic/{ => _templates}/rt.ha.yml.shefet (96%) rename _traefik/dynamic/{ => _templates}/rt.ha.yml.sz (96%) create mode 100755 szetup.sh diff --git a/.gitignore b/.gitignore index 0ad8a25..364aaa4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,15 @@ -.env.local +# These will be a local sym-link +*.local +*.local.yml +# local env should not be committed +app.env +# local data should always be in a subdir named local, and never committed +**/local +# traefik/tls and /sahred shouldn't exist, but in case they are copied over - don't commit them _traefik/tls _traefik/shared -**/app.env -ddns-updater/config.json -# This is will be a local sym-link -*.local.yml -*.local -local.* +# make it eash to disable stuff without committing +tmp.* +*.tmp +*.off + diff --git a/_traefik/dynamic/mw.fwd-auth-sysmgr.yml.shefet b/_traefik/dynamic/_templates/mw.fwd-auth-sysmgr.yml.shefet similarity index 100% rename from _traefik/dynamic/mw.fwd-auth-sysmgr.yml.shefet rename to _traefik/dynamic/_templates/mw.fwd-auth-sysmgr.yml.shefet diff --git a/_traefik/dynamic/mw.fwd-auth-sysmgr.yml.sz b/_traefik/dynamic/_templates/mw.fwd-auth-sysmgr.yml.sz similarity index 100% rename from _traefik/dynamic/mw.fwd-auth-sysmgr.yml.sz rename to _traefik/dynamic/_templates/mw.fwd-auth-sysmgr.yml.sz diff --git a/_traefik/dynamic/rt.ha.yml.shefet b/_traefik/dynamic/_templates/rt.ha.yml.shefet similarity index 96% rename from _traefik/dynamic/rt.ha.yml.shefet rename to _traefik/dynamic/_templates/rt.ha.yml.shefet index a9c852b..774b6ea 100644 --- a/_traefik/dynamic/rt.ha.yml.shefet +++ b/_traefik/dynamic/_templates/rt.ha.yml.shefet @@ -2,7 +2,7 @@ http: routers: # Define a connection between requests and services - "to-ha": + home-assistant: rule: "Host(`ha.shefet.net`)" entrypoints: - websecure diff --git a/_traefik/dynamic/rt.ha.yml.sz b/_traefik/dynamic/_templates/rt.ha.yml.sz similarity index 96% rename from _traefik/dynamic/rt.ha.yml.sz rename to _traefik/dynamic/_templates/rt.ha.yml.sz index 82ad8e7..66ce575 100644 --- a/_traefik/dynamic/rt.ha.yml.sz +++ b/_traefik/dynamic/_templates/rt.ha.yml.sz @@ -2,7 +2,7 @@ http: routers: # Define a connection between requests and services - "to-ha": + home-assistant: rule: "Host(`ha.lksz.me`)" entrypoints: - websecure diff --git a/szetup.sh b/szetup.sh new file mode 100755 index 0000000..abda927 --- /dev/null +++ b/szetup.sh @@ -0,0 +1,35 @@ +#! /usr/bin/env bash +set -e +SCRIPT_DIR=${SCRIPT_DIR:-"$( cd -- "$( dirname -- "$0" )" &> /dev/null && pwd )"} + +SYS_NAME=${1:-${SYS_NAME:?Must supply sysname as 1st argument}} +TOP_DIR="$SCRIPT_DIR/_traefik/dynamic" + +# Store the find results in an array +mapfile -d '' -t DELETE < <(find "$TOP_DIR" -maxdepth 1 -mindepth 1 -type l -lname '*_templates/*' -print0) + +# If links were found, process and delete them +if [ ${#DELETE[@]} -gt 0 ]; then + for link in "${DELETE[@]}"; do + # Get the target of the symbolic link + target=$(basename $(readlink -f "$link")) + + # Delete the link + rm "$link" + + # Report the deleted link and its target + printf '"%s" (%s) deleted.\n' "$link" "${target##*.}" + done +else + echo "No matching symbolic links found to delete." +fi + + +find "$TOP_DIR/_templates" -maxdepth 1 -mindepth 1 -type f -name "*.${SYS_NAME}" -print0 \ +| while IFS= read -r -d '' file; do + base=$(basename "$file" ".${SYS_NAME}") + ext="${base##*.}" + #echo ln -rs "${file#${TOP_DIR}/}" "${base}" + ln -vrs "${file}" "${TOP_DIR}/${base%${ext}}local.$ext"t +done +