#!/usr/bin/expect -f # An IPv6-only-compatible automation routine around `setup-alpine` for building alpine vms # Replace `user=memdmp` with `user=` # Replace `[SSHKEY]` with the desired SSH key # Replace `/tmp/vm.iso` with the Alpine ISO # Replace `/tmp/target.qcow2` with the desired qcow2 image to install on # Replace `-m 8G` with the amount of memory to provide the VM # After setup, change the disk encryption password (will be set to `pass`) via `cryptsetup luksAddKey /dev/sdb3` followed by `crypsetup luksRemoveKey /dev/sdb3` spawn qemu-system-x86_64 -smp 8 -run-with user=memdmp -drive file=/tmp/vm.iso,format=raw,index=0,media=disk -drive file=/tmp/target.qcow2,format=qcow2,index=1,media=disk -serial stdio -display none -m 8G set timeout 240 expect "login: " send "root\n" set timeout 30 expect "You may change this message by editing /etc/motd." sleep 1 send "PS1=@@\n" expect "\n@@" send "echo 'Hi!' > /etc/motd\n" expect "\n@@" send "setup-alpine\n" expect "Enter system hostname" sleep 0.1 send "replaceme.vms.crunchy.estrogen.zone\n" expect "eth0" sleep 0.1 send "\n" expect "Ip address for eth0?" send "none\n" expect "manual" send "y\n" sleep 1 send ":" sleep 0.1 send ":%s/inet manual/inet6 auto/" sleep 0.1 send "\n" sleep 0.3 send ":wq\n" expect "DNS domain name" send "\n" expect "DNS nameserver" send "2620:fe::fe 2620:fe::9 9.9.9.9 149.112.112.112\n" expect "New password: " send "\n" sleep 0.1 send "\n" expect "Which timezone are you in?" sleep 0.1 send "Europe/Zurich\n" expect "HTTP/FTP proxy URL?" sleep 0.1 send "\n" expect "Which NTP client to run?" sleep 0.1 send "chrony\n" expect "Enter mirror number or URL:" sleep 0.1 send "e\n" sleep 1 send ":ggdG\n" sleep 1 send "i" sleep 1 send "https://mirror.init7.net/alpinelinux/latest-stable/main\nhttps://mirror.init7.net/alpinelinux/latest-stable/community\n@edge https://mirror.init7.net/alpinelinux/edge/main\n@edge https://mirror.init7.net/alpinelinux/edge/community\n@testing https://mirror.init7.net/alpinelinux/edge/testing\n# " sleep 1 send "\x1b" sleep 1 send ":wq\n" expect "Setup a user?" send "lain\n" expect "Full name for user lain" send "Lain\n" expect "New password: " send "\n" expect "Retype password: " send "\n" expect "Enter ssh key or URL for lain" send "[SSHKEY]\n" expect "Which ssh server?" send "\n" expect "Which disk(s) would you like to use?" send "sdb\n" expect "How would you like to use it?" send "cryptsys\n" expect "WARNING: Erase the above disk(s) and continue?" sleep 0.1 send "y\n" expect "Enter passphrase for" sleep 0.1 send "pass\n" expect "Verify passphrase" sleep 0.1 send "pass\n" expect "Enter passphrase for" sleep 0.1 send "pass\n" set timeout 600 expect "\n@@" sleep 0.1 send "sed -i 's/default_kernel_opts=\"/default_kernel_opts=\"console=ttyS0,9600 /' /etc/update-extlinux.conf\n" expect "\n@@" send "update-extlinux\n" expect "\n@@" send "poweroff\n" expect eof