#!/bin/sh

[ ! "$STTA" ] && echo "STTA no set "  && exit 2

. $STTA/envprofile
PORTAL=/home2/eagora/stta/~downloads/files/last_develop_vers

$DEVTOOLS/cleanup

cd $WEBMINDIR

mkdir $WKDIR 2>$dn
[ ! -d $WKDIR ] && exit 2
chown root:bin $WKDIR
chmod 755 $WKDIR

tar cvf $WKDIR/$MODULE".tar" $MODULE >$dn
[ $? != 0 ] && exit 1
cd $WKDIR
tar xvf $MODULE".tar" >$dn
rm  $MODULE".tar"
cd $WKDIR/$MODULE

[ "$f_toremove" ]  && {
      for file in `echo $f_toremove `
      do
          rm $file 2>$dn
      done
}
        
[ "$d_toremove" ] && {
      for dir in `echo $d_toremove `
      do
          rm -r $dir 2>$dn
      done
}

mv envprofile.deploy envprofile
cat .brandinfofile | grep -v "stta/$TOOLSDIR/" >.brandinfofile.stta
cp -p .brandinfofile.stta .brandinfofile
      
[ "$PACKMAKER" ] && sh $DEVTOOLS/$PACKMAKER $WKDIR

cd $WKDIR

DIRDEST=$DESTPACK/$ahora
mkdir $DIRDEST 2>$dn
chown root:bin $DIRDEST
chmod 755 $DIRDEST
 
DEST=$DIRDEST/$SAVEFILE

tar cvf $DEST $MODULE >$dn
gzip -f $DEST

cd $origen
rm -r $WKDIR
echo "PACKED $MODULE  in $DEST ..."

[ -d "$PORTAL" ] && {
    cp  $DEST*gz $PORTAL
    cd $PORTAL
    eagor1sync $SAVEFILE.gz
    cp $STTA/module.info $PORTAL/module.info.txt
    eagor1sync module.info.txt
    cp $STTA/.brandinfofile $PORTAL/brandinfofile
    eagor1sync brandinfofile
    cd ../../files
    cp $STTA/.brandinfofile brandinfo.txt
    eagor1sync brandinfo.txt
    echo "$PORTAL updated !!! ..."
    echo "Files in queue  Waiting for FTP ..."
}

