]> piware.de Git - bin.git/blob - vmdebdev
debdev: gnupg2 is obsolete transitional package, move to gnupg
[bin.git] / vmdebdev
1 #!/usr/bin/expect -f
2 # create a Debian/Ubuntu development VM based on a standard autopkgtest VM
3
4 set timeout -1
5
6 set prompt "(%|#|\\$) $"
7 set sshkey [read [open "~/.ssh/id_rsa.pub"]]
8 set timeout 60
9
10 # Start the guest VM
11 set img [lrange $argv 0 0]
12 if { $img == "" } { set img "/srv/vm/autopkgtest-sid.img" }
13 spawn vm $img -nographic -snapshot -cpu host -smp 3 \
14               -virtfs local,id=srv,path=/srv,security_model=none,mount_tag=srv,readonly \
15               -virtfs local,id=etcschroot,path=/etc/schroot,security_model=none,mount_tag=etcschroot,readonly
16
17 # Login, and get root shell
18 expect {
19     # autopkgtest Debian machine only has a root login
20     "Debian GNU" { set user "root"; set sudo ""; set getroot "" }
21     "Ubuntu" { set user "ubuntu"; set password "ubuntu"; set getroot "sudo -n -i" }
22 }
23
24 expect "login: "
25 send "$user\r"
26
27 expect {
28     "Password" { send "$password\r"; exp_continue }
29     -re $prompt
30 }
31
32 send "export TERM=xterm; $getroot\r"
33 expect -re $prompt
34
35 # install wanted packages; openssh postinst does funny things to the terminal, so only give it pipes
36 send "DEBIAN_FRONTEND=noninteractive apt-get install -o Dpkg::Options::=--force-confnew -y git-buildpackage libwww-perl less vim lintian build-essential debhelper manpages-dev git dput pristine-tar bash-completion libnss-myhostname lptools python-keyrings.alt wget gnupg2 ubuntu-dev-tools python3-debian qemu-kvm qemu-utils schroot sbuild locales openssh-server </dev/null 2>&1 | cat\r"
37 expect -re $prompt
38
39 # set up user
40 send "deluser --remove-home test; adduser --disabled-password --gecos 'Martin Pitt' martin; echo 'martin:a' | chpasswd; adduser martin sbuild\r"
41 expect -re $prompt
42
43 send "echo 'martin ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/martin; update-locale LANG=C.UTF-8; touch /var/lib/sudo/lectured/martin\r"
44 expect -re $prompt
45 send "mkdir /home/martin/.ssh; echo '$sshkey' > /home/martin/.ssh/authorized_keys; chown -R martin:martin /home/martin/.ssh\r"
46 expect -re $prompt
47
48 # mount home, /srv, and schroot config from host; TODO: move to NFS?
49 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' >> /etc/fstab; mount /home/martin/h; mount /srv; mount /etc/schroot\r"
50 expect -re $prompt
51 send "(cd /home/martin; ln -s h/.gbp.conf; ln -s h/.vimrc)\r"
52 expect -re $prompt
53
54 #
55 ## install lxd if available (on Ubuntu)
56 send "(apt-get install -y lxd </dev/null && adduser martin lxd) 2>&1 | cat\r"
57 expect -re $prompt
58
59 interact