Add EFI support via --efi <device> option
[grml-debootstrap.git] / packer / debian64.bats
1 #!/usr/bin/env bats
2
3 # config
4 mountpath="/mnt"
5 device="/dev/sda"
6 disk="${device}1"
7
8 setup() {
9   mountpoint "$mountpath" &>/dev/null || mount "$disk" "$mountpath"
10 }
11
12 teardown() {
13   mountpoint "$mountpath" &>/dev/null && umount "$mountpath"
14 }
15
16 # tests
17 @test "debian_version exists and is valid version" {
18   run cat "${mountpath}/etc/debian_version"
19   [ "$status" -eq 0 ]
20   [[ "$output" == [0-9].[0-9]* ]] || [[ "$output" == 'stretch/sid' ]]
21 }
22
23 @test "kernel exists" {
24   run ls "${mountpath}"/boot/vmlinuz-*
25   [ "$status" -eq 0 ]
26   [[ "$output" =~ ${mountpath}/boot/vmlinuz-* ]]
27 }
28
29 @test "initrd exists" {
30   run ls "${mountpath}"/boot/initrd.img-*
31   [ "$status" -eq 0 ]
32   [[ "$output" =~ ${mountpath}/boot/initrd.img-* ]]
33 }
34
35 @test "grub-pc installed" {
36   run chroot $mountpath dpkg-query --show --showformat='${Status}' grub-pc
37   [ "$status" -eq 0 ]
38   [[ "$output" == "install ok installed" ]]
39 }
40
41 @test "ext3/ext4 filesystem" {
42   fstype=$(blkid -o udev ${disk} | grep '^ID_FS_TYPE=')
43   run echo $fstype
44   [ "$status" -eq 0 ]
45   [[ $output =~ ID_FS_TYPE=ext[34] ]]
46 }
47
48 @test "partition table" {
49   table_info=$(parted -s ${device} 'unit s print' | grep -A1 '^Number.*Start.*End' | tail -1)
50   regex='1 2048s.*primary ext[34] boot'
51   run echo $table_info
52   echo "debug: table_info = $table_info"
53   echo "debug: output     = $output"
54   [[ $output =~ $regex ]]
55 }
56
57 @test "tune2fs mount count setting" {
58   mount_count=$(tune2fs -l "$disk" | grep "^Maximum mount count:")
59   run echo "$mount_count"
60   [[ "$output" == "Maximum mount count:      -1" ]]
61 }
62
63 @test "kernel entry in grub config" {
64   run grep "Debian GNU/Linux" "${mountpath}/boot/grub/grub.cfg"
65   [ "$status" -eq 0 ]
66 }
67
68 @test "vim package is installed" {
69   run chroot "$mountpath" dpkg --list vim
70   [ "$status" -eq 0 ]
71 }
72
73 @test "home directory for user vagrant" {
74   run ls -d "$mountpath"/home/vagrant
75   [ "$status" -eq 0 ]
76 }
77
78 @test "home directory for user vagrant" {
79   run grep -q ssh-rsa "$mountpath"/home/vagrant/.ssh/authorized_keys
80   [ "$status" -eq 0 ]
81 }
82
83 @test "sudo setup for user vagrant" {
84   run grep -q '^vagrant ALL=(ALL) NOPASSWD: ALL' "${mountpath}/etc/sudoers.d/vagrant" "${mountpath}/etc/sudoers"
85   [ "$status" -eq 0 ]
86 }
87
88 @test "check for GRUB in MBR" {
89   # note: ^00000170 for lenny
90   # note: ^00000180 for >=wheezy
91   regex='^000001[78]0.*GRUB.*'
92   grub_string=$(dd if=${device} bs=512 count=1 2>/dev/null | hexdump -C | egrep "$regex")
93   run echo "$grub_string"
94   echo "debug: grub_string = $grub_string"
95   echo "debug: output      = $output"
96   [[ $output =~ $regex ]]
97 }