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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#!/bin/sh -e
. /usr/lib/bilibop/common.sh
ROOTFSPART="$(underlying_device_from_file /)"
if [ ! -b "${ROOTFSPART}" ]; then
echo "${AUTOPKGTEST_REBOOT_MARK}: ROOTFSPART (${ROOTFSPART}) is not a block device." >&2
exit 80
fi
ROOTFSREAL="$(findmnt --noheadings --output=target ${ROOTFSPART})"
if [ ! -d "${ROOTFSREAL}" ]; then
echo "${AUTOPKGTEST_REBOOT_MARK}: ROOTFSREAL (${ROOTFSREAL}) is not a directory." >&2
exit 81
fi
CONFIGFILE="/etc/bilibop/bilibop.conf"
display_command_and_run_it() {
echo "# ${@}"
eval "${@}"
echo
}
# This will allow humans to compare locked/unlocked states.
display_command_and_run_it "grep -E ' / |overlay|lockfs|aufs' /proc/mounts"
display_command_and_run_it "lsblk --output=name,ro,mountpoint"
display_command_and_run_it "df --output=source,fstype,target"
case "${AUTOPKGTEST_REBOOT_MARK}" in
"")
if [ "${ROOTFSREAL}" = "/" ]; then
echo "STAGE 0: root filesystem is not locked."
echo "STAGE 0: enable bilibop-lockfs and reboot."
echo
display_command_and_run_it "echo BILIBOP_LOCKFS='true' | tee ${CONFIGFILE}"
display_command_and_run_it "echo BILIBOP_LOCKFS_POLICY='soft' | tee -a ${CONFIGFILE}"
display_command_and_run_it "echo BILIBOP_LOCKFS_PATH_PREFIX='.lockfs' | tee -a ${CONFIGFILE}"
display_command_and_run_it "sync"
/tmp/autopkgtest-reboot lockfs
else
echo "STAGE 0: unexpected error" >&2
exit 90
fi
;;
lockfs)
if [ "${ROOTFSREAL}" = "/" ]; then
echo "STAGE 1: root filesystem is not locked." >&2
exit 11
fi
if [ $(blockdev --getro ${ROOTFSPART}) -eq 0 ] && [ "${ROOTFSREAL}" = "/.lockfs/ro" ]; then
echo "STAGE 1: root filesystem is successfully locked with soft policy."
echo "STAGE 1: disable bilibop-lockfs and reboot."
echo
display_command_and_run_it "mount -v -o ro ${ROOTFSPART} /mnt"
display_command_and_run_it "mount -v -o remount,rw /mnt"
display_command_and_run_it "echo BILIBOP_LOCKFS='false' | tee /mnt${CONFIGFILE}"
display_command_and_run_it "sync /mnt${CONFIGFILE}"
display_command_and_run_it "umount -v /mnt"
/tmp/autopkgtest-reboot nolockfs
else
echo "STAGE 1: unexpected error" >&2
exit 91
fi
;;
nolockfs)
if [ "${ROOTFSREAL}" = "/" ]; then
echo "STAGE 2: root filesystem is successfully unlocked."
echo "STAGE 2: end of test."
exit 0
else
echo "STAGE 2: root filesystem is still locked." >&2
exit 12
fi
;;
*)
echo "unsupported value (AUTOPKGTEST_REBOOT_MARK='${AUTOPKGTEST_REBOOT_MARK}')" >&2
exit 100
;;
esac
|