Check if we're on Debian < 8, change dd status

pull/1/head
tastytea 2015-10-05 02:14:39 +02:00
parent ae69e5bb39
commit 966c6908d2
1 changed files with 9 additions and 2 deletions

View File

@ -25,6 +25,7 @@ HASHER=""
BOOT_MOUNTED=0 BOOT_MOUNTED=0
CONFIG_FILE="/etc/hashboot.cfg" CONFIG_FILE="/etc/hashboot.cfg"
COUNTER=0 COUNTER=0
DD_STATUS="none"
#Umount /boot if we mounted it, exit with given exit code #Umount /boot if we mounted it, exit with given exit code
die () die ()
@ -43,7 +44,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=${DD_STATUS} || 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} +
@ -62,6 +63,12 @@ then
BOOT_MOUNTED=1 BOOT_MOUNTED=1
fi fi
# Debian < 8 check
if which lsb_release > /dev/null && [ "$(lsb_release -si)" == "Debian" ] && [ $(lsb_release -sr | cut -d'.' -f1) -lt 8 ]
then
DD_STATUS="noxfer"
fi
#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
@ -157,7 +164,7 @@ elif [ "${1}" == "check" ]
then then
[ -f ${DIGEST_FILE} ] || die 9 "No digestfile" [ -f ${DIGEST_FILE} ] || die 9 "No digestfile"
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}') HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
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=${DD_STATUS} || die 8
if ! grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict | tee ${LOG_FILE} if ! grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict | tee ${LOG_FILE}
then then
echo " !! TIME TO PANIK: MBR WAS MODIFIED !!" echo " !! TIME TO PANIK: MBR WAS MODIFIED !!"