Compare commits

..

No commits in common. "5d6e412d29b49955f6f1c12e5616764848be5af4" and "e5f14c352d1729503e7a4e502ddf8ca048a6a78e" have entirely different histories.

10 changed files with 123 additions and 230 deletions

View File

@ -49,7 +49,6 @@ would-like(){
}
#----------------------------------------------------------------------
# Fill section...
#
@ -149,7 +148,6 @@ hostname2ct(){
}
#----------------------------------------------------------------------
normpath(){
@ -163,9 +161,35 @@ normpath(){
}
#----------------------------------------------------------------------
#
# getLatestTemplate PATTERN [VAR]
#
# see:
# https://pve.proxmox.com/wiki/Linux_Container
getLatestTemplate(){
if [ $DRY_RUN ] ; then
[ -z $2 ] \
|| eval "$2=${CT_TEMPLATE:-\\\$CT_TEMPLATE}"
return
fi
#IFS=$'\n'
#@ pveam update
local templates=($(pveam available | grep -o ''${1}'.*$'))
local latest=${templates[-1]}
@ pveam download local ${latest}
latest=$(pveam list local | grep -o "^.*$latest")
#latest=($(ls /var/lib/vz/template/cache/${1}*))
[ -z $2 ] \
|| eval "$2=${latest}"
}
#
# xread [-n] MSG VAR
#
@ -178,9 +202,8 @@ xread(){
shift
local non_empty=1
fi
# skip...
if [[ "${!2}" == "SKIP" ]] \
|| [[ "$(eval "echo \$DFL_$2")" == "SKIP" ]] ; then
# XXX check DFL_..???
if [[ "${!2}" == "SKIP" ]] ; then
eval "$2="
return
fi
@ -264,8 +287,32 @@ xreadpass(){
}
# Wait for /etc/inithooks.conf to be generated then cleared
#
# tklWaitForSetup ID
#
# for tkl inithooks doc see:
# https://www.turnkeylinux.org/docs/inithooks
tklWaitForSetup(){
printf "# TKL setup, this may take a while"
if [ -z $DRY_RUN ] ; then
while ! $(lxc-attach $1 -- test -e /etc/inithooks.conf) ; do
printf '.'
sleep ${TIMEOUT:=5}
done
printf '+'
sleep ${TIMEOUT:=5}
while ! [[ $(lxc-attach $1 -- cat /etc/inithooks.conf | wc -c) < 2 ]] ; do
printf '.'
sleep ${TIMEOUT:=5}
done
else
printf '.+..'
fi
printf 'ready.\n'
sleep ${TIMEOUT:=5}
}
#----------------------------------------------------------------------
#
# readConfig
@ -295,7 +342,6 @@ readConfig(){
fi
}
#
# saveConfig [-d|-a] CONFIG VAR ..
#
@ -331,7 +377,6 @@ saveConfig(){
} >> "$cfg"
}
saveLastRunConfig(){
local cfg=config.last-run
echo "# Saving config to: config.last-run"
@ -343,10 +388,7 @@ saveLastRunConfig(){
saveConfig -d -a "$cfg" ${XREAD_VARS[@]}
}
#
# webAppConfig NAME
#
webAppConfig(){
local name=${1^^}
eval "${name}_SUBDOMAIN=\${${name}_SUBDOMAIN:=\${DFL_SUB${name}_DOMAIN}}
@ -362,7 +404,6 @@ webAppConfig(){
DOMAIN=
}
#
# readVars
#
@ -448,99 +489,6 @@ readVars(){
}
#
# makeTemplateSEDPatterns VAR ...
#
makeTemplateSEDPatterns(){
local var
for var in "$@" ; do
local val=${!var}
if [[ $val == SKIP ]] ; then
val=
fi
echo "-e 's/\\\${${var}}/${val//\//\\/}/g'"
done
}
# same as makeTemplateSEDPatterns but adds default vars + generates *_IPn vars...
PCT_TEMPLATE_VARS=(
EMAIL
DOMAIN
CTHOSTNAME
GATE_HOSTNAME
NS_HOSTNAME
GATE_LAN_IP
GATE_ADMIN_IP
NS_LAN_IP
NS_ADMIN_IP
WAN_IP
WAN_GATE
LAN_IP
LAN_GATE
ADMIN_IP
ADMIN_GATE
)
makePCTTemplateSEDPatterns(){
# strip ips and save to *_IPn var...
local ip_vars=()
local var
local val
for var in ${PCT_TEMPLATE_VARS[@]} ; do
if [[ $var =~ .*_IP ]] ; then
local val=${!var}
if [[ $val == SKIP ]] ; then
val=
fi
ip_vars+=("${var}n")
eval "local ${var}n=\"${val/\/*}\""
fi
done
makeTemplateSEDPatterns "${PCT_TEMPLATE_VARS[@]}" "${ip_vars[@]}" "$@"
}
#
# expandTemplate PATH VAR ...
# .. | expandTemplate VAR ...
#
PCT_TEMPLATE_PATTERNS=
expandTemplate(){
if [ -t 0 ] ; then
local input=$1
shift
else
local input=/dev/stdin
fi
if [ -z "$PCT_TEMPLATE_PATTERNS" ] ; then
local patterns=($(makeTemplateSEDPatterns "$@"))
else
local patterns=("${PCT_TEMPLATE_PATTERNS[@]}")
fi
cat "${input}" \
| eval "sed ${patterns[@]}"
}
#
# expandTemplate PATH [VAR ...]
# .. | expandTemplate [VAR ...]
#
expandPCTTemplate(){
local input=
if [ -t 0 ] ; then
input=$1
shift
fi
local PCT_TEMPLATE_PATTERNS=($(makePCTTemplateSEDPatterns "$@"))
expandTemplate "${input}"
}
#
# buildAssets [VAR ..]
#
@ -549,21 +497,62 @@ NOTES=NOTES.md
buildAssets(){
local template_dir=${TEMPLATE_DIR:-templates}
local assets_dir=${ASSETS_DIR:-assets}
local staging_dir=${STAGING_DIR:-staging}
if ! [ -e $template_dir ] ; then
return
fi
local PCT_TEMPLATE_PATTERNS=($(makePCTTemplateSEDPatterns "$@"))
local PATTERNS=()
local DFL_VARS=(
EMAIL
DOMAIN
CTHOSTNAME
GATE_HOSTNAME
NS_HOSTNAME
GATE_LAN_IP
GATE_ADMIN_IP
NS_LAN_IP
NS_ADMIN_IP
WAN_IP
WAN_GATE
LAN_IP
LAN_GATE
ADMIN_IP
ADMIN_GATE
)
for var in ${DFL_VARS[@]} ; do
local val=${!var}
if [[ $val == SKIP ]] ; then
val=
fi
PATTERNS+=("-e 's/\\\${${var}}/${val//\//\\/}/g'")
done
local IP_VARS=(
GATE_LAN_IPn
GATE_ADMIN_IPn
NS_LAN_IPn
NS_ADMIN_IPn
WAN_IPn
LAN_IPn
ADMIN_IPn
)
for var in ${IP_VARS[@]} ; do
var=${var%n}
local val=${!var}
if [[ $val == SKIP ]] ; then
val=
fi
PATTERNS+=("-e 's/\\\${${var}n}/${val/\/*}/g'")
done
# args...
for var in $@ ; do
local val=${!var}
if [[ $val == SKIP ]] ; then
val=
fi
PATTERNS+=("-e 's/\\\${${var}}/${val//\//\\/}/g'")
done
# assets...
if [ -e "${assets_dir}" ] ; then
mkdir -p "${staging_dir}"
cp -R "${assets_dir}"/* "${staging_dir}"/
fi
# template dir...
local TEMPLATES=($(find "$template_dir" -type f))
for file in "${TEMPLATES[@]}" ; do
file=${file#${template_dir}}
@ -571,59 +560,20 @@ buildAssets(){
[ $DRY_RUN ] \
&& continue
# ensure the directory exists...
mkdir -p "$(dirname "${staging_dir}/${file}")"
mkdir -p "$(dirname "${assets_dir}/${file}")"
cat "${template_dir}/${file}" \
| expandTemplate \
> "${staging_dir}/${file}"
| eval "sed ${PATTERNS[@]}" \
> "${assets_dir}/${file}"
done
# special case: NOTES.md...
if [ -z "$DESCRIPTION" ] && [ -e "$NOTES" ] ; then
DESCRIPTION="$(\
cat ${NOTES} \
| expandTemplate)"
| eval "sed ${PATTERNS[@]}")"
fi
}
#----------------------------------------------------------------------
#
# pctPushAssets ID
#
pctPushAssets(){
@ pct-push-r $1 "${STAGING_DIR:-./staging}" /
}
#
# pveGetLatestTemplate PATTERN [VAR]
#
# see:
# https://pve.proxmox.com/wiki/Linux_Container
pveGetLatestTemplate(){
if [ $DRY_RUN ] ; then
[ -z $2 ] \
|| eval "$2=${CT_TEMPLATE:-\\\$CT_TEMPLATE}"
return
fi
#@ pveam update
local templates=($(pveam available | grep -o ''${1}'.*$'))
local latest=${templates[-1]}
@ pveam download local ${latest}
latest=$(pveam list local | grep -o "^.*$latest")
#latest=($(ls /var/lib/vz/template/cache/${1}*))
[ -z $2 ] \
|| eval "$2=${latest}"
}
#
# pctCreate ID TEMPLATE ARGS [PASS]
#
@ -648,7 +598,7 @@ pctCreate(){
#
pctCreateAlpine(){
local TEMPLATE
pveGetLatestTemplate alpine TEMPLATE
getLatestTemplate alpine TEMPLATE
pctCreate $1 "$TEMPLATE" "$2" "$3"
@ -659,7 +609,7 @@ pctCreateAlpine(){
}
pctCreateDebian(){
local TEMPLATE
pveGetLatestTemplate 'debian-12-standard' TEMPLATE
getLatestTemplate 'debian-12-standard' TEMPLATE
pctCreate $1 "$TEMPLATE" "$2" "$3"
@ -670,7 +620,7 @@ pctCreateDebian(){
}
pctCreateUbuntu(){
local TEMPLATE
pveGetLatestTemplate ubuntu TEMPLATE
getLatestTemplate ubuntu TEMPLATE
pctCreate $1 "$TEMPLATE" "$2" "$3"
@ -687,7 +637,7 @@ pctCreateTurnkey(){
local app=$1
shift
local TEMPLATE
pveGetLatestTemplate '.*-turnkey-'$app TEMPLATE
getLatestTemplate '.*-turnkey-'$app TEMPLATE
pctCreate $1 "$TEMPLATE" "$2" "$3"
@ -695,31 +645,6 @@ pctCreateTurnkey(){
sleep ${TIMEOUT:=5}
}
# Wait for /etc/inithooks.conf to be generated then cleared
#
# tklWaitForSetup ID
#
# for tkl inithooks doc see:
# https://www.turnkeylinux.org/docs/inithooks
tklWaitForSetup(){
printf "# TKL setup, this may take a while"
if [ -z $DRY_RUN ] ; then
while ! $(lxc-attach $1 -- test -e /etc/inithooks.conf) ; do
printf '.'
sleep ${TIMEOUT:=5}
done
printf '+'
sleep ${TIMEOUT:=5}
while ! [[ $(lxc-attach $1 -- cat /etc/inithooks.conf | wc -c) < 2 ]] ; do
printf '.'
sleep ${TIMEOUT:=5}
done
else
printf '.+..'
fi
printf 'ready.\n'
sleep ${TIMEOUT:=5}
}
#
# pctUpdateTurnkey ID
#
@ -760,13 +685,12 @@ pctSetNotes(){
if [ "$DRY_RUN" ] ; then
echo "--- ${CT_DIR}/${ID}.conf ---"
echo -e "${TEXT}"
echo "---"
echo "--- ${CT_DIR}/${ID}.conf ---"
else
echo -e "${TEXT}" > "${CT_DIR}/${ID}.conf"
fi
}
#----------------------------------------------------------------------
# vim:set ts=4 sw=4 nowrap :

View File

@ -9,9 +9,6 @@
#
#----------------------------------------------------------------------
EDITOR ?= vim
# 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
@ -103,12 +100,6 @@ all: minimal $(APP_CTs)
#----------------------------------------------------------------------
.PHONY: clean
clean:
-rm -rf */staging
#----------------------------------------------------------------------

View File

@ -111,11 +111,5 @@ sudo make all
```
## Post-setup
XXX test conections
XXX change proxmox ip/network

View File

@ -33,19 +33,18 @@ LAN_BRIDGE=
ADMIN_BRIDGE=
# NOTE: it is simpler to statically assign these than to configure dhcp
# plus port forewarding to the dynamically assigned IP.
DFL_WAN_IP=192.168.1.101/24
DFL_WAN_GATE=192.168.1.252
DFL_WAN_SSH_IP=192.168.1.102/24
DFL_WAN_SSH_IP:192.168.1.102/24
# Domain and email configuration
# Doman and email configuration
#
DOMAIN=example.com
EMAIL=user@example.com
DOMAIN=example.com
# Web app/service domain configuration
#

View File

@ -75,7 +75,7 @@ echo "# Installing dependencies..."
@ lxc-attach $ID apk add bash bridge iptables traefik logrotate
echo "# Copying assets..."
pctPushAssets $ID
@ pct-push-r $ID ./assets /
echo "# Setup: traefik..."
@ lxc-attach $ID rc-update add traefik

View File

@ -72,7 +72,7 @@ echo "# Starting TKL UI..."
@ lxc-attach $ID -- bash -c "HUB_APIKEY=SKIP SEC_UPDATES=SKIP /usr/sbin/turnkey-init"
echo "# Copying assets..."
pctPushAssets $ID
@ pct-push-r $ID ./assets /
echo "# Disabling fail2ban..."
# NOTE: we do not need this as we'll be running from behind a reverse proxy...

View File

@ -52,24 +52,13 @@ APP_DOMAIN=$DOMAIN
#----------------------------------------------------------------------
INTERFACES=(
"name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth"
)
# XXX move this to .pct-helpers
INTERFACES_ARGS=()
i=0
for interface in "${INTERFACES[@]}" ; do
INTERFACES_ARGS+=("--net${i} "${interface}"")
i=$(( i + 1 ))
done
# NOTE: TKL gui will not function correctly without nesting enabled...
OPTS_STAGE_1="\
--hostname $CTHOSTNAME \
--cores $CORES \
--memory $RAM \
--swap $SWAP \
"${INTERFACES_ARGS[@]}" \
--net0 name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth \
--storage local-lvm \
--rootfs local-lvm:$DRIVE \
--unprivileged 1 \
@ -145,8 +134,7 @@ done
@ lxc-attach $ID -- turnkey-occ maintenance:update:htaccess
echo "# Copying assets..."
pctPushAssets $ID
# XXX need to push proxy config to gate...
@ pct-push-r $ID ./assets /
echo "# Disabling fail2ban..."
# NOTE: we do not need this as we'll be running from behind a reverse proxy...

View File

@ -75,7 +75,7 @@ echo "# Installing dependencies..."
@ lxc-attach $ID apk add bash dnsmasq logrotate
echo "# Copying assets..."
pctPushAssets $ID
@ pct-push-r $ID ./assets /
echo "# Setup: dnsmasq..."
@ lxc-attach $ID rc-update add dnsmasq

View File

@ -60,9 +60,6 @@ OPTS_STAGE_2="\
#----------------------------------------------------------------------
echo "# Building config..."
buildAssets
echo "# Creating CT..."
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"

View File

@ -100,7 +100,7 @@ echo "# Installing dependencies..."
iptables wireguard-tools-wg-quick make bind-tools libqrencode logrotate
echo "# Copying assets..."
pctPushAssets $ID
@ pct-push-r $ID ./assets /
@ lxc-attach $ID -- chmod +x /root/getFreeClientIP
echo "# Setup: wireguard server and client profile..."