-
Notifications
You must be signed in to change notification settings - Fork 14
/
vm-build.expect
60 lines (44 loc) · 1.51 KB
/
vm-build.expect
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/expect -f
set timeout 300
spawn qemu-system-arm \
-kernel kernel-qemu \
-cpu arm1176 \
-m 256 \
-M versatilepb \
-no-reboot \
-nographic \
-append "root=/dev/sda2 panic=1 rootfstype=ext4 rw console=ttyAMA0" \
-redir tcp:2222::22 \
-hda build/disk.img
expect "raspberrypi login: "
send "pi\r"
expect "Password: "
send "raspberry\r"
# make the filesystem fill the main partition
expect "pi@raspberrypi:~$ "
send "sudo resize2fs /dev/sda2\r"
expect "pi@raspberrypi:~$ "
send "df -h\r"
# install the tingbot ssh key
set key_fp [open "tingbot.key.pub" r]
set key_data [read $key_fp]
expect "pi@raspberrypi:~$ "
send "mkdir -p ~/.ssh\r"
expect "pi@raspberrypi:~$ "
send "echo '$key_data' >> ~/.ssh/authorized_keys\r"
expect "pi@raspberrypi:~$ "
send "sudo service ssh restart\r"
expect "pi@raspberrypi:~$ "
system "sleep 5"
send "service ssh status\r"
expect "pi@raspberrypi:~$ "
# mount the /boot partition
send "sudo mount -t vfat /dev/sda1 /boot\r"
expect "pi@raspberrypi:~$ "
# copy the deb files to the pi
system "./retry.sh 5 scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i tingbot.key -P 2222 build/tingbot-os.deb libsdl1.2debian_1.2.15-5_armhf.deb pi@localhost:"
# ssh into the vm and run the build script. This moves the main work
# into a sane shell (not expect!)
system "./retry.sh 5 sh -c 'cat build.sh | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i tingbot.key -p 2222 pi@localhost bash'"
send "sudo shutdown -r now\r"
expect eof