diff --git a/TODO b/TODO index 9b6bba6..06fc483 100644 --- a/TODO +++ b/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 diff --git a/hashboot-9999.ebuild b/hashboot-9999.ebuild index 6334135..5da339e 100644 --- a/hashboot-9999.ebuild +++ b/hashboot-9999.ebuild @@ -18,6 +18,7 @@ RDEPEND=" sys-apps/grep virtual/awk app-shells/bash + sys-apps/util-linux " DEPEND="${RDEPEND} " diff --git a/hashboot.sh b/hashboot.sh index dee48e7..39fe4e3 100755 --- a/hashboot.sh +++ b/hashboot.sh @@ -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 !!"