2018-07-13 03:26:48 +02:00
|
|
|
load common
|
|
|
|
|
2018-07-15 06:50:45 +02:00
|
|
|
begin_sys() {
|
2020-12-30 21:13:24 +01:00
|
|
|
apt-get -qq install debconf-utils hwinfo lvm2 cryptsetup-bin parted
|
2018-07-15 06:50:45 +02:00
|
|
|
|
2018-07-13 03:26:48 +02:00
|
|
|
cat << EOF > "${BATS_TMPDIR}/backup.d/test.sys"
|
|
|
|
when = manual
|
2021-01-07 04:23:45 +01:00
|
|
|
parentdir = $BN_BACKUPDIR
|
2018-07-15 06:50:45 +02:00
|
|
|
packages = yes
|
|
|
|
partitions = yes
|
|
|
|
hardware = yes
|
|
|
|
luksheaders = yes
|
|
|
|
lvm = yes
|
|
|
|
mbr = yes
|
2018-07-13 03:26:48 +02:00
|
|
|
bios = no
|
|
|
|
EOF
|
|
|
|
|
|
|
|
chmod 0640 "${BATS_TMPDIR}/backup.d/test.sys"
|
|
|
|
|
2018-07-15 06:50:45 +02:00
|
|
|
# Setup LVM
|
2020-12-30 21:13:24 +01:00
|
|
|
pvcreate /dev/sdc
|
|
|
|
vgcreate vgtest /dev/sdc
|
|
|
|
lvcreate -L 12M -n lvtest vgtest /dev/sdc
|
2020-12-27 17:33:05 +01:00
|
|
|
|
2020-12-30 21:13:24 +01:00
|
|
|
# Setup LUKS
|
|
|
|
parted -s /dev/sdd mklabel msdos mkpart p 1MiB 50% mkpart p 50% 100%
|
2020-12-31 18:03:15 +01:00
|
|
|
partprobe
|
2020-12-30 21:13:24 +01:00
|
|
|
cryptsetup -q --type luks1 luksFormat /dev/sdd1 <<< 123test
|
|
|
|
cryptsetup -q --type luks2 luksFormat /dev/sdd2 <<< 123test
|
2020-12-30 21:46:38 +01:00
|
|
|
cryptsetup -q --type luks2 luksFormat /dev/sde <<< 123test
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 06:50:45 +02:00
|
|
|
finish_sys() {
|
2020-12-31 18:03:38 +01:00
|
|
|
# remove test artifacts
|
2021-01-07 04:23:45 +01:00
|
|
|
rm -rf ${BN_BACKUPDIR}/*
|
2020-12-31 18:03:38 +01:00
|
|
|
# cleanup lvm
|
2018-07-13 03:26:48 +02:00
|
|
|
lvremove -f vgtest/lvtest
|
2018-07-15 06:50:45 +02:00
|
|
|
vgremove vgtest
|
2020-12-30 21:13:24 +01:00
|
|
|
pvremove /dev/sdc
|
2020-12-31 18:03:38 +01:00
|
|
|
# cleanup luks data and partition tables
|
2020-12-30 21:13:24 +01:00
|
|
|
dd if=/dev/zero of=/dev/sdc bs=512 count=1 conv=notrunc
|
2020-12-31 18:03:38 +01:00
|
|
|
dd if=/dev/zero of=/dev/sdd1 bs=512 count=2048 conv=notrunc
|
|
|
|
dd if=/dev/zero of=/dev/sdd2 bs=512 count=2048 conv=notrunc
|
2020-12-30 21:13:24 +01:00
|
|
|
dd if=/dev/zero of=/dev/sdd bs=512 count=1 conv=notrunc
|
2020-12-31 18:03:38 +01:00
|
|
|
dd if=/dev/zero of=/dev/sde bs=512 count=2048 conv=notrunc
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 06:50:45 +02:00
|
|
|
@test "action runs without errors" {
|
2021-01-07 04:23:45 +01:00
|
|
|
runaction
|
|
|
|
greplog "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning."
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 16:38:02 +02:00
|
|
|
@test "system report is created" {
|
2021-01-07 04:23:45 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/sysreport.txt" ]
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 16:38:02 +02:00
|
|
|
@test "packages backup is made" {
|
2021-01-07 04:23:45 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/dpkg-selections.txt" ]
|
|
|
|
[ -s "${BN_BACKUPDIR}/debconfsel.txt" ]
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 16:38:02 +02:00
|
|
|
@test "partitions backup is made" {
|
2021-01-07 04:23:45 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/partitions.sda.txt" ]
|
|
|
|
[ -s "${BN_BACKUPDIR}/partitions.sdd.txt" ]
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 06:50:45 +02:00
|
|
|
@test "mbr backup is made" {
|
2021-01-07 04:23:45 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/mbr.sda.bin" ]
|
|
|
|
file "${BN_BACKUPDIR}/mbr.sda.bin" | grep -q "DOS/MBR boot sector"
|
2018-07-15 06:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "hardware info backup is made" {
|
2021-01-07 04:23:45 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/hardware.txt" ]
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 16:38:02 +02:00
|
|
|
@test "lvm backup is made" {
|
2021-01-07 04:23:45 +01:00
|
|
|
[ -d "${BN_BACKUPDIR}/lvm" ]
|
|
|
|
[ -s "${BN_BACKUPDIR}/lvm/vgtest" ]
|
|
|
|
grep -q 'contents = "Text Format Volume Group"' "${BN_BACKUPDIR}/lvm/vgtest"
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2020-12-30 21:46:38 +01:00
|
|
|
@test "luksheaders v1 partition backup is made" {
|
2021-01-07 04:23:45 +01:00
|
|
|
file "${BN_BACKUPDIR}/luksheader.sdd1.bin" | grep -q "LUKS encrypted file"
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
2020-12-27 17:33:05 +01:00
|
|
|
|
2020-12-30 21:46:38 +01:00
|
|
|
@test "luksheaders v2 partition backup is made" {
|
2021-01-07 04:23:45 +01:00
|
|
|
file "${BN_BACKUPDIR}/luksheader.sdd2.bin" | grep -q "LUKS encrypted file"
|
2020-12-27 17:33:05 +01:00
|
|
|
}
|
2020-12-30 21:46:38 +01:00
|
|
|
|
|
|
|
@test "luksheaders v2 device backup is made" {
|
2021-01-07 04:23:45 +01:00
|
|
|
file "${BN_BACKUPDIR}/luksheader.sde.bin" | grep -q "LUKS encrypted file"
|
2020-12-30 21:46:38 +01:00
|
|
|
}
|