Parse header of ${DIGEST_FILE} to set correct hash calculator

pull/1/head
tastytea 2015-09-30 00:24:56 +02:00
parent 92dcb3e01d
commit 603033a861
1 changed files with 16 additions and 13 deletions

View File

@ -16,6 +16,7 @@ HASHER=""
BOOT_MOUNTED=0 BOOT_MOUNTED=0
CONFIG_FILE="/etc/hashboot.cfg" CONFIG_FILE="/etc/hashboot.cfg"
#Umount /boot if we mounted it, exit with given exit code #Umount /boot if we mounted it, exit with given exit code
function die function die
{ {
@ -28,13 +29,22 @@ function die
exit ${1} exit ${1}
} }
#If we're not root: exit #If we're not root: exit
if [ ${UID} -ne 0 ] if [ ${UID} -ne 0 ]
then then
die 4 "You have to be root" die 4 "You have to be root"
fi fi
#If /boot is in fstab but not mounted: mount, mark as mounted
if grep -q '/boot.*noauto' /etc/fstab && ! grep -q /boot /etc/mtab
then
mount /boot
BOOT_MOUNTED=1
fi
if [ "${1}" == "index" ]
then
#Try different hashers, use the most secure #Try different hashers, use the most secure
HASHER=$(/usr/bin/which --skip-dot sha512sum 2> /dev/null) HASHER=$(/usr/bin/which --skip-dot sha512sum 2> /dev/null)
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha384sum 2> /dev/null) test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha384sum 2> /dev/null)
@ -46,15 +56,6 @@ test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot md5sum 2> /dev/null)
#If we found no hasher: exit #If we found no hasher: exit
[ -z ${HASHER} ] && die 5 "No hash calculator found" [ -z ${HASHER} ] && die 5 "No hash calculator found"
#If /boot is in fstab but not mounted: mount, mark as mounted
if grep -q '/boot.*noauto' /etc/fstab && ! grep -q /boot /etc/mtab
then
mount /boot
BOOT_MOUNTED=1
fi
if [ "${1}" == "index" ]
then
#Look for config file and set ${MBR_DEVICE}. #Look for config file and set ${MBR_DEVICE}.
if [ -f ${CONFIG_FILE} ] if [ -f ${CONFIG_FILE} ]
then then
@ -74,7 +75,7 @@ then
#Write MBR of MBR_DEVICE to ${DIGEST_FILE} #Write MBR of MBR_DEVICE to ${DIGEST_FILE}
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=none || die 8 dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=none || die 8
#Write hashes of all regular files to ${DIGEST_FILE} #Write hashes of all regular files to ${DIGEST_FILE}
${HASHER} ${MBR_TMP} > ${DIGEST_FILE} ${HASHER} ${MBR_TMP} >> ${DIGEST_FILE}
find /boot -type f -exec ${HASHER} --binary {} >> ${DIGEST_FILE} + find /boot -type f -exec ${HASHER} --binary {} >> ${DIGEST_FILE} +
if [ $? == 0 ] if [ $? == 0 ]
then then
@ -94,6 +95,8 @@ then
elif [ "${1}" == "check" ] elif [ "${1}" == "check" ]
then then
COUNTER=0 COUNTER=0
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=none || die 8 dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=none || 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