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
bfed076867
commit
d58b384e0a
76
.pct-helpers
76
.pct-helpers
@ -544,7 +544,6 @@ expandPCTTemplate(){
|
|||||||
#
|
#
|
||||||
# buildAssets [VAR ..]
|
# buildAssets [VAR ..]
|
||||||
#
|
#
|
||||||
# XXX revise: SKIP handling...
|
|
||||||
NOTES=NOTES.md
|
NOTES=NOTES.md
|
||||||
buildAssets(){
|
buildAssets(){
|
||||||
local template_dir=${TEMPLATE_DIR:-templates}
|
local template_dir=${TEMPLATE_DIR:-templates}
|
||||||
@ -623,32 +622,77 @@ pveGetLatestTemplate(){
|
|||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# pctCreate ID TEMPLATE ARGS [PASS]
|
# pctBaseCreate ID TEMPLATE ARGS [PASS]
|
||||||
#
|
#
|
||||||
pctCreate(){
|
pctBaseCreate(){
|
||||||
|
local ID=$1
|
||||||
|
local TEMPLATE=$2
|
||||||
|
local ARGS=$3
|
||||||
|
local PASS=$4
|
||||||
|
|
||||||
local TMP_PASS=$(cat /dev/urandom | base64 | head -c ${TMP_PASS_LEN:=32})
|
local TMP_PASS=$(cat /dev/urandom | base64 | head -c ${TMP_PASS_LEN:=32})
|
||||||
# NOTE: we are not setting the password here to avoid printing it to the terminal...
|
# NOTE: we are not setting the password here to avoid printing it to the terminal...
|
||||||
@ pct create $1 \
|
@ pct create $ID \
|
||||||
${2} \
|
"${TEMPLATE}" \
|
||||||
${3} \
|
${ARGS} \
|
||||||
--password="$TMP_PASS" \
|
--password="$TMP_PASS" \
|
||||||
--start 1 \
|
--start 1 \
|
||||||
|| exit 1
|
|| exit 1
|
||||||
|
|
||||||
# set actual root password...
|
# set actual root password...
|
||||||
if [ "$4" ] ; then
|
if [ "$PASS" ] ; then
|
||||||
echo "root:$4" \
|
echo "root:$PASS" \
|
||||||
| @ lxc-attach $1 chpasswd
|
| @ lxc-attach $ID chpasswd
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# pctCreate<distro> ID ARGS [PASS]
|
# pctCreate ID TEMPLATE [PASS]
|
||||||
|
#
|
||||||
|
#OPTS_STAGE_1=
|
||||||
|
#INTERFACES=
|
||||||
|
#CTHOSTNAME=
|
||||||
|
#CORES=
|
||||||
|
#RAM=
|
||||||
|
#SWAP=
|
||||||
|
#DRIVE=
|
||||||
|
#PCT_EXTRA=
|
||||||
|
# XXX
|
||||||
|
pctCreate(){
|
||||||
|
# build network args...
|
||||||
|
local interfaces_args=()
|
||||||
|
local i=0
|
||||||
|
local interface
|
||||||
|
for interface in "${INTERFACES[@]}" ; do
|
||||||
|
interfaces_args+=("--net${i} "${interface}"")
|
||||||
|
i=$(( i + 1 ))
|
||||||
|
done
|
||||||
|
|
||||||
|
# NOTE: TKL gui will not function correctly without nesting enabled...
|
||||||
|
local args="\
|
||||||
|
--hostname $CTHOSTNAME \
|
||||||
|
--cores $CORES \
|
||||||
|
--memory $RAM \
|
||||||
|
--swap $SWAP \
|
||||||
|
"${interfaces_args[@]}" \
|
||||||
|
--storage local-lvm \
|
||||||
|
--rootfs local-lvm:$DRIVE \
|
||||||
|
--unprivileged 1 \
|
||||||
|
--features nesting=1 \
|
||||||
|
${PCT_EXTRA} \
|
||||||
|
"
|
||||||
|
|
||||||
|
pctBaseCreate "$1" "$2" "${OPTS_STAGE_1:-"${args}"}" "$3"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# pctCreate<distro> ID [PASS]
|
||||||
#
|
#
|
||||||
pctCreateAlpine(){
|
pctCreateAlpine(){
|
||||||
local TEMPLATE
|
local TEMPLATE
|
||||||
pveGetLatestTemplate alpine TEMPLATE
|
pveGetLatestTemplate alpine TEMPLATE
|
||||||
|
|
||||||
pctCreate $1 "$TEMPLATE" "$2" "$3"
|
pctCreate $1 "$TEMPLATE" "$2"
|
||||||
|
|
||||||
sleep ${TIMEOUT:=5}
|
sleep ${TIMEOUT:=5}
|
||||||
|
|
||||||
@ -659,7 +703,7 @@ pctCreateDebian(){
|
|||||||
local TEMPLATE
|
local TEMPLATE
|
||||||
pveGetLatestTemplate 'debian-12-standard' TEMPLATE
|
pveGetLatestTemplate 'debian-12-standard' TEMPLATE
|
||||||
|
|
||||||
pctCreate $1 "$TEMPLATE" "$2" "$3"
|
pctCreate $1 "$TEMPLATE" "$2"
|
||||||
|
|
||||||
sleep ${TIMEOUT:=5}
|
sleep ${TIMEOUT:=5}
|
||||||
|
|
||||||
@ -670,7 +714,7 @@ pctCreateUbuntu(){
|
|||||||
local TEMPLATE
|
local TEMPLATE
|
||||||
pveGetLatestTemplate ubuntu TEMPLATE
|
pveGetLatestTemplate ubuntu TEMPLATE
|
||||||
|
|
||||||
pctCreate $1 "$TEMPLATE" "$2" "$3"
|
pctCreate $1 "$TEMPLATE" "$2"
|
||||||
|
|
||||||
sleep ${TIMEOUT:=5}
|
sleep ${TIMEOUT:=5}
|
||||||
|
|
||||||
@ -679,7 +723,7 @@ pctCreateUbuntu(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# pctCreateTurnkey APP ID ARGS [PASS]
|
# pctCreateTurnkey APP ID [PASS]
|
||||||
#
|
#
|
||||||
pctCreateTurnkey(){
|
pctCreateTurnkey(){
|
||||||
local app=$1
|
local app=$1
|
||||||
@ -687,12 +731,13 @@ pctCreateTurnkey(){
|
|||||||
local TEMPLATE
|
local TEMPLATE
|
||||||
pveGetLatestTemplate '.*-turnkey-'$app TEMPLATE
|
pveGetLatestTemplate '.*-turnkey-'$app TEMPLATE
|
||||||
|
|
||||||
pctCreate $1 "$TEMPLATE" "$2" "$3"
|
pctCreate $1 "$TEMPLATE" "$2"
|
||||||
|
|
||||||
tklWaitForSetup $1
|
tklWaitForSetup $1
|
||||||
|
|
||||||
sleep ${TIMEOUT:=5}
|
sleep ${TIMEOUT:=5}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Wait for /etc/inithooks.conf to be generated then cleared
|
# Wait for /etc/inithooks.conf to be generated then cleared
|
||||||
#
|
#
|
||||||
# tklWaitForSetup ID
|
# tklWaitForSetup ID
|
||||||
@ -718,6 +763,7 @@ tklWaitForSetup(){
|
|||||||
printf 'ready.\n'
|
printf 'ready.\n'
|
||||||
sleep ${TIMEOUT:=5}
|
sleep ${TIMEOUT:=5}
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# pctUpdateTurnkey ID
|
# pctUpdateTurnkey ID
|
||||||
#
|
#
|
||||||
|
|||||||
@ -42,20 +42,11 @@ readVars
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
OPTS_STAGE_1="\
|
INTERFACES=(
|
||||||
--hostname $CTHOSTNAME \
|
"name=wan,bridge=vmbr${WAN_BRIDGE},firewall=1${WAN_GATE:+,gw=${WAN_GATE}}${WAN_IP:+,ip=${WAN_IP}},type=veth"
|
||||||
--cores $CORES \
|
"name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1${ADMIN_IP:+,ip=${ADMIN_IP}},type=veth"
|
||||||
--memory $RAM \
|
"name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1${LAN_IP:+,ip=${LAN_IP}},type=veth"
|
||||||
--swap $SWAP \
|
)
|
||||||
--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:$DRIVE \
|
|
||||||
--unprivileged 1 \
|
|
||||||
--features nesting=1 \
|
|
||||||
${PCT_EXTRA} \
|
|
||||||
"
|
|
||||||
|
|
||||||
OPTS_STAGE_2="\
|
OPTS_STAGE_2="\
|
||||||
--startup order=80 \
|
--startup order=80 \
|
||||||
@ -69,7 +60,7 @@ echo "# Building config..."
|
|||||||
buildAssets
|
buildAssets
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
|
pctCreateAlpine $ID "$PASS"
|
||||||
|
|
||||||
echo "# Installing dependencies..."
|
echo "# Installing dependencies..."
|
||||||
@ lxc-attach $ID apk add bash bridge iptables traefik logrotate
|
@ lxc-attach $ID apk add bash bridge iptables traefik logrotate
|
||||||
|
|||||||
@ -41,19 +41,9 @@ readVars
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
# NOTE: TKL gui will not function correctly without nesting enabled...
|
INTERFACES=(
|
||||||
OPTS_STAGE_1="\
|
"name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth"
|
||||||
--hostname $CTHOSTNAME \
|
)
|
||||||
--cores $CORES \
|
|
||||||
--memory $RAM \
|
|
||||||
--swap $SWAP \
|
|
||||||
--net0 name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth \
|
|
||||||
--storage local-lvm \
|
|
||||||
--rootfs local-lvm:$DRIVE \
|
|
||||||
--unprivileged 1 \
|
|
||||||
--features nesting=1 \
|
|
||||||
${PCT_EXTRA} \
|
|
||||||
"
|
|
||||||
|
|
||||||
OPTS_STAGE_2="\
|
OPTS_STAGE_2="\
|
||||||
--onboot 1 \
|
--onboot 1 \
|
||||||
@ -66,7 +56,7 @@ echo "# Building config..."
|
|||||||
buildAssets
|
buildAssets
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
pctCreateTurnkey 'gitea' $ID "$OPTS_STAGE_1" "$PASS"
|
pctCreateTurnkey 'gitea' $ID "$PASS"
|
||||||
|
|
||||||
echo "# Starting TKL UI..."
|
echo "# Starting TKL UI..."
|
||||||
@ lxc-attach $ID -- bash -c "HUB_APIKEY=SKIP SEC_UPDATES=SKIP /usr/sbin/turnkey-init"
|
@ lxc-attach $ID -- bash -c "HUB_APIKEY=SKIP SEC_UPDATES=SKIP /usr/sbin/turnkey-init"
|
||||||
|
|||||||
@ -56,27 +56,6 @@ INTERFACES=(
|
|||||||
"name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth"
|
"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[@]}" \
|
|
||||||
--storage local-lvm \
|
|
||||||
--rootfs local-lvm:$DRIVE \
|
|
||||||
--unprivileged 1 \
|
|
||||||
--features nesting=1 \
|
|
||||||
${PCT_EXTRA} \
|
|
||||||
"
|
|
||||||
|
|
||||||
OPTS_STAGE_2="\
|
OPTS_STAGE_2="\
|
||||||
--onboot 1 \
|
--onboot 1 \
|
||||||
"
|
"
|
||||||
@ -88,7 +67,7 @@ echo "# Building config..."
|
|||||||
buildAssets
|
buildAssets
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
pctCreateTurnkey 'nextcloud' $ID "$OPTS_STAGE_1" "$PASS"
|
pctCreateTurnkey 'nextcloud' $ID "$PASS"
|
||||||
|
|
||||||
echo "# Starting TKL UI..."
|
echo "# Starting TKL UI..."
|
||||||
# XXX might be a good idea to reaaad stuff from config...
|
# XXX might be a good idea to reaaad stuff from config...
|
||||||
|
|||||||
19
ns/make.sh
19
ns/make.sh
@ -43,19 +43,10 @@ readVars
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
OPTS_STAGE_1="\
|
INTERFACES=(
|
||||||
--hostname $CTHOSTNAME \
|
"name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1${LAN_GATE:+,gw=$LAN_GATE}${LAN_IP:+,ip=$LAN_IP},type=veth"
|
||||||
--cores $CORES \
|
"name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1${ADMIN_IP:+,ip=$ADMIN_IP},type=veth"
|
||||||
--memory $RAM \
|
)
|
||||||
--swap $SWAP \
|
|
||||||
--net0 name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1${LAN_GATE:+,gw=$LAN_GATE}${LAN_IP:+,ip=$LAN_IP},type=veth \
|
|
||||||
--net1 name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1${ADMIN_IP:+,ip=$ADMIN_IP},type=veth \
|
|
||||||
--storage local-lvm \
|
|
||||||
--rootfs local-lvm:$DRIVE \
|
|
||||||
--unprivileged 1 \
|
|
||||||
--features nesting=1 \
|
|
||||||
${PCT_EXTRA} \
|
|
||||||
"
|
|
||||||
|
|
||||||
OPTS_STAGE_2="\
|
OPTS_STAGE_2="\
|
||||||
--startup order=90,up=10 \
|
--startup order=90,up=10 \
|
||||||
@ -69,7 +60,7 @@ echo "# Building config..."
|
|||||||
buildAssets
|
buildAssets
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
|
pctCreateAlpine $ID "$PASS"
|
||||||
|
|
||||||
echo "# Installing dependencies..."
|
echo "# Installing dependencies..."
|
||||||
@ lxc-attach $ID apk add bash dnsmasq logrotate
|
@ lxc-attach $ID apk add bash dnsmasq logrotate
|
||||||
|
|||||||
21
ssh/make.sh
21
ssh/make.sh
@ -43,20 +43,11 @@ readVars
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
OPTS_STAGE_1="\
|
INTERFACES=(
|
||||||
--hostname $CTHOSTNAME \
|
"name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth"
|
||||||
--cores $CORES \
|
"name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1,ip=dhcp,type=veth"
|
||||||
--memory $RAM \
|
"name=wan,bridge=vmbr${WAN_BRIDGE},firewall=1${WAN_SSH_IP:+,ip=${WAN_SSH_IP}},type=veth"
|
||||||
--swap $SWAP \
|
)
|
||||||
--net0 name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth \
|
|
||||||
--net1 name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1,ip=dhcp,type=veth \
|
|
||||||
--net2 name=wan,bridge=vmbr${WAN_BRIDGE},firewall=1${WAN_SSH_IP:+,ip=${WAN_SSH_IP}},type=veth \
|
|
||||||
--storage local-lvm \
|
|
||||||
--rootfs local-lvm:$DRIVE \
|
|
||||||
--unprivileged 1 \
|
|
||||||
--features nesting=1 \
|
|
||||||
${PCT_EXTRA} \
|
|
||||||
"
|
|
||||||
|
|
||||||
OPTS_STAGE_2="\
|
OPTS_STAGE_2="\
|
||||||
--onboot 1 \
|
--onboot 1 \
|
||||||
@ -66,7 +57,7 @@ OPTS_STAGE_2="\
|
|||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
pctCreateDebian $ID "${OPTS_STAGE_1}" "$PASS"
|
pctCreateDebian $ID "$PASS"
|
||||||
|
|
||||||
echo "# Installing dependencies..."
|
echo "# Installing dependencies..."
|
||||||
@ lxc-attach $ID -- bash -c 'yes | apt install vim htop iftop iotop tmux mc sudo'
|
@ lxc-attach $ID -- bash -c 'yes | apt install vim htop iftop iotop tmux mc sudo'
|
||||||
|
|||||||
@ -39,19 +39,10 @@ readVars
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
OPTS_STAGE_1="\
|
INTERFACES=(
|
||||||
--hostname $CTHOSTNAME \
|
"name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth"
|
||||||
--cores $CORES \
|
"name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1,ip=dhcp,type=veth"
|
||||||
--memory $RAM \
|
)
|
||||||
--swap $SWAP \
|
|
||||||
--net0 name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth \
|
|
||||||
--net1 name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1,ip=dhcp,type=veth \
|
|
||||||
--storage local-lvm \
|
|
||||||
--rootfs local-lvm:$DRIVE \
|
|
||||||
--unprivileged 1 \
|
|
||||||
--features nesting=1 \
|
|
||||||
${PCT_EXTRA} \
|
|
||||||
"
|
|
||||||
|
|
||||||
OPTS_STAGE_2="\
|
OPTS_STAGE_2="\
|
||||||
--onboot 1 \
|
--onboot 1 \
|
||||||
@ -64,7 +55,7 @@ echo "# Building config..."
|
|||||||
buildAssets
|
buildAssets
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
|
pctCreateAlpine $ID "$PASS"
|
||||||
|
|
||||||
echo "# Copying assets..."
|
echo "# Copying assets..."
|
||||||
pctPushAssets $ID
|
pctPushAssets $ID
|
||||||
|
|||||||
@ -68,19 +68,11 @@ readVars
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
OPTS_STAGE_1="\
|
INTERFACES=(
|
||||||
--hostname $CTHOSTNAME \
|
"name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth"
|
||||||
--cores $CORES \
|
"name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1,ip=dhcp,type=veth"
|
||||||
--memory $RAM \
|
)
|
||||||
--swap $SWAP \
|
|
||||||
--net0 name=lan,bridge=vmbr${LAN_BRIDGE},firewall=1,ip=dhcp,type=veth \
|
|
||||||
--net1 name=admin,bridge=vmbr${ADMIN_BRIDGE},firewall=1,ip=dhcp,type=veth \
|
|
||||||
--storage local-lvm \
|
|
||||||
--rootfs local-lvm:$DRIVE \
|
|
||||||
--unprivileged 1 \
|
|
||||||
--features nesting=1 \
|
|
||||||
${PCT_EXTRA} \
|
|
||||||
"
|
|
||||||
|
|
||||||
OPTS_STAGE_2="\
|
OPTS_STAGE_2="\
|
||||||
--onboot 1 \
|
--onboot 1 \
|
||||||
@ -93,7 +85,7 @@ echo "# Building config..."
|
|||||||
buildAssets ENDPOINT ENDPOINT_PORT DNS CLIENT_IPS ALLOWED_IPS
|
buildAssets ENDPOINT ENDPOINT_PORT DNS CLIENT_IPS ALLOWED_IPS
|
||||||
|
|
||||||
echo "# Creating CT..."
|
echo "# Creating CT..."
|
||||||
pctCreateAlpine $ID "${OPTS_STAGE_1}" "$PASS"
|
pctCreateAlpine $ID "$PASS"
|
||||||
|
|
||||||
echo "# Installing dependencies..."
|
echo "# Installing dependencies..."
|
||||||
@ lxc-attach $ID apk add \
|
@ lxc-attach $ID apk add \
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user