#!/bin/sh
#
# These are functions used by the scripts that check the
# data partitions.
#

# Partition mounting.
#
mount_ro ()
{
        mount -t ext2 -o ro $1 /mnt
}

mount_rw ()
{
        mount -t ext2 $1 /mnt
}

remount_ro ()
{
        mount -t ext2 -o remount,ro $1 /mnt
}

remount_rw ()
{
        mount -t ext2 -o remount $1 /mnt
}

# This checks to see if the files exist on a partition, and if so,
# if they verify.
#
# INPUT:        $1 = /dev/mtdblockX
#
# OUTPUT:       0 = Files are there, and they verify.
#               1 = Files not found.
#               2 = Files are there, but do not verify.
#
file_verify ()
{
# See if the files exist.
#
if [ -e /mnt/cfg*tgz ] && [ -e /mnt/cfg*sum ]
then
        cfg_file=$(ls /mnt/cfg*tgz)
        sum_file=$(ls /mnt/cfg*sum)
else
        # echo "Files not found on $1..."
        return 1
fi

# See if the files verify.
#
if [ $(cksum $cfg_file | cut -d" " -f1) = $(cat $sum_file) ]
then
        # echo "$1 files verify!"
        return 0
else
        # echo "$1 files do not verify!"
        return 2
fi
}
