mirror of https://schlomp.space/tastytea/hashboot
introduce config file for MBR location
parent
85b5f869c6
commit
84ffb6cbd7
21
hashboot.sh
21
hashboot.sh
|
@ -2,7 +2,7 @@
|
||||||
#Hashes all files in /boot to check them during early boot
|
#Hashes all files in /boot to check them during early boot
|
||||||
#Exit codes: 0 = success, 1 = checksum mbr mismatch, 2 = checksum /boot mismatch,
|
#Exit codes: 0 = success, 1 = checksum mbr mismatch, 2 = checksum /boot mismatch,
|
||||||
#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
|
#7 = write error, 8 = dd error, 9 config file error
|
||||||
|
|
||||||
VERSION="0.7.1"
|
VERSION="0.7.1"
|
||||||
PATH="/bin:/usr/bin:/sbin:/usr/sbin"
|
PATH="/bin:/usr/bin:/sbin:/usr/sbin"
|
||||||
|
@ -14,6 +14,7 @@ MBR_TMP="/tmp/mbr"
|
||||||
BACKUP_FILE="/var/cache/boot-backup.tar.gz"
|
BACKUP_FILE="/var/cache/boot-backup.tar.gz"
|
||||||
HASHER=""
|
HASHER=""
|
||||||
BOOT_MOUNTED=0
|
BOOT_MOUNTED=0
|
||||||
|
CONFIG_FILE="/etc/hashboot.cfg"
|
||||||
|
|
||||||
#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
|
||||||
|
@ -58,6 +59,24 @@ fi
|
||||||
|
|
||||||
if [ "${1}" == "index" ]
|
if [ "${1}" == "index" ]
|
||||||
then
|
then
|
||||||
|
#Look for config file and set ${MBR_DEVICE}.
|
||||||
|
if [ -f ${CONFIG_FILE} ]
|
||||||
|
then
|
||||||
|
MBR_DEVICE=$(grep mbr_device ${CONFIG_FILE} | awk '{print $3}')
|
||||||
|
if [ $? != 0 ]
|
||||||
|
then
|
||||||
|
echo "Error reading config file" >&2
|
||||||
|
die 9
|
||||||
|
fi
|
||||||
|
#If not found, create one and ask for ${MBR_DEVICE}
|
||||||
|
else
|
||||||
|
echo "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}"
|
||||||
|
fi
|
||||||
|
|
||||||
#Write header
|
#Write header
|
||||||
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${DIGEST_FILE}
|
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${DIGEST_FILE}
|
||||||
#Write MBR of MBR_DEVICE to ${DIGEST_FILE}
|
#Write MBR of MBR_DEVICE to ${DIGEST_FILE}
|
||||||
|
|
Loading…
Reference in New Issue