#
# DESCRIPTION
#
#     verify md5 sums of system image 
#
# part of the LiveBackup project:  
#
#                     http://livebackup.sourceforge.net/
#
# Copyright 2006-2010 by Wolfgang Rohrmoser <info@rohrmoser-engineering.de>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

if [ "$MD5VERIFY" = "yes" ]; then

    cd $MEDIA_MNT/system/
    md5file=""

    case "$image_format" in

	directory)
	md5file="$SYSTEM.md5"
	;;

	cloop)
	md5file="$SYSTEM.cloop.md5"
	;;

	squashfs)
	md5file="$SYSTEM.sqsh.md5"
	;;

	diskimage)
	md5file="$SYSTEM.img.md5"
	;;

	*)
        msg -c "FATAL:  !! unsupported image format in $0!!"
	exit 1
    esac
    
    if [ -f $md5file ]; then
	msg -i "verify image, please wait .."
	out=$(md5sum -c $md5file)
	ret=$? 
	msg -i "$out"
	if [ $ret -ne 0 ]; then
	    msg -c "CRITICAL: md5 sum verification failed, continue anyway ? (y/N): "
	    read ans
	    if [ $ans != "y" ]; then
		exit 1
	    fi
	fi
    else
	msg -w "WARNING: cannot find $MEDIA_MNT/system/$md5file, skipping verification .."
    fi

fi



#
# Local Variables: 
# mode: shell-script
# End: 
#


