refactoring + added last-run config...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2024-01-10 17:56:40 +03:00
parent 04989c47a2
commit 5f88f39dec
8 changed files with 98 additions and 25 deletions

View File

@ -171,14 +171,17 @@ getLatestTemplate(){
# #
# xread [-n] MSG VAR # xread [-n] MSG VAR
# #
# This saves all user input variables to the $XREAD_VARS array.
xread(){ xread(){
local non_empty= local non_empty=
if [[ $1 == '-n' ]] ; then if [[ $1 == '-n' ]] ; then
shift shift
local non_empty=1 local non_empty=1
fi fi
[ -z ${!2} ] \ if [ -z ${!2} ] ; then
&& eval 'read -ep "'$1'" -i "$DFL_'$2'" '${2}'' eval 'read -ep "'$1'" -i "$DFL_'$2'" '${2}''
XREAD_VARS+=(${2})
fi
if [ -z $non_empty ] ; then if [ -z $non_empty ] ; then
eval ''$2'=${'$2':=$DFL_'$2'}' eval ''$2'=${'$2':=$DFL_'$2'}'
fi fi
@ -240,16 +243,51 @@ tklWaitForSetup(){
# #
# readConfig # readConfig
# #
# Envioronment variables:
# CLEAN_RUN - if set ignore ./config.last-run
# CONFIG - config file to load last
#
readConfig(){ readConfig(){
if [ -z $NO_DEFAULTS ] ; then if [ -z $NO_DEFAULTS ] ; then
[ -e ../config.global ] \ [ -e ../config.global ] \
&& source ../config.global && source ../config.global
[ -e ./config ] \ [ -e ./config ] \
&& source ./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 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 # readVars
# #

View File

@ -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 config.global: config.global.example
vim "+0r config.global.example" $@ vim "+0r config.global.example" $@
#----------------------------------------------------------------------
# Shorthands...
.PHONY: config
config: config.global config: config.global
.PHONY: gate .PHONY: gate
gate: ./gate-traefik gate: gate-traefik
$</make.sh
.PHONY: ns
ns: ns.srv
.PHONY: ssh
ssh: ssh.srv
.PHONY: wireguard
wireguard: wireguard.srv
.PHONY: syncthing
syncthing: syncthing.srv
.PHONY: nextcloud
nextcloud: nextcloud.srv
.PHONY: gitea
gitea: gitea.srv
#----------------------------------------------------------------------
.PHONY: all .PHONY: all
all: config gate ns ssh wireguard syncthing nextcloud gitea all: config $(CTs)
#----------------------------------------------------------------------

View File

@ -95,6 +95,8 @@ echo "# Setup: iptables update script..."
echo "# Post config..." echo "# Post config..."
pctSet $ID "${OPTS_STAGE_2}" $REBOOT pctSet $ID "${OPTS_STAGE_2}" $REBOOT
saveLastRunConfig
echo "# Done." echo "# Done."

View File

@ -115,6 +115,7 @@ echo "# Updating system..."
echo "# Post config..." echo "# Post config..."
pctSet $ID "${OPTS_STAGE_2}" $REBOOT pctSet $ID "${OPTS_STAGE_2}" $REBOOT
saveLastRunConfig
echo "# Done." echo "# Done."

View File

@ -84,6 +84,8 @@ echo "# Setup: dnsmasq..."
echo "# Post config..." echo "# Post config..."
pctSet $ID "${OPTS_STAGE_2}" $REBOOT pctSet $ID "${OPTS_STAGE_2}" $REBOOT
saveLastRunConfig
echo "# Done." echo "# Done."

View File

@ -82,6 +82,8 @@ done
echo "# Post config..." echo "# Post config..."
pctSet $ID "${OPTS_STAGE_2}" $REBOOT pctSet $ID "${OPTS_STAGE_2}" $REBOOT
saveLastRunConfig
echo "# Done." echo "# Done."

View File

@ -80,6 +80,8 @@ sleep ${TIMEOUT:=5}
echo "# Post config..." echo "# Post config..."
pctSet $ID "${OPTS_STAGE_2}" $REBOOT pctSet $ID "${OPTS_STAGE_2}" $REBOOT
saveLastRunConfig
echo "# Done." echo "# Done."

View File

@ -106,6 +106,8 @@ echo "# client config:"
echo "# Post config..." echo "# Post config..."
pctSet $ID "${OPTS_STAGE_2}" $REBOOT pctSet $ID "${OPTS_STAGE_2}" $REBOOT
saveLastRunConfig
echo "# Done." echo "# Done."