mirror of
https://github.com/flynx/proxmox-utils.git
synced 2025-12-17 09:01:49 +00:00
refactoring + added last-run config...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
04989c47a2
commit
5f88f39dec
42
.pct-helpers
42
.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
|
||||
@ -241,15 +244,50 @@ 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
|
||||
#
|
||||
|
||||
68
Makefile
68
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
|
||||
$</make.sh
|
||||
gate: gate-traefik
|
||||
|
||||
|
||||
.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
|
||||
all: config gate ns ssh wireguard syncthing nextcloud gitea
|
||||
all: config $(CTs)
|
||||
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
@ -95,6 +95,8 @@ echo "# Setup: iptables update script..."
|
||||
echo "# Post config..."
|
||||
pctSet $ID "${OPTS_STAGE_2}" $REBOOT
|
||||
|
||||
saveLastRunConfig
|
||||
|
||||
echo "# Done."
|
||||
|
||||
|
||||
|
||||
@ -115,6 +115,7 @@ echo "# Updating system..."
|
||||
echo "# Post config..."
|
||||
pctSet $ID "${OPTS_STAGE_2}" $REBOOT
|
||||
|
||||
saveLastRunConfig
|
||||
|
||||
echo "# Done."
|
||||
|
||||
|
||||
@ -84,6 +84,8 @@ echo "# Setup: dnsmasq..."
|
||||
echo "# Post config..."
|
||||
pctSet $ID "${OPTS_STAGE_2}" $REBOOT
|
||||
|
||||
saveLastRunConfig
|
||||
|
||||
echo "# Done."
|
||||
|
||||
|
||||
|
||||
@ -82,6 +82,8 @@ done
|
||||
echo "# Post config..."
|
||||
pctSet $ID "${OPTS_STAGE_2}" $REBOOT
|
||||
|
||||
saveLastRunConfig
|
||||
|
||||
echo "# Done."
|
||||
|
||||
|
||||
|
||||
@ -80,6 +80,8 @@ sleep ${TIMEOUT:=5}
|
||||
echo "# Post config..."
|
||||
pctSet $ID "${OPTS_STAGE_2}" $REBOOT
|
||||
|
||||
saveLastRunConfig
|
||||
|
||||
echo "# Done."
|
||||
|
||||
|
||||
|
||||
@ -106,6 +106,8 @@ echo "# client config:"
|
||||
echo "# Post config..."
|
||||
pctSet $ID "${OPTS_STAGE_2}" $REBOOT
|
||||
|
||||
saveLastRunConfig
|
||||
|
||||
echo "# Done."
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user