--- /dev/null
+#!/usr/bin/expect -f
+# create a Debian/Ubuntu development VM based on a standard autopkgtest VM
+
+set timeout -1
+
+set prompt "(%|#|\\$) $"
+set sshkey [read [open ".ssh/id_rsa.pub"]]
+
+# Start the guest VM
+set img [lrange $argv 0 0]
+if { $img == "" } { set img "/srv/vm/autopkgtest-sid.img" }
+spawn vm $img -nographic -snapshot -virtfs local,id=srv,path=/srv,security_model=none,mount_tag=srv,readonly \
+ -virtfs local,id=etcschroot,path=/etc/schroot,security_model=none,mount_tag=etcschroot,readonly
+
+# Login, and get root shell
+expect {
+ # autopkgtest Debian machine only has a root login
+ "Debian GNU" { set user "root"; set sudo ""; set getroot "" }
+ "Ubuntu" { set user "ubuntu"; set password "ubuntu"; set getroot "sudo -n -i" }
+}
+
+expect "login: "
+send "$user\r"
+
+expect {
+ "Password" { send "$password\r"; exp_continue }
+ -re $prompt
+}
+
+send "export TERM=xterm; $getroot\r"
+expect -re $prompt
+
+# install wanted packages
+send "apt-get install -o Dpkg::Options::=--force-confnew -y sudo less bash-completion vim openssh-server locales git-buildpackage build-essential fakeroot lintian debhelper manpages-dev git dput pristine-tar schroot sbuild </dev/null\r"
+expect -re $prompt
+
+# set up user
+send "deluser --remove-home test; adduser --disabled-password --gecos 'Martin Pitt' martin; echo 'martin:a' | chpasswd; adduser martin sbuild\r"
+expect -re $prompt
+
+send "echo 'martin ALL=(ALL) NOPASSWD:ALL' | tee /etc/sudoers.d/martin; update-locale LANG=C.UTF-8; touch /var/lib/sudo/lectured/martin\r"
+expect -re $prompt
+send "mkdir /home/martin/.ssh; echo '$sshkey' | tee /home/martin/.ssh/authorized_keys; chown -R martin:martin /home/martin/.ssh\r"
+expect -re $prompt
+
+# mount home, /srv, and schroot config from host; TODO: move to NFS?
+send "mkdir /home/martin/h; printf 'home /home/martin/h 9p trans=virtio,access=any,nofail,ro 0 0\nsrv /srv 9p trans=virtio,access=any,nofail,ro 0 0\netcschroot /etc/schroot 9p trans=virtio,access=any,nofail,ro 0 0\n' | tee -a /etc/fstab; mount /home/martin/h; mount /srv; mount /etc/schroot\r"
+expect -re $prompt
+send "(cd /home/martin; ln -s h/.gbp.conf; ln -s h/.vimrc)\r"
+
+# set up lxd if available (on Ubuntu)
+# FIXME: lxd init invocation aborts expect/qemu
+#send "apt-get install -y lxd </dev/null && adduser martin lxd && yes '' | lxd init || true\r"
+send "apt-get install -y lxd </dev/null && adduser martin lxd || true\r"
+expect -re $prompt
+
+interact