#!/bin/ash -efu
#
# mki-image-prepare
#
# This file is part of mkimage
# Copyright (C) 2007-2009  Alexey Gladkov <gladkov.alexey@gmail.com>
#
# This file is covered by the GNU General Public License,
# which should be included with mkimage as the file COPYING.
#

. "${0%/*}"/mki-sh-functions
. "${0%/*}"/mki-sh-image-prepare

verbose "has started executing."

[ -d "$subchroot" ] ||
	hsh_initroot "$subdir"

ln $verbose -nsf -- "$WORKDIRNAME/chroot" "$chroot/.image"

[ -f "$chroot/.fakedata" -a -f "$chroot/.image/.fakedata" ] ||
	exit 0

inode1="$(stat -c '%i' "$chroot/.fakedata")"
inode2="$(stat -c '%i' "$chroot/.image/.fakedata")"
[ "$inode1" != "$inode2" ] ||
	exit 0

mki-run chmod 666 /.fakedata
cat "$chroot"/.image/.fakedata >> "$chroot"/.fakedata
mki-run chmod 644 /.fakedata

rm -f -- "$chroot"/.image/.fakedata

ln -- "$chroot"/.fakedata "$chroot"/.image/.fakedata
