#! /bin/bash

# Preparations
package_name="loops-1.1.0"
package_dep="/Raktar/LOOPS_Packages"
nagyg_maths="/home/nagyg/Maths/2006"

rm -f $package_dep/$package_name-win.zip
rm -f $package_dep/$package_name.tar.gz

# determine all ASCII files

echo "Determining all ASCII files"

cd $nagyg_maths/pkg
files=""
for i in $( find ) ;
do
    a=$( file -i $i | grep text/plain )
    if [  "$a" != "" ]; then
	files="$files $i"
    fi	
done


# turn all ASCII files to DOS format

echo "Turning all ASCII files to DOS format"


for i in $files ;
do
    unix2dos $i &> /dev/null
done	

# make the -win.zip file

echo "Making the -win.zip file"
zip -r $package_dep/$package_name-win.zip \
	README.loops loops/* \
	&> /dev/null

# turn all ASCII files but loops_manual.txt to UNIX format

echo "Turning all ASCII files but loops_manual.txt to UNIX format"
for i in $files ;
do
    dos2unix $i &> /dev/null
done

# chmod clean_docus, make_docus, pack 

echo "Change mode for clean_docus, make_docus and pack"
chmod 	uog+x \
	loops/etc/make_docus \
	loops/etc/convert.pl \
	loops/etc/pack 

# make the .tar.gz file

echo "Making the .tar.gz file"
tar -czf $package_dep/$package_name.tar.gz \
	README.loops loops/* 