#!/bin/bash
#############################################################################
##
## This file is part of Taurus, a Tango User Interface Library
## 
## http://www.tango-controls.org/static/taurus/latest/doc/html/index.html
##
## Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
## 
## Taurus is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## 
## Taurus is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Lesser General Public License for more details.
## 
## You should have received a copy of the GNU Lesser General Public License
## along with Taurus.  If not, see <http://www.gnu.org/licenses/>.
##
#############################################################################
#This is a helper script for creating the man pages of the taurus scripts 
#It requires the help2man utility to be installed
#This is a quick-and-dirty solution for taurus maintenance only --don't complain about bugs!

DOCDIR=`pwd`
SETUPDIR="$DOCDIR/../"

# Install into a temp dir to get the scripts
TMPDIR=`mktemp -d`
echo $TMPDIR
TMPLIBDIR=$TMPDIR/lib
TMPBINDIR=$TMPDIR/bin
cd $SETUPDIR
export PYTHONPATH=$TMPLIBDIR:$PYTHONPATH
python setup.py install --root=$TMPDIR --install-lib=lib --install-scripts=bin


SCRIPTSDIR=$TMPBINDIR
cd $SCRIPTSDIR

rm $DOCDIR/*.1

echo $SCRIPTSDIR
for f in `ls`
  do echo "--------------------"
  # remove "-alpha" (and other -xxx) from the version if present
  V=`./$f --version 2>/dev/null |egrep -o '[0-9]+.[0-9]+(.[0-9])?'`
  echo help2man -N -o "$DOCDIR/man/$f.1" --version-string=$V ./$f
  help2man -N -o "$DOCDIR/man/$f.1" --version-string=$V ./$f
  # scripts are installed with 755 permissions, but manpages should be 644
  chmod 644 "$DOCDIR/man/$f.1"
  done

cd $DOCDIR

rm -rf $TMPDIR
