mirror of
https://github.com/flynx/proxmox-utils.git
synced 2025-12-17 17:11:47 +00:00
refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
f21d15c0a5
commit
ece66aa5b6
42
.pct-helpers
42
.pct-helpers
@ -317,20 +317,18 @@ readVars(){
|
|||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# buildAssets [TEMPLATES [ASSETS]]
|
# buildAssets [VAR ..]
|
||||||
#
|
#
|
||||||
buildAssets(){
|
buildAssets(){
|
||||||
local TEMPLATE_DIR=$1
|
local template_dir=${TEMPLATE_DIR:-templates}
|
||||||
TEMPLATE_DIR=${TEMPLATE_DIR:=templates}
|
local assets_dir=${ASSETS_DIR:-assets}
|
||||||
local ASSETS_DIR=$2
|
|
||||||
ASSETS_DIR=${ASSETS_DIR:=assets}
|
|
||||||
|
|
||||||
if ! [ -e $TEMPLATE_DIR ] ; then
|
if ! [ -e $template_dir ] ; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PATTERNS=()
|
local PATTERNS=()
|
||||||
DFL_VARS=(
|
local DFL_VARS=(
|
||||||
EMAIL
|
EMAIL
|
||||||
DOMAIN
|
DOMAIN
|
||||||
CTHOSTNAME
|
CTHOSTNAME
|
||||||
@ -347,10 +345,11 @@ buildAssets(){
|
|||||||
ADMIN_IP
|
ADMIN_IP
|
||||||
ADMIN_GATE
|
ADMIN_GATE
|
||||||
)
|
)
|
||||||
for var in ${DFL_VARS} ; do
|
for var in ${DFL_VARS[@]} ; do
|
||||||
PATTERNS+=("-e 's/\\\${${var}}/'\${${var}/\\//\\\\/}'/g'")
|
local val=${!var}
|
||||||
|
PATTERNS+=("-e 's/\\\${${var}}/${val/\\//\\\\/}/g'")
|
||||||
done
|
done
|
||||||
IP_VARS=(
|
local IP_VARS=(
|
||||||
GATE_LAN_IPn
|
GATE_LAN_IPn
|
||||||
GATE_ADMIN_IPn
|
GATE_ADMIN_IPn
|
||||||
NS_LAN_IPn
|
NS_LAN_IPn
|
||||||
@ -359,26 +358,27 @@ buildAssets(){
|
|||||||
LAN_IPn
|
LAN_IPn
|
||||||
ADMIN_IPn
|
ADMIN_IPn
|
||||||
)
|
)
|
||||||
for var in ${IP_VARS} ; do
|
for var in ${IP_VARS[@]} ; do
|
||||||
PATTERNS+=("-e 's/\\\${${var}}/'\${${var}/\\/*}'/g'")
|
local val=${!var}
|
||||||
|
PATTERNS+=("-e 's/\\\${${var}}/${val/\\/*}/g'")
|
||||||
done
|
done
|
||||||
# args...
|
# args...
|
||||||
for var in $@ ; do
|
for var in $@ ; do
|
||||||
PATTERNS+=("-e 's/\\\${${var}}/'\${${var}/\\//\\\\/}'/g'")
|
local val=${!var}
|
||||||
|
PATTERNS+=("-e 's/\\\${${var}}/${val/\\//\\\\/}/g'")
|
||||||
done
|
done
|
||||||
|
|
||||||
local TEMPLATES=($(find "$TEMPLATE_DIR" -type f))
|
local TEMPLATES=($(find "$template_dir" -type f))
|
||||||
for file in "${TEMPLATES[@]}" ; do
|
for file in "${TEMPLATES[@]}" ; do
|
||||||
file=${file#${TEMPLATE_DIR}}
|
file=${file#${template_dir}}
|
||||||
echo Generating: ${file}...
|
echo Generating: ${file}...
|
||||||
[ $DRY_RUN ] \
|
[ $DRY_RUN ] \
|
||||||
&& continue
|
&& continue
|
||||||
# ensure the directory exists...
|
# ensure the directory exists...
|
||||||
mkdir -p "$(dirname "${ASSETS_DIR}/${file}")"
|
mkdir -p "$(dirname "${assets_dir}/${file}")"
|
||||||
cat "${TEMPLATE_DIR}/${file}" \
|
cat "${template_dir}/${file}" \
|
||||||
| sed \
|
| eval "sed ${PATTERNS[@]}" \
|
||||||
${PATTERNS[@]} \
|
> "${assets_dir}/${file}"
|
||||||
> "${ASSETS_DIR}/${file}"
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -67,7 +67,7 @@ OPTS_STAGE_2="\
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
echo "# Building config..."
|
echo "# Building config..."
|
||||||
buildAssets "$TEMPLATE_DIR" "$ASSETS_DIR"
|
buildAssets
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
|
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
|
||||||
|
|||||||
@ -67,7 +67,7 @@ OPTS_STAGE_2="\
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
echo "# Building config..."
|
echo "# Building config..."
|
||||||
buildAssets "$TEMPLATE_DIR" "$ASSETS_DIR"
|
buildAssets
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
getLatestTemplate '.*-turnkey-nextcloud' TEMPLATE
|
getLatestTemplate '.*-turnkey-nextcloud' TEMPLATE
|
||||||
|
|||||||
@ -66,7 +66,7 @@ OPTS_STAGE_2="\
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
echo "# Building config..."
|
echo "# Building config..."
|
||||||
buildAssets "$TEMPLATE_DIR" "$ASSETS_DIR"
|
buildAssets
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
|
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
|
||||||
|
|||||||
@ -35,9 +35,12 @@ LAN_GATE=-
|
|||||||
|
|
||||||
REBOOT=${REBOOT:=1}
|
REBOOT=${REBOOT:=1}
|
||||||
|
|
||||||
DFL_ENDPOINT=${DFL_ENDPOINT:=${DOMAIN}}
|
DFL_ENDPOINT=${DFL_ENDPOINT:=$(dig +short DOMAIN | tail -1)}
|
||||||
xread "Wireguard endpoint: " ENDPOINT
|
xread "Wireguard endpoint: " ENDPOINT
|
||||||
|
|
||||||
|
DFL_ENDPOINT_PORT=${DFL_ENDPOINT_PORT:=51820}
|
||||||
|
xread "Wireguard endpoint port: " ENDPOINT_PORT
|
||||||
|
|
||||||
readVars
|
readVars
|
||||||
|
|
||||||
|
|
||||||
@ -66,7 +69,7 @@ OPTS_STAGE_2="\
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
echo "# Building config..."
|
echo "# Building config..."
|
||||||
buildAssets "$TEMPLATE_DIR" "$ASSETS_DIR"
|
buildAssets ENDPOINT ENDPOINT_PORT
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
|
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
|
||||||
|
|||||||
@ -13,8 +13,7 @@ CLIENT_DIR := $(SERVER_DIR)/clients/
|
|||||||
|
|
||||||
CLIENT_IPS ?= 10.42.0.0/16
|
CLIENT_IPS ?= 10.42.0.0/16
|
||||||
ENDPOINT_PORT ?= 51820
|
ENDPOINT_PORT ?= 51820
|
||||||
#ENDPOINT ?= ${DOMAIN}
|
ENDPOINT ?= ${ENDPOINT}
|
||||||
ENDPOINT ?= $(shell dig +short ${DOMAIN} | tail -1)
|
|
||||||
|
|
||||||
DNS ?= ${NS_LAN_IPn}
|
DNS ?= ${NS_LAN_IPn}
|
||||||
ALLOWED_IPS ?= 0.0.0.0/0
|
ALLOWED_IPS ?= 0.0.0.0/0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user