bootstrap.sh (2031B)
1 #!/usr/bin/env bash 2 set -euxo pipefail 3 QEMU_URI=${QEMU_URI:-qemu+ssh://wakasu.home/system} 4 declare -A addrs=( ["ubnt1"]="30" ["ubnt2"]="31") 5 6 token="$(pwgen -1 32)" 7 8 bootstrap() { 9 machine=$1 10 virt-install --connect="${QEMU_URI}" \ 11 --name="${machine}" --vcpus=4 --ram=4192 \ 12 --disk path=/var/lib/libvirt/images/${machine}.qcow2,bus=virtio,size=120 \ 13 --network bridge=br1,mac.address=52:54:00:dd:a3:${addrs[${machine}]} \ 14 --os-variant ubuntu20.04 \ 15 --location 'http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/' \ 16 --initrd-inject ${machine}/preseed.cfg \ 17 --video=vga \ 18 --wait=-1 \ 19 --extra-args 'ks=file:/preseed.cfg /console=ttyS0,115200n8 serial' 20 # --graphics none \ 21 # --console pty,target_type=serial \ 22 # --extra-args 'ks=file:/preseed.cfg /console=ttyS0,115200n8 serial' 23 } 24 25 configure-ubnt1() { 26 ssh -o "StrictHostKeyChecking=no" -t vincent@192.168.1.130 sudo snap install microk8s --classic --channel=1.22 27 ssh -t root@192.168.1.130 microk8s status --wait-ready 28 ssh -t root@192.168.1.130 usermod -a -G microk8s vincent 29 ssh -t root@192.168.1.130 microk8s enable dns ingress storage registry rbac 30 ssh -t root@192.168.1.130 mkdir -p /root/.kube 31 # ssh -t root@192.168.1.130 microk8s config > /root/.kube/config.microk8s 32 # FIXME: Parse the output to get the full url to join 33 ssh -t root@192.168.1.130 microk8s add-node --token-ttl=-1 --token=${token} 34 } 35 36 configure-ubnt2() { 37 ssh -o "StrictHostKeyChecking=no" -t root@192.168.1.131 sudo snap install microk8s --classic --channel=1.22 38 ssh -t root@192.168.1.130 microk8s status --wait-ready 39 ssh -t root@192.168.1.130 usermod -a -G microk8s vincent 40 ssh -t root@192.168.1.131 microk8s join 192.168.1.130:250000/${token} 41 } 42 43 for m in ubnt*; do 44 set +e 45 virsh --connect="${QEMU_URI}" list | grep $m 46 if [[ $? -gt 0 ]]; then 47 set -e 48 bootstrap $m 49 echo "bootstrap machine $m" 50 sleep 60 51 configure-$m 52 fi 53 done