mirror of https://schlomp.space/tastytea/hashboot
More MBR stuff
parent
80e6f27157
commit
6ebbd9ee69
15
hashboot.sh
15
hashboot.sh
|
@ -9,7 +9,7 @@ PATH="/bin:/usr/bin:/sbin:/usr/sbin"
|
||||||
|
|
||||||
DIGEST_FILE="/var/lib/hashboot.digest"
|
DIGEST_FILE="/var/lib/hashboot.digest"
|
||||||
LOG_FILE="/tmp/hashboot.log"
|
LOG_FILE="/tmp/hashboot.log"
|
||||||
MBR_FILE="/var/lib/mbr.digest"
|
MBR_DEVICE="/dev/sda"
|
||||||
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=""
|
||||||
|
@ -60,9 +60,10 @@ if [ "${1}" == "index" ]
|
||||||
then
|
then
|
||||||
#Write header
|
#Write header
|
||||||
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${DIGEST_FILE}
|
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${DIGEST_FILE}
|
||||||
|
#Write MBR of MBR_DEVICE to ${DIGEST_FILE}
|
||||||
|
dd if=/dev/sda of=${MBR_TMP} bs=1M count=1 status=noxfer || die 8
|
||||||
#Write hashes of all regular files to ${DIGEST_FILE}
|
#Write hashes of all regular files to ${DIGEST_FILE}
|
||||||
err=$(dd if=/dev/sda of=${MBR_TMP} bs=2M count=1 status=noxfer 2>&1) || die 8
|
${HASHER} ${MBR_TMP} > ${DIGEST_FILE}
|
||||||
${HASHER} ${MBR_TMP} > ${MBR_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
|
||||||
|
@ -72,7 +73,7 @@ then
|
||||||
die 7
|
die 7
|
||||||
fi
|
fi
|
||||||
#Backup of good files
|
#Backup of good files
|
||||||
tar -czpPf ${BACKUP_FILE} /boot ${MBR_TMP} ${MBR_FILE} ${DIGEST_FILE}
|
tar -czpPf ${BACKUP_FILE} ${MBR_TMP} /boot ${DIGEST_FILE}
|
||||||
if [ $? == 0 ]
|
if [ $? == 0 ]
|
||||||
then
|
then
|
||||||
echo "Backup written to ${BACKUP_FILE}"
|
echo "Backup written to ${BACKUP_FILE}"
|
||||||
|
@ -83,15 +84,15 @@ then
|
||||||
elif [ "${1}" == "check" ]
|
elif [ "${1}" == "check" ]
|
||||||
then
|
then
|
||||||
COUNTER=0
|
COUNTER=0
|
||||||
err=$(dd if=/dev/sda of=${MBR_TMP} bs=2M count=1 status=noxfer 2>&1) || die 8
|
dd if=/dev/sda of=${MBR_TMP} bs=1M count=1 status=noxfer || die 8
|
||||||
if $(${HASHER} --check --warn --quiet --strict ${MBR_FILE} > ${LOG_FILE})
|
if $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE})
|
||||||
then
|
then
|
||||||
echo "MBR ok"
|
echo "MBR ok"
|
||||||
else
|
else
|
||||||
echo " !! TIME TO PANIK: MBR WAS MODIFIED !!"
|
echo " !! TIME TO PANIK: MBR WAS MODIFIED !!"
|
||||||
COUNTER=$((COUNTER + 1))
|
COUNTER=$((COUNTER + 1))
|
||||||
fi
|
fi
|
||||||
if $(${HASHER} --check --warn --quiet --strict ${DIGEST_FILE} >> ${LOG_FILE})
|
if $(grep -v ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict >> ${LOG_FILE})
|
||||||
then
|
then
|
||||||
echo "/boot ok"
|
echo "/boot ok"
|
||||||
die 0
|
die 0
|
||||||
|
|
Loading…
Reference in New Issue