#!/bin/bash CTHOSTNAME=$1 CTPASS=$2 USER=$3 echo Creating $CTHOSTNAME ... # Find last CT and get its ID LASTID=$(pct list | cut -d" " -f1 | tail -1) if [[ -z "$CTHOSTNAME" ]]; then echo "CT hostname not set" exit 1 fi if [[ -z "$CTPASS" ]]; then echo "CT password not set" exit 1 fi if [[ -z "$USER" ]]; then echo "USER not set" exit 1 fi if [[ -z "$LASTID" ]]; then LASTID=99 fi NEWID=$(($LASTID + 1)) echo ID of new CT is: $NEWID ## Find the biggest free IP for i in $(seq $((NEWID + 101)) 254); do ping -W 3 -c 3 192.168.1.$i || break; done CTIP="192.168.1.$i" pct create $NEWID local:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst --arch amd64 --cores 2 --features nesting=1 --hostname $CTHOSTNAME --memory 2048 --net0 name=eth0,bridge=vmbr0,firewall=1,gw=192.168.1.1,gw6=2001:470:1f1a:1a4::5,ip=$CTIP/24,ip6=2001:470:1f1a:1a4::$(printf '%x' $((NEWID - 87)))/96,type=veth --onboot 1 --ostype debian --swap 1024 --unprivileged 1 --storage local-lvm --ssh-public-keys /root/.ssh/fram3d.pub --password $CTPASS pct set $NEWID --rootfs local-lvm:vm-$NEWID-disk-0,size=32G pct start $NEWID echo "Creds:" echo "root@$CTIP" echo "root@2001:470:1f1a:1a4::$(printf '%x' $((NEWID - 87)))" echo $CTPASS