86 lines
2.0 KiB
Bash
86 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
# Default values
|
|
STORAGE="local"
|
|
BRIDGE="vmbr0"
|
|
IP=""
|
|
VLAN=""
|
|
|
|
# Parse arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--storage)
|
|
STORAGE="$2"
|
|
shift 2
|
|
;;
|
|
--bridge)
|
|
BRIDGE="$2"
|
|
shift 2
|
|
;;
|
|
--ip)
|
|
IP="$2"
|
|
shift 2
|
|
;;
|
|
--vlan)
|
|
VLAN="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
echo "Unknown argument: $1"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Generate CTID
|
|
CTID=$(( $(date +%s) - 1000000000 ))
|
|
echo "Generated CTID: $CTID"
|
|
|
|
# Update and download Debian 12 template
|
|
echo "Updating and downloading Debian 12 template..."
|
|
pveam update
|
|
pveam download local debian-12-standard_12.0-1_amd64.tar.zst
|
|
|
|
# Create LXC container
|
|
echo "Creating LXC container..."
|
|
if [ -n "$VLAN" ]; then
|
|
pct create "$CTID" local:template/debian-12-standard_12.0-1_amd64.tar.zst \
|
|
--hostname "customer-$CTID" \
|
|
--memory 2048 \
|
|
--cores 2 \
|
|
--net0 name=eth0,bridge="$BRIDGE",tag="$VLAN" \
|
|
--unprivileged 1 \
|
|
--features nesting=1 \
|
|
--storage "$STORAGE"
|
|
else
|
|
pct create "$CTID" local:template/debian-12-standard_12.0-1_amd64.tar.zst \
|
|
--hostname "customer-$CTID" \
|
|
--memory 2048 \
|
|
--cores 2 \
|
|
--net0 name=eth0,bridge="$BRIDGE" \
|
|
--unprivileged 1 \
|
|
--features nesting=1 \
|
|
--storage "$STORAGE"
|
|
fi
|
|
|
|
# Configure APT proxy
|
|
echo "Configuring APT proxy..."
|
|
pct exec "$CTID" -- mkdir -p /etc/apt/apt.conf.d
|
|
pct exec "$CTID" -- bash -c 'echo "Acquire::http::Proxy \"http://192.168.45.2:3142\";" > /etc/apt/apt.conf.d/01proxy'
|
|
|
|
# Copy setup scripts
|
|
echo "Copying setup scripts..."
|
|
pct push "$CTID" ./setupowner.sh /root/setupowner.sh
|
|
pct push "$CTID" ./templates/docker-compose.yml /root/docker-compose.yml
|
|
|
|
# Start container
|
|
echo "Starting container..."
|
|
pct start "$CTID"
|
|
|
|
# Execute setup script
|
|
echo "Executing setup script..."
|
|
pct exec "$CTID" -- /root/setupowner.sh
|
|
|
|
echo "Installation completed for CTID: $CTID" |