mirror of https://schlomp.space/tastytea/hashboot
little fixes, modified initscripts to reflect exit code changes
parent
d59eaf7ef8
commit
7f3fa8630d
3
TODO
3
TODO
|
@ -1,2 +1,3 @@
|
||||||
* Deian package
|
* Debian package
|
||||||
* Ubuntu package
|
* Ubuntu package
|
||||||
|
* Read header of ${DIGEST_FILE}
|
118
hashboot.sh
118
hashboot.sh
|
@ -18,31 +18,31 @@ BOOT_MOUNTED=""
|
||||||
#Umount /boot if we mounted it, exit with given exit code
|
#Umount /boot if we mounted it, exit with given exit code
|
||||||
function die
|
function die
|
||||||
{
|
{
|
||||||
if [ ! -z ${BOOT_MOUNTED} ]
|
if [ ! -z ${BOOT_MOUNTED} ]
|
||||||
then
|
then
|
||||||
umount /boot
|
umount /boot
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit ${1}
|
exit ${1}
|
||||||
}
|
}
|
||||||
|
|
||||||
function recover
|
function recover
|
||||||
{
|
{
|
||||||
echo "Restoring files from backup... (type yes or no for each file)"
|
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 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 -xzpPvwf ${BACKUP_FILE} ${file}
|
||||||
[ $? != 0 ] && echo "Error restoring ${file} from backup, continuing"
|
[ $? != 0 ] && echo "Error restoring ${file} from backup, continuing"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#If we're not root: exit
|
#If we're not root: exit
|
||||||
if [ ${UID} -ne 0 ]
|
if [ ${UID} -ne 0 ]
|
||||||
then
|
then
|
||||||
echo "You have to be root" >&2
|
echo "You have to be root" >&2
|
||||||
die 4
|
die 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Try different hashers, use the most secure
|
#Try different hashers, use the most secure
|
||||||
|
@ -56,73 +56,67 @@ test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot md5sum 2> /dev/null)
|
||||||
#If we found no hasher: exit
|
#If we found no hasher: exit
|
||||||
if [ -z ${HASHER} ]
|
if [ -z ${HASHER} ]
|
||||||
then
|
then
|
||||||
echo "No hash calculator found" >&2
|
echo "No hash calculator found" >&2
|
||||||
die 5
|
die 5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#If /boot is in fstab but not mounted: mount, mark as mounted
|
#If /boot is in fstab but not mounted: mount, mark as mounted
|
||||||
if grep -q '/boot.*noauto' /etc/fstab && ! grep -q /boot /etc/mtab
|
if grep -q '/boot.*noauto' /etc/fstab && ! grep -q /boot /etc/mtab
|
||||||
then
|
then
|
||||||
mount /boot
|
mount /boot
|
||||||
BOOT_MOUNTED=1
|
BOOT_MOUNTED=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${1}" == "index" ]
|
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 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=1M count=1 status=noxfer 2>&1) || die 8 >&2
|
err=$(dd if=/dev/sda of=${MBR_TMP} bs=2M count=1 status=noxfer 2>&1) || die 8
|
||||||
${HASHER} ${MBR_TMP} > ${MBR_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
|
||||||
echo "List of hashes written to ${DIGEST_FILE}"
|
echo "List of hashes written to ${DIGEST_FILE}"
|
||||||
else
|
else
|
||||||
echo "Error writing ${DIGEST_FILE}" >&2
|
echo "Error writing ${DIGEST_FILE}" >&2
|
||||||
die 7
|
die 7
|
||||||
fi
|
fi
|
||||||
#Backup of good files
|
#Backup of good files
|
||||||
tar -czpPf ${BACKUP_FILE} /boot ${MBR_TMP} ${MBR_FILE}
|
tar -czpPf ${BACKUP_FILE} /boot ${MBR_TMP} ${MBR_FILE} ${DIGEST_FILE}
|
||||||
if [ $? == 0 ]
|
if [ $? == 0 ]
|
||||||
then
|
then
|
||||||
echo "Backup written to ${BACKUP_FILE}"
|
echo "Backup written to ${BACKUP_FILE}"
|
||||||
else
|
else
|
||||||
echo "Error writing ${BACKUP_FILE}" >&2
|
echo "Error writing ${BACKUP_FILE}" >&2
|
||||||
die 7
|
die 7
|
||||||
fi
|
fi
|
||||||
elif [ "${1}" == "check" ]
|
elif [ "${1}" == "check" ]
|
||||||
then
|
then
|
||||||
COUNTER=0
|
COUNTER=0
|
||||||
err=$(dd if=/dev/sda of=${MBR_TMP} bs=1M count=1 status=noxfer 2>&1) || die 8 >&2
|
err=$(dd if=/dev/sda of=${MBR_TMP} bs=2M count=1 status=noxfer 2>&1) || die 8
|
||||||
if $(${HASHER} --check --warn --quiet --strict ${MBR_FILE} > ${LOG_FILE})
|
if $(${HASHER} --check --warn --quiet --strict ${MBR_FILE} > ${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 $(${HASHER} --check --warn --quiet --strict ${DIGEST_FILE} >> ${LOG_FILE})
|
then
|
||||||
then
|
echo "/boot ok"
|
||||||
echo "/boot io"
|
|
||||||
die 0
|
die 0
|
||||||
|
else
|
||||||
else
|
echo " !! TIME TO PANIK: AT LEAST 1 FILE WAS MODIFIED !!"
|
||||||
echo " !! TIME TO PANIK: AT LEAST 1 FILE WAS MODIFIED !!"
|
|
||||||
COUNTER=$((COUNTER + 2))
|
COUNTER=$((COUNTER + 2))
|
||||||
die $COUNTER
|
die $COUNTER
|
||||||
|
fi
|
||||||
fi
|
|
||||||
elif [ "${1}" == "recover" ]
|
elif [ "${1}" == "recover" ]
|
||||||
then
|
then
|
||||||
recover
|
recover
|
||||||
else
|
else
|
||||||
echo "Usage: ${0} index|check|recover" >&2
|
echo "Usage: ${0} index|check|recover" >&2
|
||||||
die 6
|
die 6
|
||||||
fi
|
fi
|
||||||
|
|
||||||
die 0
|
die 0
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ start()
|
||||||
which hashboot.sh > /dev/null || return 1
|
which hashboot.sh > /dev/null || return 1
|
||||||
|
|
||||||
hashboot.sh check
|
hashboot.sh check
|
||||||
if [ $? == 4 ]
|
if [ $? -gt 0 ] && [ $? -le 3 ]
|
||||||
then
|
then
|
||||||
echo -n "Recover files? [y/N] "
|
echo -n "Recover files? [y/N] "
|
||||||
read -r yesno
|
read -r yesno
|
||||||
|
|
|
@ -19,7 +19,7 @@ case "$1" in
|
||||||
log_daemon_msg "Checking integrity of files in /boot"
|
log_daemon_msg "Checking integrity of files in /boot"
|
||||||
|
|
||||||
hashboot.sh check
|
hashboot.sh check
|
||||||
if [ $? == 4 ]
|
if [ $? -gt 0 ] && [ $? -le 3 ]
|
||||||
then
|
then
|
||||||
log_end_msg 4
|
log_end_msg 4
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue