#!/bin/sh

mkdir program-bz2/

cd data/

for a in *;
  do
  bzip2 -k "$a";
done

mkdir ../bzip2
mv *.bz2 ../bzip2

mkdir ../cat_bzip2
mkdir ../cat_file_bz2

for a in *;
  do
  for b in *;
    do
    if [ $a != $b ]
	then
	cat "$a" "$b" > ../cat_file_bz2/"$a"'_'"$b"
	bzip2 -k ../cat_file_bz2/"$a"'_'"$b"
	mv ../cat_file_bz2/*.bz2 ../cat_bzip2
    fi
  done
done

cd ../bzip2
(ls -l *.bz2 | awk '{print $9 " " $5}')  > ../program-bz2/filesize

cd ../cat_bzip2
(ls -l *.bz2 | awk '{print $9 " " $5}')  > ../program-bz2/filesize.cat

cd ../data
(ls -l * | awk '{print $9}')  > ../program-bz2/filename


cp ../kolmo2.class ../program-bz2
cp ../List.class ../program-bz2


cd ../program-bz2
java kolmo2 > fileout

cd ../
rm -rf cat_file_bz2
rm -rf cat_bzip2
rm -rf bzip2
