1
1
mirror of https://schlomp.space/tastytea/hashboot synced 2024-11-16 14:37:06 +01:00

Find out where the first partition starts and set the MBR size accordingly

This commit is contained in:
tastytea 2015-10-03 15:35:52 +02:00
parent d1391f653f
commit 5fcf6abad7
3 changed files with 11 additions and 3 deletions

1
TODO

@ -1,5 +1,4 @@
* Debian package
* Ubuntu package
* Supress dd output while staying Debian 7 compatible
* Find out if we are raspbian compatible (first partition starts at 4MiB)
* Debian and Ubuntu repositories

@ -18,6 +18,7 @@ RDEPEND="
sys-apps/grep
virtual/awk
app-shells/bash
sys-apps/util-linux
"
DEPEND="${RDEPEND}
"

@ -46,6 +46,14 @@ read_config ()
fi
}
mbr_size ()
{
# Find out where the first partition starts returns(prints) size in KiB
sectorsize=$(LC_ALL=C fdisk -l /dev/sda | grep '^Units:' | awk '{print $8}')
startsector=$(LC_ALL=C fdisk -l /dev/sda | grep -A1 '^Device' | tail -n1 | awk '{print $3}')
expr ${sectorsize} \* ${startsector} / 1024
}
#If we're not root: exit
if [ ${UID} -ne 0 ]
then
@ -78,7 +86,7 @@ then
#Write header
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${DIGEST_FILE}
#Write MBR of MBR_DEVICE to ${DIGEST_FILE}
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=noxfer || die 8
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=$(mbr_size)K count=1 status=noxfer || die 8
#Write hashes of all regular files to ${DIGEST_FILE}
${HASHER} ${MBR_TMP} >> ${DIGEST_FILE}
find /boot -type f -exec ${HASHER} --binary {} >> ${DIGEST_FILE} +
@ -103,7 +111,7 @@ then
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
read_config
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=noxfer || die 8
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=$(mbr_size)K count=1 status=noxfer || die 8
if ! $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE})
then
echo " !! TIME TO PANIK: MBR WAS MODIFIED !!"