#! /bin/sh
#
# module :
# ++ working on getsaxo.xml before processing for HTML and wiki
#
# TODO
# ====
#
# file in/out parameters to be usable correctly in makefile
#
# update :
# $Id$
#
# fplod 2008-04-15T10:53:26Z aedon.locean-ipsl.upmc.fr (Darwin)
# creation from makehtml.sh
# adapation to docbook 5.0
#
set -u
set -o posix
#
case $( whoami ) in
    smasson)
        lgforge=smasson
    ;;
    floseb)
        lgforge=smasson
    ;;
    *)
        lgforge=saxo
    ;;
esac
#
# size of SRC and DATA with .svn
szallsvn=$( du -sh ../../.. | awk '{print $1}' )
szallsvn=${szallsvn%*M}
# size of SRC with .svn
szsrcsvn=$( du -sh ../../../SRC | awk '{print $1}' )
szsrcsvn=${szsrcsvn%*M}
# size of DATA with .svn
szdatasvn=$( du -sh ../../../DATA | awk '{print $1}' )
szdatasvn=${szdatasvn%*M}
#
echo "iii : you will be asked ${lgforge}@forge.ipsl.jussieu.fr passwd two times"
#
# find the most recent SAXO_SRC_yyyymmddrxxx.tar.gz in
# /ipsl/forge/projets/saxo/download/
infosrc=$(ssh ${lgforge}@forge.ipsl.jussieu.fr ls -lht /ipsl/forge/projets/saxo/download/SAXO_SRC_*.tar.gz  | head -n 1)
filesrc=$(echo ${infosrc} | awk '{print $NF}')
szsrc=$(echo ${infosrc} | awk '{print $5}')
#
# ndate is the date in the file SAXO_SRC_*.tar.gz
ndate=${filesrc##*_}
ndate=${ndate%.tar.gz}
#
# find the most recent SAXO_DATA_yyyymmddrxxx.tar.gz in
# /ipsl/forge/projets/saxo/download/
infodata=$(ssh ${lgforge}@forge.ipsl.jussieu.fr ls -lht /ipsl/forge/projets/saxo/download/SAXO_DATA_*.tar.gz | head -n 1)
filedata=$(echo ${infodata} | awk '{print $NF}')
szdata=$(echo ${infodata} | awk '{print $5}')
#
# ndate2 is the date in the file SAXO_DATA_*.tar.gz
ndate2=${filedata##*_}
ndate2=${ndate2%.tar.gz}
#
sed -e s/"\&date\;"/${ndate}/g \
    -e s/"\&date2\;"/${ndate2}/g \
    -e s/"\&szsrc\;"/${szsrc}/g \
    -e s/"\&szdata\;"/${szdata}/g \
    -e s/"\&szallsvn\;"/${szallsvn}/g \
    -e s/"\&szsrcsvn\;"/${szsrcsvn}/g \
    -e s/"\&szdatasvn\;"/${szdatasvn}/g \
    getsaxo.xml > getsaxo_sed.xml
#
# exit
exit 0
