export V=$(cat .version)
echo $V

rm no-download

rm -r semantic_net_doc
rm -r knowledge
rm database.tmp
rm booted
rm dialog.txt
rm foo.db
rm tmon.out
rm Du
rm *.log
rm A B
rm svn-*
rm cache__*
rm cache__is_in.tmp

rm word_types.*

rm -rf JEliza-Windows/
rm -rf FreeHAL-Windows/
find . -name "jeliza-r*" -type d | xargs rm -rf
rm -rf JEliza-Perl-Linux-*
rm -rf FreeHAL-Linux-*

rm -rf dist
mkdir dist

cp -r * dist/
find dist -name '.svn' | xargs rm -rf
find dist -name '.svn' | xargs rm -rf
find dist -name '.svn' | xargs rm -rf

#aliased.pm      convert-word-types-dic.pl   header.template.html     jeliza-engine.pl  make-archives.sh   Socket-Class-1.13  wrapper.cpp
#Apache          display.cfg                 HeadParser.pm            jeliza-log.pl     Makefile.PL        Std.pm             wrapper.pl
#Authen          downloaded.html             HTML                     jeliza.pl         MANIFEST           test.pl            WWW
#auto            Entities.pm                 HTML-Parser-3.56         jeliza-shell.pl   Net                Text               XML
#background.jpg  enum                        HTTP                     kernel.exe        OldDocs            TokeParser.pm      XMLRPC
#Carp            Filter.pm                   IO                       lang_de           PullParser.pm      to-server.log      YAML
#Changes         footer-extra.template.html  jeliza.cfg               lang_en           README             UDDI               Zlib.pm
#Class           footer.template.html        jeliza-cgi-engine.pl     LICENSE           Regexp             version
#Clone-0.28      for-tts.txt                 jeliza-cgi.pl            Lingua            Regexp.pm          version.pm
#Clone.pm        grin.png                    jeliza-cgi-simple.pl     LinkExtor.pm      remove_entries.pl  wink.png
#Compress        Hash                        jeliza-console.pl        LWP               search-www.pl      word_types.brain
#Config          header-extra.template.html  jeliza-engine-backup.pl  LWP.pm            SOAP               word_types.dic


cd dist
rm -f *.pm dist -r make-archives.sh
rm -rf Apache Authen auto Carp Class Clone-0.28 Compress Config display.cfg downloaded.html enum for-tts.txt Hash HTML HTML-Parser-3.56 Algorithm
rm -rf HTTP IO *.exe LWP Net OldDocs Regexp SOAP Socket-Class-1.13 Text UDDI word_types.brain word_types.dic wrapper.cpp wrapper.pl WWW XML XMLRPC File
rm -rf Tie DBM autom4te.cache 
mv Changes NEWS
mkdir lib
mv Lingua YAML lang_de lang_en lib
find -type f | sed 's@\./@@igm' | grep -v svn | grep -v Clone | grep -v HTML-Parser | grep -v cgi | grep -v html | grep -v wrapper | grep -v Socket | grep -v backup | grep -v nano.save > MANIFEST
cd ..




rm -rf freehal-${V}
mv dist freehal-${V}
cd freehal-${V}
rm x x.pl *.sh *.exe
cd ..
tar cplSzf ../freehal_${V}_src.tgz freehal-${V}
rm -rf freehal-${V}

################

rm -rf dist
mkdir dist

cp -r * dist/
find dist -name '.svn' | xargs rm -rf
find dist -name '.svn' | xargs rm -rf
find dist -name '.svn' | xargs rm -rf

rm -rf FreeHAL-Linux-${V}
mv dist FreeHAL-Linux-${V}
cd FreeHAL-Linux-${V}

rm -r ../../JEliza/tmp/dist/linux/{lib,src}
cp -rf ../../JEliza/tmp/dist/linux/freehal .
cp -rf ../../JEliza/tmp/dist/linux/bin/freehal .
mkdir bin
cp -rf ../../JEliza/for-jeliza-perl-linux/freehal bin

rm x *.sh *.exe

cd ..
rm -rf freehal-${V}
mv FreeHAL-Linux-${V} freehal-${V}
tar cplSzf ../freehal_${V}_linux.tgz freehal-${V}
rm -rf freehal-${V}

#################

rm -rf dist JEliza-Perl-Windows FreeHAL-Windows JEliza-Perl-${V} FreeHAL-${V} JEliza-Windows FreeHAL
mkdir dist

cp -r ../FreeHAL\ Windows/FreeHAL-QT.exe ../FreeHAL\ Windows/kernel.exe dist/
cp -r ../FreeHAL\ Windows/mplayer.exe ../FreeHAL\ Windows/mplayer dist/
cp -r ../FreeHAL\ Windows/perl.exe dist/
cp -r ../FreeHAL\ Windows/tagger-perl.exe dist/
cp -r * dist/
rm dist/x.pl
find dist -name '.svn' | xargs rm -rf
find dist -name '.svn' | xargs rm -rf
find dist -name '.svn' | xargs rm -rf
cp ../jeliza-perl-permanent/JEliza-Windows/mingwm10.dll dist/

cd dist

rm -rf Apache Authen auto Carp Class Clone-0.28 Compress Config display.cfg downloaded.html enum for-tts.txt Hash HTML HTML-Parser-3.56 Algorithm
rm -rf HTTP IO LWP Net OldDocs Regexp SOAP Socket-Class-1.13 Text UDDI word_types.brain word_types.dic wrapper.cpp wrapper.pl WWW XML XMLRPC File
rm -rf Tie DBM autom4te.cache  File booted do-* *.txt *.log *.tmp

cd ..

cp ../FreeHAL\ Windows/Qt*.dll dist

rm -rf JEliza-Windows
mv dist JEliza-Windows
rm -rf JEliza-Windows/dist
rm JEliza-Windows/word_types.*

rm ../JEliza-Perl_${V}_windows.zip

mv JEliza-Windows FreeHAL

zip -r ../freehal_${V}_windows.zip FreeHAL 2>&1 > /dev/null

if [ "x$1" = "xbeta" ]
then
	true
else
	wine ~/.wine/drive_c/Programme/ISTool/ISCC.exe ../jeliza-perl.iss
fi


rm -rf JEliza-Windows FreeHAL

################

if [ "x$1" = "xbeta" ]
then
	rm /data/downloads/freehal/beta/*
	mv ../freehal_${V}_* /data/downloads/freehal/beta/
fi

touch no-download
