diff --git a/ChangeLog b/ChangeLog index 589423f..4439748 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +* 2015-06-05 tastytea + Changed to be not interactive while checking to work with systemd * 2015-06-05 tastytea Version 0.4 Error handling diff --git a/hashboot.sh b/hashboot.sh index 710b329..a6eb244 100755 --- a/hashboot.sh +++ b/hashboot.sh @@ -22,6 +22,18 @@ function die exit ${1} } +function recover +{ + 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 +} + #If we're not root: exit if [ ${UID} -ne 0 ] then @@ -75,8 +87,6 @@ then echo "Error writing ${BACKUP_FILE}" >&2 die 5 fi - - die 0 elif [ "${1}" == "check" ] then if $(${HASHER} --check --warn --quiet --strict ${DIGEST_FILE} > ${LOG_FILE}) @@ -84,24 +94,14 @@ then die 0 else 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: " - read -r reboot - if [ ${reboot} == "reboot" ] - then - reboot - fi die 4 fi +elif [ "${1}" == "recover" ] +then + recover else - echo "Usage: ${0} index|check" >&2 + echo "Usage: ${0} index|check|recover" >&2 die 1 -fi \ No newline at end of file +fi + +die 0 diff --git a/initscript.debian b/initscript.debian index 6e4ea6a..0b4d2a5 100755 --- a/initscript.debian +++ b/initscript.debian @@ -18,11 +18,23 @@ case "$1" in start) log_daemon_msg "Checking integrity of files in /boot" - if ! hashboot.sh check + hashboot.sh check + if [ $? == 4 ] then - log_end_msg 1 + log_end_msg 4 + + echo -n "Recover files? [y/N] " + read -r yesno + if [ ${yesno} == "y" ] + then + hashboot.sh recover + fi + sh - exit 1 + exit 4 + elif [ $? != 0 ] + log_end_msg $? + exit $? fi log_end_msg 0 diff --git a/initscript.gentoo b/initscript.gentoo index 13d5f5b..e592d64 100755 --- a/initscript.gentoo +++ b/initscript.gentoo @@ -14,10 +14,20 @@ start() # See if hashboot.sh is accessible which hashboot.sh > /dev/null || return 1 - if ! hashboot.sh check + hashboot.sh check + if [ $? == 4 ] then + echo -n "Recover files? [y/N] " + read -r yesno + if [ ${yesno} == "y" ] + then + hashboot.sh recover + fi + sh - return 2 + return 4 + elif [ $? != 0 ] + return $? fi eend 0