#!/bin/sh

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

cd .. || exit 1

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

tar cvf - ssvnc/{README,COPYING} 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,COPYING} ssvnc/bin/{ss*,util/ss*} ssvnc/Unix | (cd $dest; tar xvf -)
tar cvf - ssvnc/{README,COPYING} 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 "$0" | (cd $tmp; tar xf -) || exit 1
$tmp/bin/ssvnc "$@"
exit 0
data__() {'

scr=./ssvnc.sh
echo "$top" > $scr
(cd ssvnc; tar cvf - README COPYING 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

ls -l ssvnc*-$vers.*

###########################################
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

