read_config does not need to be a function

pull/1/head
tastytea 2015-10-04 18:44:36 +02:00
parent 9192d4b225
commit 6a7d3eaf24
1 changed files with 28 additions and 35 deletions

View File

@ -38,8 +38,30 @@ die ()
exit ${1} 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}. #Look for config file and set ${MBR_DEVICE}.
if [ -f ${CONFIG_FILE} ] if [ -f ${CONFIG_FILE} ]
then then
@ -68,32 +90,6 @@ read_config ()
then then
die 1 "Something went wrong. Most likely your partition table is corrupt. Use hashboot recover to fix this." die 1 "Something went wrong. Most likely your partition table is corrupt. Use hashboot recover to fix this."
fi 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" ] if [ "${1}" == "index" ]
then then
@ -108,8 +104,6 @@ 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"
read_config
#Exists ${DIGEST_FILE}, if true run du magic, else write ${DIGEST_FILE} #Exists ${DIGEST_FILE}, if true run du magic, else write ${DIGEST_FILE}
if [ -f ${DIGEST_FILE} ] if [ -f ${DIGEST_FILE} ]
then then
@ -146,7 +140,6 @@ 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=${MBR_SIZE}K count=1 status=noxfer || die 8 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}) if ! $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE})