#!/bin/bash
set -x

export LANG=en_US
export LC=C
export LC_ALL=C

RELEASE=3.2
PETSC_DIR=/home/balay/hg-repo/petsc-release-${RELEASE}

#automatically crankup the patchlevel
# ${PETSC_DIR}/bin/maint/createpatch
# /home/balay/spetsc/bin/maint/createpatch

#create the tarfile
${PETSC_DIR}/bin/maint/builddist ${PETSC_DIR}

#Now copy the generated tarfiles over to the website
PATCH_VERSION=`grep '^#define PETSC_VERSION_PATCH ' ${PETSC_DIR}/include/petscversion.h |tr -s ' ' | cut -d ' ' -f 3`
VERSION=${RELEASE}-p${PATCH_VERSION}
scp ~/petsc-${VERSION}.tar.gz petsc@login.mcs.anl.gov:/mcs/ftp/pub/petsc/release-snapshots/
scp ~/petsc-lite-${VERSION}.tar.gz petsc@login.mcs.anl.gov:/mcs/ftp/pub/petsc/release-snapshots/

# petsc.tar.gz/petsc-lite.tar.gz links are done manually
ssh petsc@login.mcs.anl.gov " \
  cd /mcs/ftp/pub/petsc/release-snapshots; \
  /bin/rm -f petsc-${RELEASE}.tar.gz petsc-lite-${RELEASE}.tar.gz ; \
  /bin/ln -s petsc-${VERSION}.tar.gz petsc-${RELEASE}.tar.gz; \
  /bin/ln -s petsc-lite-${VERSION}.tar.gz petsc-lite-${RELEASE}.tar.gz"

# Update download/index.html as well
ssh petsc@login.mcs.anl.gov chmod u+w /mcs/web/research/projects/petsc/download/index.html
scp ${PETSC_DIR}/src/docs/website/download/index.html petsc@login.mcs.anl.gov:/mcs/web/research/projects/petsc/download

#######################################
# M bin/maint/createpatch
# M bin/maint/rebuildtar
# M bin/maint/update-docs.py
# M include/petscversion.h
# M src/docs/tex/manual/intro.tex
# M src/docs/tex/manual/manual.tex
# M src/docs/website/documentation/changes/300.html
# M src/docs/website/documentation/changes/dev.html
# M src/docs/website/documentation/changes/index.html
# M src/docs/website/documentation/installation.html
# M src/docs/website/download/index.html
# M src/docs/website/index.html
# A src/docs/website/documentation/changes/31.html

# ? bin/win32fe/win32fe.exe
# ? bin/win32fe/win32feutils.dll

