#!/bin/bash

. buildsys/functions

ProcessArgs $*
Assert LoadConfigs
Assert SetupLogDir
Assert SetupResFile
Assert SetupRemoteLogDir

if [ "$KEEP_DIST" != "yes" ]
then
   echo "KEEP_DIST=SKIPPED" >> $RESFILE
   exit 0
fi

if [ "$DEP" = "none" ]
then
   VCPATH=../../../install/VC
else
   VCPATH=$DEPWORKDIR/install/VC
fi

cd $VCPATH || 
{ 
    exit 1; 
}

SetState ArchivingDistribution

echo "KEEP_DIST=RUNNING" >> $RESFILE
ArchiveLogs

mkdirOnStore -p $RLOGDIR/distro
RES=$?
if [ $RES = 0 ]
then
   for i in *
   do 
      if [ $RES = 0 ]
      then
         if [[ `echo "$i" | grep "TEST"` != "" ]]
         then
            echo "TEST installer not backed off ..."
         else
            Store $i distro/
            RES=$?
         fi
      fi
   done
fi

# Copy the list of features that are written as part of the dcps_build_dist to the distro
# section on the scoreboard.
if [ -f $DEPWORKDIR/features.txt ]
then
   Store $DEPWORKDIR/features.txt distros/
fi

if [ $RES = 0 ]
then
   exit 0
else
   exit 2
fi
