mirror of https://schlomp.space/tastytea/hashboot
die better
parent
d41028875c
commit
0c3bd88246
25
hashboot.sh
25
hashboot.sh
|
@ -24,6 +24,7 @@ function die
|
||||||
umount /boot
|
umount /boot
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[ -z "${2}" ] || echo "${2}" >&2
|
||||||
exit ${1}
|
exit ${1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,8 +32,7 @@ function die
|
||||||
#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
|
die 4 "You have to be root"
|
||||||
die 4
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Try different hashers, use the most secure
|
#Try different hashers, use the most secure
|
||||||
|
@ -44,11 +44,7 @@ test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha224sum 2> /dev/null)
|
||||||
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha1sum 2> /dev/null)
|
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot sha1sum 2> /dev/null)
|
||||||
test -z ${HASHER} && HASHER=$(/usr/bin/which --skip-dot md5sum 2> /dev/null)
|
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} ]
|
[ -z ${HASHER} ] && die 5 "No hash calculator found"
|
||||||
then
|
|
||||||
echo "No hash calculator found" >&2
|
|
||||||
die 5
|
|
||||||
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
|
||||||
|
@ -63,11 +59,7 @@ then
|
||||||
if [ -f ${CONFIG_FILE} ]
|
if [ -f ${CONFIG_FILE} ]
|
||||||
then
|
then
|
||||||
MBR_DEVICE=$(grep mbr_device ${CONFIG_FILE} | awk '{print $3}')
|
MBR_DEVICE=$(grep mbr_device ${CONFIG_FILE} | awk '{print $3}')
|
||||||
if [ $? != 0 ]
|
[ $? != 0 ] && die 9 "Error reading config file"
|
||||||
then
|
|
||||||
echo "Error reading config file" >&2
|
|
||||||
die 9
|
|
||||||
fi
|
|
||||||
#If not found, create one and ask for ${MBR_DEVICE}
|
#If not found, create one and ask for ${MBR_DEVICE}
|
||||||
else
|
else
|
||||||
echo -n "Which device contains the MBR? [/dev/sda] "
|
echo -n "Which device contains the MBR? [/dev/sda] "
|
||||||
|
@ -88,8 +80,7 @@ then
|
||||||
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
|
die 7 "Error writing ${DIGEST_FILE}"
|
||||||
die 7
|
|
||||||
fi
|
fi
|
||||||
#Backup of good files
|
#Backup of good files
|
||||||
tar -czpPf ${BACKUP_FILE} ${MBR_TMP} /boot ${DIGEST_FILE}
|
tar -czpPf ${BACKUP_FILE} ${MBR_TMP} /boot ${DIGEST_FILE}
|
||||||
|
@ -97,8 +88,7 @@ then
|
||||||
then
|
then
|
||||||
echo "Backup written to ${BACKUP_FILE}"
|
echo "Backup written to ${BACKUP_FILE}"
|
||||||
else
|
else
|
||||||
echo "Error writing ${BACKUP_FILE}" >&2
|
die 7 "Error writing ${BACKUP_FILE}"
|
||||||
die 7
|
|
||||||
fi
|
fi
|
||||||
elif [ "${1}" == "check" ]
|
elif [ "${1}" == "check" ]
|
||||||
then
|
then
|
||||||
|
@ -136,8 +126,7 @@ then
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "Usage: ${0} index|check|recover" >&2
|
die 6 "Usage: ${0} index|check|recover"
|
||||||
die 6
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
die 0
|
die 0
|
||||||
|
|
Loading…
Reference in New Issue