#!@BASH@
# vim:syntax=sh
#
# Id :  $Id: authello.in 12258 2007-01-16 11:11:44Z hvddool $
# URL:  $URL: https://infix.uvt.nl/its-id/trunk/sources/authello/src/authello.in $
#
# Copyright (C) 2005, 2006 Tilburg University http://www.uvt.nl/
#
# This file is part of authello. Authello is free software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.  You should have received a copy of
# the GNU General Public License along with this file (see COPYING).
#
# authello
#
# generates a simple copy of the Authello script under a different name,
# copying and modifying only what you need te create your own helloworld
# perl script.
#
#  usage:
#   authello [full-path-to-directory-containing-authello-templates [yourprojectname]]
#
#  example:
#
#   joostvb@banach:~/tmp/a/scratch/fooproject% authello ~/svn/infix.uvt.nl/its-id/sources/authello fooproject
#
#  another example:
#
#       copy (+modify) the following files to a newly created location: example
#         authello/
#                  configure.in
#                  Makefile.am
#                 /src
#                  Makefile.am
#                  authello.in
#       cd example
#       example/configure [options]
#       make install
#

templatesdir=@DATADIR@/@PACKAGE@/templates

if test -z "$1"; then
  if test -z "$2"; then
    echo -n "second argument unset, choosing default "
    basename $(pwd)
    project=$(basename $(pwd))
  else
   project="$2"
  fi
  echo "first argument unset, choosing default $templatesdir"
  templates="$templatesdir"
else
  templates="$1"
fi

test -d src || mkdir src
if test -f configure.in; then
  echo Found existing configure.in.  Skipping install of template configure.in.
else
  sed -e "s/[Aa]uthello/$project/g" < $templates/configure.in | \
    grep -v bootstrap | grep -v actII > configure.in
fi

for f in Makefile.am bootstrap INSTALL.test; do
  if test -f $f; then
    echo Found existing $f.  Skipping install of template $f.
  else
    cp $templates/$f .
  fi
done

if test -f src/Makefile.am; then
  echo Found existing src/Makefile.am.  Skipping install of template src/Makefile.am
else
  sed -e "s/[Aa]uthello/$project/g;s/bootstrap//;s/actII//" < \
    $templates/src/Makefile.am > src/Makefile.am
fi

if test -f src/$project.in; then
  echo Found existing src/$project.in.  Skipping install of template src/$project.in.
else
  sed -e "s/[Aa]uthello/$project/g" < $templates/src/authello.in > src/$project.in
fi

if test -f src/$project.cf; then
  echo Found existing src/$project.cf.  Skipping install of src/$project.cf.
else
  cp $templates/src/authello.cf src/$project.cf
fi

# FIXME
touch NEWS README AUTHORS ChangeLog

cat <<EOT

                          *** NOTA BENE ***
The files configure, Makefile.in, Makefile, src/Makefile.in, src/Makefile
are automatically generated.  Do not edit them.  The files  bootstrap,
configure.in, Makefile.am, src/Makefile.am are sources, and should be edited
and maintained.  If you are using a Version Control System, you should register
those files.
                                 ***

EOT

echo -n "Do you want a test-install and run? [Y/n] "
read a
if test "n" = "$a"; then
   echo "OK, will quit now!"
   exit 0
fi

echo "Now running ./bootstrap ..."

sh ./bootstrap

echo "Now running ./configure ..."

./configure --prefix=/tmp/$project --bindir=$HOME/bin \
  --with-testlibdir=$HOME/testlib

echo "Now running \"make install\"..."

make install

echo "List of files installed:"

find /tmp/$project

echo "Now running $project..."

$project

echo "Displaying manpage..."

man -M /tmp/$project/man $project

#make uninstall

