#!/bin/sh

#mkdir -p -- "$WORKDIR/ALTLinux/base"

[ -d "$WORKDIR/ALTLinux/" ] || exit 0


substruct="asterisk-disk asterisk-base runa-disk runa-base disk-base"
while [ -n "$substruct" ] ; do
substruct_first=`echo $substruct | cut -d ' ' -f 1`
substruct=`echo $substruct | cut -s -d ' ' -f 2-10`
comp1=`echo $substruct_first | cut -s -d '-' -f 1`
comp2=`echo $substruct_first | cut -s -d '-' -f 2`

echo "comp1: $comp1 comp2: $comp2"

if [ -d "$WORKDIR/ALTLinux/RPMS.$comp2" ]; then
	/.host/find "$WORKDIR/ALTLinux/RPMS.$comp2" -type f -name '*.rpm' -printf '%f\n' |
	while read fn; do
			f="$WORKDIR/ALTLinux/RPMS.$comp1/$fn"

			[  -f "$f" ] && rm -vf -- "$f"
	done
fi
done


comps="$(/.host/find "$WORKDIR/ALTLinux/" -mindepth 1 -maxdepth 1 -type d -name 'RPMS.*' -printf '%f ' |
	sed -e 's/RPMS\.//g')"

genbasedir \
	--topdir="$WORKDIR" \
        --architecture="$INFO_ARCH" \
        --no-oldhashfile \
        --partial \
        --bz2only \
	--create \
        --notautomatic=false \
        ${INFO_NAME:+--archive="$INFO_NAME"} \
        ${INFO_VERSION:+--version="$INFO_VERSION"} \
        ${INFO_ORIGIN:+--origin="$INFO_ORIGIN"} \
        ${INFO_LABEL:+--label="$INFO_LABEL"} \
        ALTLinux $comps
