From 38f032497e2553feda495b683039b32bd64cb552 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 5 Jun 2015 21:06:47 +0200 Subject: [PATCH] Error handling, formatting, small fixes/additions, version 0.4 --- ChangeLog | 3 +++ INSTALL | 3 ++- TODO | 3 ++- hashboot.sh | 25 ++++++++++++++++++++++--- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index a84f500..589423f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +* 2015-06-05 tastytea + Version 0.4 + Error handling * 2015-06-05 tastytea Version 0.3 Recovery diff --git a/INSTALL b/INSTALL index 8722cf0..46a0511 100644 --- a/INSTALL +++ b/INSTALL @@ -1,3 +1,4 @@ * Make sure you have sha*sum or md5sum installed * Make hashboot.sh executable -* Place hashboot.sh where it's needed \ No newline at end of file +* Place hashboot.sh where it's needed +* Install the appropriate init script \ No newline at end of file diff --git a/TODO b/TODO index 7883668..035b03e 100644 --- a/TODO +++ b/TODO @@ -3,4 +3,5 @@ * Gentoo ebuild * Debian package (done) * Ubuntu package -* recovery (done) \ No newline at end of file +* recovery (done) +* Error handling (done) \ No newline at end of file diff --git a/hashboot.sh b/hashboot.sh index 37b49fe..710b329 100755 --- a/hashboot.sh +++ b/hashboot.sh @@ -1,8 +1,9 @@ #!/bin/sh #Hashes all files in /boot to check them during early boot -#Exit codes: 0 = success, 1 = wrong usage, 2 = not root, 3 = no hasher found, 4 = checksum mismatch +#Exit codes: 0 = success, 1 = wrong usage, 2 = not root, 3 = no hasher found, +#4 = checksum mismatch, 5 = write error -VERSION="0.3" +VERSION="0.4" DIGEST_FILE="/var/lib/hashboot.digest" LOG_FILE="/tmp/hashboot.log" BACKUP_FILE="/var/cache/boot-backup.tar.gz" @@ -57,8 +58,24 @@ then echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${DIGEST_FILE} #Write hashes of all regular files to ${DIGEST_FILE} find /boot -type f -exec ${HASHER} --binary {} >> ${DIGEST_FILE} + + if [ $? == 0 ] + then + echo "List of hashes written to ${DIGEST_FILE}" + else + echo "Error writing ${DIGEST_FILE}" >&2 + die 5 + fi + #Backup of good files tar -czpPf ${BACKUP_FILE} /boot + if [ $? == 0 ] + then + echo "Backup written to ${BACKUP_FILE}" + else + echo "Error writing ${BACKUP_FILE}" >&2 + die 5 + fi + die 0 elif [ "${1}" == "check" ] then @@ -66,12 +83,14 @@ then then die 0 else - echo " !! TIME TO PANIK: A FILE WAS MODIFIED !!" + echo " !! TIME TO PANIK: AT LEAST 1 FILE WAS MODIFIED !!" echo "Restoring files from backup... (type yes or no for each file)" + #For each failed file: ask if it should be recovered from backup for file in $(cut -d: -f1 ${LOG_FILE}) do tar -xzpPvwf ${BACKUP_FILE} ${file} + [ $? != 0 ] && echo "Error restoring ${file} from backup, continuing" done echo -n "Type reboot to reboot now, otherwise you get a shell: "