mirror of
https://schlomp.space/tastytea/hashboot
synced 2024-11-16 14:37:06 +01:00
more better. more errorcodes. no: one differs.
This commit is contained in:
parent
ed2415cc34
commit
0a71b249b6
38
hashboot
38
hashboot
@ -2,7 +2,7 @@
|
|||||||
#Hashes all files in /boot to check them during early boot
|
#Hashes all files in /boot to check them during early boot
|
||||||
#Exit codes: 0 = success, 1 = checksum mbr mismatch, 2 = checksum /boot mismatch,
|
#Exit codes: 0 = success, 1 = checksum mbr mismatch, 2 = checksum /boot mismatch,
|
||||||
#3 = checksum mbr/boot mismatch, 4 = not root, 5 = no hasher found, 6 = wrong usage,
|
#3 = checksum mbr/boot mismatch, 4 = not root, 5 = no hasher found, 6 = wrong usage,
|
||||||
#7 = write error, 8 = dd error, 9 config file error
|
#7 = write error, 8 = dd error, 9 = file not found
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
# "THE HUG-WARE LICENSE" (Revision 1): #
|
# "THE HUG-WARE LICENSE" (Revision 1): #
|
||||||
@ -20,7 +20,7 @@ LOG_FILE="/tmp/hashboot.log"
|
|||||||
MBR_DEVICE="/dev/sda"
|
MBR_DEVICE="/dev/sda"
|
||||||
MBR_SIZE=1024
|
MBR_SIZE=1024
|
||||||
MBR_TMP="/tmp/mbr"
|
MBR_TMP="/tmp/mbr"
|
||||||
BACKUP_FILE="/var/cache/boot-backup.tar.gz"
|
BACKUP_FILE="/var/cache/boot-backup.tar"
|
||||||
HASHER=""
|
HASHER=""
|
||||||
BOOT_MOUNTED=0
|
BOOT_MOUNTED=0
|
||||||
CONFIG_FILE="/etc/hashboot.cfg"
|
CONFIG_FILE="/etc/hashboot.cfg"
|
||||||
@ -109,6 +109,8 @@ fi
|
|||||||
|
|
||||||
if [ "${1}" == "index" ]
|
if [ "${1}" == "index" ]
|
||||||
then
|
then
|
||||||
|
[ -f ${DIGEST_FILE} ] || die 10 "No digestfile"
|
||||||
|
[ -f ${CONFIG_FILE} ] || die 9 "No configfile"
|
||||||
#Try different hashers, use the most secure
|
#Try different hashers, use the most secure
|
||||||
HASHER=$(/usr/bin/which sha512sum 2> /dev/null)
|
HASHER=$(/usr/bin/which sha512sum 2> /dev/null)
|
||||||
test -z "${HASHER}" && HASHER=$(/usr/bin/which sha384sum 2> /dev/null)
|
test -z "${HASHER}" && HASHER=$(/usr/bin/which sha384sum 2> /dev/null)
|
||||||
@ -150,24 +152,20 @@ then
|
|||||||
|
|
||||||
elif [ "${1}" == "check" ]
|
elif [ "${1}" == "check" ]
|
||||||
then
|
then
|
||||||
[ -f ${DIGEST_FILE} ]
|
[ -f ${DIGEST_FILE} ] || die 9 "No digestfile"
|
||||||
|
[ -f ${CONFIG_FILE} ] || die 9 "No configfile"
|
||||||
|
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
|
||||||
|
if ! $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE})
|
||||||
then
|
then
|
||||||
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
|
echo " !! TIME TO PANIK: MBR WAS MODIFIED !!"
|
||||||
|
COUNTER=$((COUNTER + 1))
|
||||||
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=${MBR_SIZE}K count=1 status=noxfer || die 8
|
fi
|
||||||
if ! $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE})
|
if ! $(grep -v ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict >> ${LOG_FILE})
|
||||||
then
|
then
|
||||||
echo " !! TIME TO PANIK: MBR WAS MODIFIED !!"
|
echo " !! TIME TO PANIK: AT LEAST 1 FILE WAS MODIFIED !!"
|
||||||
COUNTER=$((COUNTER + 1))
|
COUNTER=$((COUNTER + 2))
|
||||||
fi
|
die $COUNTER
|
||||||
if ! $(grep -v ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict >> ${LOG_FILE})
|
|
||||||
then
|
|
||||||
echo " !! TIME TO PANIK: AT LEAST 1 FILE WAS MODIFIED !!"
|
|
||||||
COUNTER=$((COUNTER + 2))
|
|
||||||
die $COUNTER
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
#error no digest file
|
|
||||||
fi
|
fi
|
||||||
elif [ "${1}" == "recover" ]
|
elif [ "${1}" == "recover" ]
|
||||||
then
|
then
|
||||||
@ -176,7 +174,7 @@ then
|
|||||||
#For each failed file: ask if it should be recovered from backup
|
#For each failed file: ask if it should be recovered from backup
|
||||||
for file in $(cut -d: -f1 ${LOG_FILE})
|
for file in $(cut -d: -f1 ${LOG_FILE})
|
||||||
do
|
do
|
||||||
tar -xzpPvwf ${BACKUP_FILE} ${file}
|
tar -xpPvwf ${BACKUP_FILE} ${file}
|
||||||
[ $? != 0 ] && echo "Error restoring ${file} from backup, continuing" >&2
|
[ $? != 0 ] && echo "Error restoring ${file} from backup, continuing" >&2
|
||||||
#If the MBR is to be recovered, copy to ${MBR_DEVICE}
|
#If the MBR is to be recovered, copy to ${MBR_DEVICE}
|
||||||
if [ "${file}" == ${MBR_TMP} ]
|
if [ "${file}" == ${MBR_TMP} ]
|
||||||
|
Loading…
Reference in New Issue
Block a user