#!/bin/sh

rm -rf ./src/tmp/* || exit 1
vers=1.0.29

cd .. || exit 1

cp -p ssvnc/bin/ssvnc_cmd ssvnc/bin/tightvncviewer

###########################################
dest=./t.unix_only
rm -rf $dest
mkdir -p $dest || exit 1

tar cvf - ssvnc/{README,ReleaseNotes,COPYING,ssvnc.desktop} ssvnc/bin ssvnc/Unix | (cd $dest; tar xvf -)
rm -f $dest/ssvnc/bin/.linkin

tar=ssvnc_unix_only-${vers}.tar.gz
(cd $dest; tar czvf ../$tar ssvnc)
ls -l $tar
rm -rf $dest

###########################################
dest=./t.unix_minimal
rm -rf $dest
mkdir -p $dest || exit 1

tar cvf - ssvnc/{README,ReleaseNotes,COPYING,ssvnc.desktop} ssvnc/bin/{ss*,util/ss*} | (cd $dest; tar xvf -)

tar=ssvnc_unix_minimal-${vers}.tar.gz
(cd $dest; tar czvf ../$tar ssvnc)
ls -l $tar
rm -rf $dest

top='#!/bin/sh
n=11
tmp=`mktemp -d "/tmp/ssvnc.XXXXXX"` || exit 1
if [ "X$tmp" = "X" -o ! -d "$tmp" ]; then exit 1; fi
trap "cd /tmp; rm -rf $tmp" 0 2 15

tail -n +$n "$0" | (cd $tmp; tar xf -) || exit 1
$tmp/bin/ssvnc "$@"
exit 0
data__() {'

scr=./ssvnc.sh
echo "$top" > $scr
(cd ssvnc; tar cvf - README ReleaseNotes COPYING ssvnc.desktop bin/{ss*,util/ss*}) >> $scr
chmod 755 $scr
ls -l $scr

if [ "X$1" = "Xquick" ]; then
	exit 0
fi

###########################################
rm -f ssvnc_all-$vers.zip
rm -f ssvnc-$vers.zip
zip -9 -r ssvnc_all-$vers.zip ssvnc
zip -9 -r ssvnc-$vers.zip ssvnc -x '*.zip' '*.tar.gz'
tar cvf - --exclude='*.zip' --exclude='*.tar.gz' ssvnc | gzip -9 >  ssvnc-$vers.tar.gz
tar cvf - --exclude='*.zip' --exclude='*.tar.gz' --exclude='*.dll' --exclude='*.exe' --exclude ssvnc/Windows/util ssvnc | gzip -9 >  ssvnc_no_windows-$vers.tar.gz

echo
ls -l ssvnc*-$vers.*
echo


###########################################
dest=./t.windows_only
rm -rf ${dest}
mkdir -p $dest || exit 1

cp -pR ssvnc $dest
rm -rf $dest/ssvnc/{src,bin,man}
rm -rf $dest/ssvnc/MacOSX
rm -rf $dest/ssvnc/Unix
rm  -f $dest/ssvnc/build.unix
rm  -f $dest/ssvnc/filelist.txt
cp -p ssvnc/bin/util/ssvnc.tcl  $dest/ssvnc/Windows/util

zip=ssvnc_windows_only-${vers}.zip
rm -f $zip
(cd $dest; zip -9 -r ../$zip ssvnc)

ls -l $zip
rm -rf $dest


sync
echo
for g in ssvnc*-$vers*.gz
do
	md5sum $g
	gzip -t $g || (tput bel; sleep 2)
done
for g in ssvnc*-$vers*.zip
do
	md5sum $g
done

sleep 3
echo
