Use global variable for MBR size

pull/1/head
tastytea 2015-10-04 18:38:26 +02:00
parent a8dcb7496a
commit 9192d4b225
1 changed files with 6 additions and 7 deletions

View File

@ -18,6 +18,7 @@ DIGEST_FILE="/var/lib/hashboot.digest"
DIGEST_FILE_TMP="/tmp/hashboot.digesttmp" DIGEST_FILE_TMP="/tmp/hashboot.digesttmp"
LOG_FILE="/tmp/hashboot.log" LOG_FILE="/tmp/hashboot.log"
MBR_DEVICE="" MBR_DEVICE=""
MBR_SIZE=0
MBR_TMP="/tmp/mbr" MBR_TMP="/tmp/mbr"
BACKUP_FILE="/var/cache/boot-backup.tar.gz" BACKUP_FILE="/var/cache/boot-backup.tar.gz"
HASHER="" HASHER=""
@ -52,11 +53,8 @@ read_config ()
echo "#Device with the MBR on it" > ${CONFIG_FILE} echo "#Device with the MBR on it" > ${CONFIG_FILE}
echo "mbr_device = ${MBR_DEVICE}" >> ${CONFIG_FILE} echo "mbr_device = ${MBR_DEVICE}" >> ${CONFIG_FILE}
fi fi
}
mbr_size () # Find out where the first partition starts and set ${MBR_SIZE} in KiB
{
# Find out where the first partition starts returns(prints) size in KiB
sectorsize=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep '^Units' | awk '{print $8}') sectorsize=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep '^Units' | awk '{print $8}')
if [ "${sectorsize}" == "=" ] # Older versions of util-linux if [ "${sectorsize}" == "=" ] # Older versions of util-linux
then then
@ -64,7 +62,8 @@ mbr_size ()
fi fi
startsector=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep -A1 'Device' | tail -n1 | awk '{print $3}') startsector=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep -A1 'Device' | tail -n1 | awk '{print $3}')
expr ${sectorsize} \* ${startsector} / 1024 MBR_SIZE=$(expr ${sectorsize} \* ${startsector} / 1024)
if [ ${?} != 0 ] if [ ${?} != 0 ]
then then
die 1 "Something went wrong. Most likely your partition table is corrupt. Use hashboot recover to fix this." die 1 "Something went wrong. Most likely your partition table is corrupt. Use hashboot recover to fix this."
@ -76,7 +75,7 @@ write_hashes ()
#Write header to ${1} #Write header to ${1}
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${1} echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${1}
#Write MBR of MBR_DEVICE to ${1} #Write MBR of MBR_DEVICE to ${1}
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=$(mbr_size)K 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 ${1} #Write hashes of all regular files to ${1}
${HASHER} ${MBR_TMP} >> ${1} ${HASHER} ${MBR_TMP} >> ${1}
find /boot -type f -exec ${HASHER} --binary {} >> ${1} + find /boot -type f -exec ${HASHER} --binary {} >> ${1} +
@ -149,7 +148,7 @@ then
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}') HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
read_config read_config
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=$(mbr_size)K 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}) if ! $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE})
then then
echo " !! TIME TO PANIK: MBR WAS MODIFIED !!" echo " !! TIME TO PANIK: MBR WAS MODIFIED !!"