#!/bin/bash usage() { local code="${1:-0}" cat < to specify one manually." exit 1 fi else echo "Using network interface: $INTERFACE" fi # --- resize partition --- echo "Expanding partition and resizing filesystem..." growpart /dev/vda 1 resize2fs /dev/vda1 df -h if ! confirm "Continue with network configuration?"; then echo "Exiting." exit 1 fi # --- generate Netplan config --- NETPLAN_CONFIG="/etc/netplan/01-network-config.yaml" echo "Creating Netplan configuration at $NETPLAN_CONFIG..." cat < $NETPLAN_CONFIG network: version: 2 renderer: networkd ethernets: $INTERFACE: dhcp4: false dhcp6: false addresses: EOF [[ -n "$IPv4_VM" ]] && echo " - $IPv4_VM/24" >> $NETPLAN_CONFIG [[ -n "$IPv6_VM" ]] && echo " - $IPv6_VM/64" >> $NETPLAN_CONFIG if [[ -n "$IPv4_GATEWAY_HOST_SERVER" || -n "$IPv6_GATEWAY_HOST_SERVER" ]]; then echo " routes:" >> $NETPLAN_CONFIG if [[ -n "$IPv4_GATEWAY_HOST_SERVER" ]]; then echo " - to: default" >> $NETPLAN_CONFIG echo " via: $IPv4_GATEWAY_HOST_SERVER" >> $NETPLAN_CONFIG fi if [[ -n "$IPv6_GATEWAY_HOST_SERVER" ]]; then echo " - to: default" >> $NETPLAN_CONFIG echo " via: $IPv6_GATEWAY_HOST_SERVER" >> $NETPLAN_CONFIG fi fi cat <> $NETPLAN_CONFIG nameservers: addresses: - 1.1.1.1 # Cloudflare IPv4 DNS - 8.8.8.8 # Google IPv4 DNS - 2606:4700:4700::1111 # Cloudflare IPv6 DNS - 2001:4860:4860::8888 # Google IPv6 DNS EOF chmod 600 $NETPLAN_CONFIG netplan generate if ! confirm "Apply Netplan changes?"; then echo "Exiting." exit 1 fi netplan --debug apply ip -4 a ip -6 a ip -4 r ip -6 r echo "Testing IPv4 connectivity for 10 seconds..." timeout 10 ping -4 google.com echo "Testing IPv6 connectivity for 10 seconds..." timeout 10 ping -6 google.com if confirm "Proceed with system update and upgrade?"; then apt update && apt upgrade -y else echo "Skipping updates." fi # --- SSH setup --- echo "Generating SSH host keys..." ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N "" ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N "" ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" systemctl restart ssh.service mkdir -p ~/.ssh echo "# Add your admin SSH keys here, save and exit!" > ~/.ssh/authorized_keys nano ~/.ssh/authorized_keys echo "Setup complete! Try to ping and ssh from the outside before killing this console"