more better. more errorcodes. no: one differs.

pull/1/head
xor 2015-10-04 23:18:30 +02:00
parent ed2415cc34
commit 0a71b249b6
1 changed files with 18 additions and 20 deletions

View File

@ -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,10 +152,9 @@ then
elif [ "${1}" == "check" ] elif [ "${1}" == "check" ]
then then
[ -f ${DIGEST_FILE} ] [ -f ${DIGEST_FILE} ] || die 9 "No digestfile"
then [ -f ${CONFIG_FILE} ] || die 9 "No configfile"
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=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
@ -166,9 +167,6 @@ then
COUNTER=$((COUNTER + 2)) COUNTER=$((COUNTER + 2))
die $COUNTER die $COUNTER
fi fi
else
#error no digest file
fi
elif [ "${1}" == "recover" ] elif [ "${1}" == "recover" ]
then then
echo "Restoring files from backup... (type yes or no for each file)" echo "Restoring files from backup... (type yes or no for each file)"
@ -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} ]