mirror of https://schlomp.space/tastytea/hashboot
read_config does not need to be a function
parent
9192d4b225
commit
6a7d3eaf24
53
hashboot
53
hashboot
|
@ -38,8 +38,30 @@ die ()
|
|||
exit ${1}
|
||||
}
|
||||
|
||||
read_config ()
|
||||
write_hashes ()
|
||||
{
|
||||
#Write header to ${1}
|
||||
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${1}
|
||||
#Write MBR of MBR_DEVICE to ${1}
|
||||
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=${MBR_SIZE}K count=1 status=noxfer || die 8
|
||||
#Write hashes of all regular files to ${1}
|
||||
${HASHER} ${MBR_TMP} >> ${1}
|
||||
find /boot -type f -exec ${HASHER} --binary {} >> ${1} +
|
||||
}
|
||||
|
||||
#If we're not root: exit
|
||||
if [ ${UID} -ne 0 ]
|
||||
then
|
||||
die 4 "You have to be root"
|
||||
fi
|
||||
|
||||
#If /boot is in fstab but not mounted: mount, mark as mounted
|
||||
if grep -q '/boot.*noauto' /etc/fstab && ! grep -q /boot /etc/mtab
|
||||
then
|
||||
mount /boot
|
||||
BOOT_MOUNTED=1
|
||||
fi
|
||||
|
||||
#Look for config file and set ${MBR_DEVICE}.
|
||||
if [ -f ${CONFIG_FILE} ]
|
||||
then
|
||||
|
@ -68,32 +90,6 @@ read_config ()
|
|||
then
|
||||
die 1 "Something went wrong. Most likely your partition table is corrupt. Use hashboot recover to fix this."
|
||||
fi
|
||||
}
|
||||
|
||||
write_hashes ()
|
||||
{
|
||||
#Write header to ${1}
|
||||
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${1}
|
||||
#Write MBR of MBR_DEVICE to ${1}
|
||||
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=${MBR_SIZE}K count=1 status=noxfer || die 8
|
||||
#Write hashes of all regular files to ${1}
|
||||
${HASHER} ${MBR_TMP} >> ${1}
|
||||
find /boot -type f -exec ${HASHER} --binary {} >> ${1} +
|
||||
}
|
||||
|
||||
#If we're not root: exit
|
||||
if [ ${UID} -ne 0 ]
|
||||
then
|
||||
die 4 "You have to be root"
|
||||
fi
|
||||
|
||||
#If /boot is in fstab but not mounted: mount, mark as mounted
|
||||
if grep -q '/boot.*noauto' /etc/fstab && ! grep -q /boot /etc/mtab
|
||||
then
|
||||
mount /boot
|
||||
BOOT_MOUNTED=1
|
||||
fi
|
||||
|
||||
|
||||
if [ "${1}" == "index" ]
|
||||
then
|
||||
|
@ -108,8 +104,6 @@ then
|
|||
#If we found no hasher: exit
|
||||
[ -z "${HASHER}" ] && die 5 "No hash calculator found"
|
||||
|
||||
read_config
|
||||
|
||||
#Exists ${DIGEST_FILE}, if true run du magic, else write ${DIGEST_FILE}
|
||||
if [ -f ${DIGEST_FILE} ]
|
||||
then
|
||||
|
@ -146,7 +140,6 @@ elif [ "${1}" == "check" ]
|
|||
then
|
||||
COUNTER=0
|
||||
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
|
||||
read_config
|
||||
|
||||
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=${MBR_SIZE}K count=1 status=noxfer || die 8
|
||||
if ! $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE})
|
||||
|
|
Loading…
Reference in New Issue