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