Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > 3b1c70357ba64c093a73a994f980ca3c > files > 16

schroot-1.2.3-5.fc13.i686.rpm

#!/bin/sh
# Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
#
# schroot 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 3 of the License, or
# (at your option) any later version.
#
# schroot 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, see
# <http://www.gnu.org/licenses/>.
#
#####################################################################

set -e

if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then
    . "$CHROOT_SCRIPT_CONFIG"
elif [ "$2" = "ok" ]; then
    echo "script-config file '$CHROOT_SCRIPT_CONFIG' does not exist"
    exit 1
fi

if [ "$AUTH_VERBOSITY" = "verbose" ]; then
  VERBOSE="--verbose"
fi

# Copy a file if the source and destination differ
# $1: source file
# $2: destination file
copy_file()
{
    if [ -r "$1" ]; then
	if [ -r "$2" ]; then

            # Device and inode
	    da=$(/usr/bin/stat --format="%d %i" "$1")
	    db=$(/usr/bin/stat --format="%d %i" "$2")

            # Content
	    ca=$(/usr/bin/md5sum "$1" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/')
	    cb=$(/usr/bin/md5sum "$2" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/')

	    # Copy if files are different
	    if [ "$da" != "$db" ]; then
		if [ "$ca" != "$cb" ]; then
		    cp $VERBOSE "$1" "$2"
		fi
	    fi

	else

	    # Copy if destination file does not exist
	    cp $VERBOSE "$1" "$2"

	fi

    else
	echo "W: Not copying nonexistent file: $file"
    fi
}

if [ $1 = "setup-start" ] || [ $1 = "setup-recover" ]; then

    if [ -n "$COPYFILES" ]; then
	if [ -f "$COPYFILES" ]; then
	    while read file; do
		if echo "$file" | grep -q '^/'; then
		    copy_file "$file" "${CHROOT_PATH}$file"
		else
		    echo "W: Not copying file with relative path: $file"
		fi
	    done < "$COPYFILES"
	else
	    echo "copyfiles file '$COPYFILES' does not exist"
	    exit 1
	fi
    fi

fi