From 5f88f39dece3dfd56cc433f2146294ba4e2c497b Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 10 Jan 2024 17:56:40 +0300 Subject: [PATCH] refactoring + added last-run config... Signed-off-by: Alex A. Naanou --- .pct-helpers | 44 ++++++++++++++++++++++++++-- Makefile | 68 ++++++++++++++++++++++++++++++-------------- gate-traefik/make.sh | 2 ++ nextcloud/make.sh | 1 + ns/make.sh | 2 ++ ssh/make.sh | 2 ++ syncthing/make.sh | 2 ++ wireguard/make.sh | 2 ++ 8 files changed, 98 insertions(+), 25 deletions(-) diff --git a/.pct-helpers b/.pct-helpers index 03bb87d..875526b 100644 --- a/.pct-helpers +++ b/.pct-helpers @@ -171,14 +171,17 @@ getLatestTemplate(){ # # xread [-n] MSG VAR # +# This saves all user input variables to the $XREAD_VARS array. xread(){ local non_empty= if [[ $1 == '-n' ]] ; then shift local non_empty=1 fi - [ -z ${!2} ] \ - && eval 'read -ep "'$1'" -i "$DFL_'$2'" '${2}'' + if [ -z ${!2} ] ; then + eval 'read -ep "'$1'" -i "$DFL_'$2'" '${2}'' + XREAD_VARS+=(${2}) + fi if [ -z $non_empty ] ; then eval ''$2'=${'$2':=$DFL_'$2'}' fi @@ -240,16 +243,51 @@ tklWaitForSetup(){ # # readConfig -# +# +# Envioronment variables: +# CLEAN_RUN - if set ignore ./config.last-run +# CONFIG - config file to load last +# readConfig(){ if [ -z $NO_DEFAULTS ] ; then [ -e ../config.global ] \ && source ../config.global [ -e ./config ] \ && source ./config + # XXX is this the right priority for this??? + [ -e ./config.last-run ] \ + && [ -z $CLEAN_RUN ] \ + && source ./config.last-run + [ -e "$CONFIG" ] \ + && source $CONFIG fi } +# +# saveConfig [-d] CONFIG VAR .. +# +saveConfig(){ + local prefix= + if [ $1 == '-d' ] ; then + prefix=DFL_ + shift + fi + local cfg=$1 + shift + + { + for var in $@ ; do + echo "${prefix}${var}=${!var}" + done + } > $cfg +} + + +saveLastRunConfig(){ + echo "# Saving config to: config.last-run" + saveConfig -d config.last-run ${XREAD_VARS[@]} +} + # # readVars # diff --git a/Makefile b/Makefile index 6a6f38c..be27e12 100644 --- a/Makefile +++ b/Makefile @@ -1,42 +1,66 @@ +#---------------------------------------------------------------------- +# +# +# TODO: +# - cleanup/destroy +# - update +# - backup +# - pull config +# +#---------------------------------------------------------------------- + +# NOTE: The order here is important: +# - to avoid bootstrapping network connections gate must be the +# first CT to get built to route the rest of CT's to the WAN +# connection during the build process. +# - ns should be the second to be built to provide the rest of the +# CT's with DHCP network configuration. +# - the rest of the CT's are created in order of importance, strting +# from CT's needed for access and ending with services. +CTs := \ + gate \ + ns \ + ssh \ + wireguard \ + syncthing \ + nextcloud \ + gitea -%.srv: - $*/make.sh + +#---------------------------------------------------------------------- + +.PHONY: FORCE +FORCE: + + +%: %/make.sh FORCE + $< config.global: config.global.example vim "+0r config.global.example" $@ + +#---------------------------------------------------------------------- +# Shorthands... + +.PHONY: config config: config.global .PHONY: gate -gate: ./gate-traefik - $