#!/bin/bash
#=============================================================================#
#                    Make cpio mage from fakeroot directory                   #
#=============================================================================#
# Requires:
#	hasher by Dmitry V. Levin (ldv)
#   	cpio
#=============================================================================#
# (C) Denis Smirnov <mithraen@freesource.info                     12.06.2006  #
#=============================================================================#
set +e

WORKDIR=`realpath $1`
touch "$2"
RESULT=`realpath $2`
chroot="$WORKDIR/chroot/"

T=`mktemp`
echo -en '/etc\0/etc/group\0/etc/passwd\0' > $T

cp -a `which cpio` $chroot/.host/

echo "Creating $RESULT" | csed '/.*/ p green' >&2
hsh-run "$WORKDIR" --rooter -- /.host/find / \
	-mindepth 1 \
	-name .in -prune -o \
	-name .out -prune -o \
	-name .host -prune -o \
	-name .fakedata -prune -o \
	-name .altlinux.img -prune -o \
	-wholename /usr/lib*/*fakeroot* -prune -o \
	-print0 \
	| grep -vz ^/etc$ \
	| grep -vz ^/etc/passwd$ \
	| grep -vz ^/etc/group$ \
	>> $T \
	2> /dev/null

hsh-run "$WORKDIR"  --rooter -- /.host/cpio \
	-0 -c --create --quiet > "$RESULT" < $T

rm -f $T

