mirror of https://schlomp.space/tastytea/hashboot
Fix bug where config file was not read on check
parent
f846a6155e
commit
f4f97d6f74
36
hashboot.sh
36
hashboot.sh
|
@ -4,12 +4,12 @@
|
||||||
#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 config file error
|
||||||
|
|
||||||
VERSION="0.7.3"
|
VERSION="0.7.4"
|
||||||
PATH="/bin:/usr/bin:/sbin:/usr/sbin:${PATH}"
|
PATH="/bin:/usr/bin:/sbin:/usr/sbin:${PATH}"
|
||||||
|
|
||||||
DIGEST_FILE="/var/lib/hashboot.digest"
|
DIGEST_FILE="/var/lib/hashboot.digest"
|
||||||
LOG_FILE="/tmp/hashboot.log"
|
LOG_FILE="/tmp/hashboot.log"
|
||||||
MBR_DEVICE="/dev/sda"
|
MBR_DEVICE=""
|
||||||
MBR_TMP="/tmp/mbr"
|
MBR_TMP="/tmp/mbr"
|
||||||
BACKUP_FILE="/var/cache/boot-backup.tar.gz"
|
BACKUP_FILE="/var/cache/boot-backup.tar.gz"
|
||||||
HASHER=""
|
HASHER=""
|
||||||
|
@ -29,6 +29,23 @@ die ()
|
||||||
exit ${1}
|
exit ${1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read_config ()
|
||||||
|
{
|
||||||
|
#Look for config file and set ${MBR_DEVICE}.
|
||||||
|
if [ -f ${CONFIG_FILE} ]
|
||||||
|
then
|
||||||
|
MBR_DEVICE=$(grep ^mbr_device ${CONFIG_FILE} | awk '{print $3}')
|
||||||
|
[ $? != 0 ] && die 9 "Error reading config file"
|
||||||
|
#If not found, create one and ask for ${MBR_DEVICE}
|
||||||
|
else
|
||||||
|
echo -n "Which device contains the MBR? [/dev/sda] "
|
||||||
|
read -r MBR_DEVICE
|
||||||
|
[ -z "${MBR_DEVICE}" ] && MBR_DEVICE="/dev/sda"
|
||||||
|
echo "#Device with the MBR on it" > ${CONFIG_FILE}
|
||||||
|
echo "mbr_device = ${MBR_DEVICE}" >> ${CONFIG_FILE}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
#If we're not root: exit
|
#If we're not root: exit
|
||||||
if [ ${UID} -ne 0 ]
|
if [ ${UID} -ne 0 ]
|
||||||
then
|
then
|
||||||
|
@ -56,19 +73,7 @@ then
|
||||||
#If we found no hasher: exit
|
#If we found no hasher: exit
|
||||||
[ -z "${HASHER}" ] && die 5 "No hash calculator found"
|
[ -z "${HASHER}" ] && die 5 "No hash calculator found"
|
||||||
|
|
||||||
#Look for config file and set ${MBR_DEVICE}.
|
read_config
|
||||||
if [ -f ${CONFIG_FILE} ]
|
|
||||||
then
|
|
||||||
MBR_DEVICE=$(grep ^mbr_device ${CONFIG_FILE} | awk '{print $3}')
|
|
||||||
[ $? != 0 ] && die 9 "Error reading config file"
|
|
||||||
#If not found, create one and ask for ${MBR_DEVICE}
|
|
||||||
else
|
|
||||||
echo -n "Which device contains the MBR? [/dev/sda] "
|
|
||||||
read -r MBR_DEVICE
|
|
||||||
[ -z "${MBR_DEVICE}" ] && MBR_DEVICE="/dev/sda"
|
|
||||||
echo "#Device with the MBR on it" > ${CONFIG_FILE}
|
|
||||||
echo "mbr_device = ${MBR_DEVICE}" >> ${CONFIG_FILE}
|
|
||||||
fi
|
|
||||||
|
|
||||||
#Write header
|
#Write header
|
||||||
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${DIGEST_FILE}
|
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${DIGEST_FILE}
|
||||||
|
@ -96,6 +101,7 @@ elif [ "${1}" == "check" ]
|
||||||
then
|
then
|
||||||
COUNTER=0
|
COUNTER=0
|
||||||
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
|
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
|
||||||
|
read_config
|
||||||
|
|
||||||
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=noxfer || die 8
|
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M 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})
|
||||||
|
|
Loading…
Reference in New Issue