#!/bin/bash

# Vorgezogener fsck, falls ein MountCount +1 = MaxMountCount

DrivesToCheck="/dev/hda1 /dev/hda6 /dev/hda7 /dev/hda8 /dev/hdb1"
GraphLcdConf=/etc/graphlcd.conf
GraphLcdType=t6963c
FsckSplash=/etc/vdr/plugins/graphlcd/splash/fsck/240x128-fsck_00.glcd  
showpic=/etc/vdr/plugins/graphlcd/glcd-base/bin/showpic

#showpic library path
LD_LIBRARY_PATH=/etc/vdr/plugins/graphlcd/glcd-base/lib
export LD_LIBRARY_PATH
PATH=/bin:/sbin

for HDD in $DrivesToCheck
do
RunFsck="false"
MountCount=`tune2fs -l $HDD | grep "Mount count" | cut -c 27-`
echo "Mount Count from $HDD = $MountCount"
MaxMountCount=`tune2fs -l $HDD | grep "Maximum mount count" | cut -c 27-`
echo "Max Mount Count from $HDD = $MaxMountCount"
let MountCountZahl=$MountCount+1
if [ $MountCountZahl -ge $MaxMountCount ]
then
RunFsck="true"
echo "---Run fsck for $HDD is needed---"
if [ $RunFsck == "true" ]; then
touch /etc/mtab
if [ $? -eq 0 ]
then
echo "---RootFS still mounted, skipping run of fsck on $HDD!!!---"
else
echo "---Now starting fsck on $HDD---"
$showpic -c $GraphLcdConf -d $GraphLcdType $FsckSplash &
STPID=$!
fsck -C0 -y -f $HDD
echo "---Filesystemcheck is done on $HDD---"
fi
fi
else
echo "---No Need to run fsck on $HDD---"
fi
done