#!/bin/sh
# **********************************************************
# *                                                        *
# *  Make an RDA Developer's NDA Source Code Release File  *
# *                                                        *
# **********************************************************
# File: utils/install/RdaDevelSource
#
#   COPYRIGHT (c) 2003, 2004, 2005, 2006, 2007, 2008, 2010 BY
#         VAISALA INC., WESTFORD MASSACHUSETTS, U.S.A.
# 
# THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
# ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
# INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
# COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
# OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
# TRANSFERED.

BASENAME="rda-source"

VERSION="`show_machine_code --version | sed 's/ *$//' | sed 's/.* //'`"

IRIS_REL=${IRIS_ROOT}"/builds/rda-${VERSION}/"
IRIS_INS=${IRIS_ROOT}"/install/"

ORIGINAL_DIR=`pwd`
SOURCE_ROOT=${ORIGINAL_DIR%/*/*}

FTPNAME="ftp.sigmet.vaisala.com"
PUBLICNAME="/var/ftp/outgoing/releases/developer/rda/${BASENAME}-${VERSION}.tgz"

if [ -z ${FTP_USER} ] ; then
  SIGMET_FTP_USER=$USER
else
  SIGMET_FTP_USER=${FTP_USER}
fi

# The original release directory had better be there, but not the file
# we're about to create.
#
if [ ! -d ${IRIS_REL} ] ; then
  echo "Sorry, '${IRIS_REL}' does not yet exist.  You must build"
  echo "  a standard RDA release first before adding the developer's source"
  echo "  files to it."
  exit 1
fi
if [ -r "${IRIS_REL}${BASENAME}.tgz" ] ; then
  echo "Sorry, ${IRIS_REL}${BASENAME}.tgz already exists.  Please manually"
  echo "  delete the existing file if you really intend to recreate it."
  exit 1
fi

# Build a special source file just for developers.  This consists of
# the standard source plus the NDA source.  We combine everything into
# one so that there is still just one source file to install in the
# end.
#
echo "Making ${IRIS_REL}${BASENAME}.tgz..."

RDASOURCEARGS=""
if [ -r ${SOURCE_ROOT}/rda/embedded/include ] ; then
  RDASOURCEARGS="${RDASOURCEARGS} -source rda/embedded/include"
fi
if [ -r ${SOURCE_ROOT}/rda/intelipp ] ; then
  RDASOURCEARGS="${RDASOURCEARGS} -source rda/intelipp"
fi
if [ -r ${SOURCE_ROOT}/rda/rvpxproc ] ; then
  RDASOURCEARGS="${RDASOURCEARGS} -source rda/rvpxproc/open"
  RDASOURCEARGS="${RDASOURCEARGS} -source rda/rvpxproc/site"
fi

rm -f ${IRIS_REL}${BASENAME} ${IRIS_REL}${BASENAME}.tgz

${IRIS_INS}make_iris_tape -rda -stdout 8 ${RDASOURCEARGS} > ${IRIS_REL}${BASENAME}
gzip -S .tgz --best ${IRIS_REL}${BASENAME}

echo ""
  echo "Installing public file..."
  scp ${IRIS_REL}${BASENAME}.tgz ${SIGMET_FTP_USER}@${FTPNAME}:${PUBLICNAME}
  ssh ${SIGMET_FTP_USER}@${FTPNAME} chmod 660       ${PUBLICNAME}
