Alex A. Naanou 6279b1e6c2 refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2024-01-03 18:51:22 +03:00

105 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/bash
#----------------------------------------------------------------------
source ../.pct-helpers
PATH=$PATH:$(dirname "$(pwd)")
#----------------------------------------------------------------------
[ -e ../config.global ] \
&& source ../config.global
[ -e ./config ] \
&& source ./config
#----------------------------------------------------------------------
DFL_ID=${DFL_ID:=101}
DFL_CTHOSTNAME=${DFL_CTHOSTNAME:=gate}
DFL_WAN_IP=${DFL_WAN_IP:=192.168.1.101/24}
DFL_WAN_GATE=${DFL_WAN_GATE:=192.168.1.252}
# these can be:
# <empty>
# <IP>/<mask>
# dhcp
DFL_ADMIN_IP=${DFL_ADMIN_IP:=10.0.0.2/24}
ADMIN_GATE=-
DFL_LAN_IP=${DFL_LAN_IP:=10.1.1.2/24}
LAN_GATE=-
DFL_WAN_BRIDGE=${DFL_WAN_BRIDGE:=2}
DFL_LAN_BRIDGE=${DFL_LAN_BRIDGE:=0}
DFL_ADMIN_BRIDGE=${DFL_ADMIN_BRIDGE:=1}
REBOOT=${REBOOT:=1}
readVars
#----------------------------------------------------------------------
# XXX should we set the initial ip as 10.x.x.2/23, dhcp or empty???
# --net0 name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=10.1.1.2/24,type=veth \
# --net1 name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1,ip=10.0.0.2/24,type=veth \
OPTS_STAGE_1="\
--hostname $CTHOSTNAME \
--memory 128 \
--swap 128 \
--net0 name=wan,bridge=vmbr${WAN_BRIDGE},firewall=1${WAN_GATE:+,gw=${WAN_GATE}}${WAN_IP:+,ip=${WAN_IP}},type=veth \
--net1 name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1${ADMIN_IP:+,ip=${ADMIN_IP}},type=veth \
--net2 name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1${LAN_IP:+,ip=${LAN_IP}},type=veth \
--storage local-lvm \
--rootfs local-lvm:0.5 \
--unprivileged 1 \
${PCT_EXTRA} \
"
OPTS_STAGE_2="\
--startup order=80 \
--onboot 1 \
"
#----------------------------------------------------------------------
echo Building config...
buildAssets "$TEMPLATE_DIR" "$ASSETS_DIR"
echo Creating CT...
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
echo Updating container...
@ lxc-attach $ID apk update
@ lxc-attach $ID apk upgrade
echo Installing dependencies...
@ lxc-attach $ID apk add bash bridge iptables traefik
echo Copying assets...
@ pct-push-r $ID ./assets /
echo Setup: traefik...
@ lxc-attach $ID rc-update add traefik
@ lxc-attach $ID rc-service traefik start
echo Setup: iptables...
@ lxc-attach $ID rc-update add iptables
@ lxc-attach $ID bash /root/routing.sh
@ lxc-attach $ID rc-service iptables save
@ lxc-attach $ID rc-service iptables start
echo "Post config..."
pctSet $ID "${OPTS_STAGE_2}" $REBOOT
echo Done.
#----------------------------------------------------------------------
# vim:set ts=4 sw=4 :