#
#
# Does a build in a Debian/Ubuntu VM by
# - copy tar.gz to the vm
# - unpack
# - execute make_deb
# - copy back the generated deb package to outgoing

. scripts/build_package_prepare_upload_unpack

logpath=log
if test "$outdir" != ""; then
        logpath="$outdir/log"
fi

echo "Building"
if test "$autobuild" == 1; then
scripts/runcmd  -m=".* Entering directory" -l=$logpath.$caller.`whoami` $sshcmd $target_host \"cd $target_build_dir/`basename $source_tar .tar.gz`\; fakeroot ./make_deb\"
else
scripts/runcmd  -n=$caller -m=".* Entering directory" -l=$logpath.$caller.`whoami` $sshcmd $target_host \"cd $target_build_dir/`basename $source_tar .tar.gz`\; fakeroot ./make_deb\"
fi
if [ $? -ne 0 ]; then
	echo "$0 failed"
	exit 1
fi

outgoing=$outdir
if test "$outgoing" = ""; then
        outgoing="outgoing"
fi


echo "Downloading deb"
$scpcmd $target_host:$target_build_dir/*.deb $outgoing/

echo "Downloading deb to repository dir"
$scpcmd $target_host:$target_build_dir/*.deb repo/ubuntu/binary
$scpcmd $target_host:$target_build_dir/*.tar.gz repo/ubuntu/source
$scpcmd $target_host:$target_build_dir/*.dsc repo/ubuntu/source

echo "Done"

