#!/usr/bin/expect -f

# Wait enough (forever) until a long-time boot
set timeout -1

spawn qemu-system-x86_64 \
    -hda bionic-server-cloudimg-amd64.img \
    -cpu qemu64,+ssse3,+sse4.1,+sse4.2,+popcnt -smp 8 \
    -net nic -net user,hostfwd=tcp::11022-:22 \
    -m 4096 -nographic

expect "login: "
send "root\n"

expect "Password: "
send "root\n"

# Without it ssh is not working on guest machine for some reason
expect "# "
send "dhclient && ssh-keygen -A && systemctl restart sshd.service\n"

# Wait forever
expect "########"