diff --git a/.pct-helpers b/.pct-helpers index dff5478..943962d 100644 --- a/.pct-helpers +++ b/.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 } diff --git a/gate-traefik/make.sh b/gate-traefik/make.sh index 401cb24..ece80c3 100755 --- a/gate-traefik/make.sh +++ b/gate-traefik/make.sh @@ -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" diff --git a/nextcloud/make.sh b/nextcloud/make.sh index a0705d6..a45437a 100755 --- a/nextcloud/make.sh +++ b/nextcloud/make.sh @@ -67,7 +67,7 @@ OPTS_STAGE_2="\ #---------------------------------------------------------------------- echo "# Building config..." -buildAssets "$TEMPLATE_DIR" "$ASSETS_DIR" +buildAssets echo "# Creating CT..." getLatestTemplate '.*-turnkey-nextcloud' TEMPLATE diff --git a/ns/make.sh b/ns/make.sh index f274424..d52d8e9 100755 --- a/ns/make.sh +++ b/ns/make.sh @@ -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" diff --git a/wireguard/make.sh b/wireguard/make.sh index e7272ae..362aeff 100755 --- a/wireguard/make.sh +++ b/wireguard/make.sh @@ -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" diff --git a/wireguard/templates/root/Makefile b/wireguard/templates/root/Makefile index 573185f..df43376 100644 --- a/wireguard/templates/root/Makefile +++ b/wireguard/templates/root/Makefile @@ -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