#!/bin/bash

export S=../v1 A=x86_64

set -e 

export D=$(stat --printf "%Y" "$1")
! [ -d $D ]
mkdir $D
ln -sf $D last

find $S/$A/release/ -type f ! -newer "$1" ! -name "setup.hint" |
	while read s; do
		fn=${s##*/}
		sd=${s%/*}
		dd=$D/${sd#$S/}

		[ -d $dd ] || mkdir -p $dd
		[ -f $sd/setup.hint -a ! -f $dd/setup.hint ] && egrep -av "^(curr|prev):" $sd/setup.hint >$dd/setup.hint
			
		ln -s $(realpath --relative-to=$dd $s) $dd
	done

cd $D
ln -s ../$S/acceptable.lst
../$S/genini --arch=$A --recursive --output=$A/setup.ini $A/release

bzip2 <$A/setup.ini >$A/setup.ini.bz2
find $A -type l | fgrep -vxf <(sed -ne 's/\(install\|license\|source\): \([^ ]*\) .*$/\2/p' $A/setup.ini) | xargs rm
