#!/bin/sh

INCLDIR=../../include

if [ "$1" = "-y" ]; then
  REMOVE=/bin/true
  shift
else
  REMOVE=/bin/false
fi
if [ $# -ne 1 ]; then
  echo "usage: install-to-PAM pam-directory"
  echo ""
  echo "Run this program if you want to place this code into PAM tree"
  echo "Usual value for pam-directory is /usr/src/pam-0.66/Linux-PAM/modules"
  echo ""
  echo "Due to strangeness of static PAM modules do not forget, that static"
  echo "module links together with static libncp, resulting in very big"
  echo "object file (60KB without debugging info, 500KB with)."
  echo ""
  exit 1
fi
DEST=$1
if [ ! -d $DEST/. ]; then
  echo "$DEST does not exist or is not directory"
  exit 1
fi
if [ ! -f $DEST/register_static ]; then
  echo "$DEST is not module directory of PAM suite"
  exit 1
fi
if [ ! -f pam_ncp_auth.c ]; then
  echo "You must run this program from ncp_pam_auth plugin directory"
  exit 1
fi
if [ ! -f $INCLDIR/config.h ]; then
  echo "You must first run configure in ncpfs directory before running this program"
  exit 1
fi
DESTD=$DEST/pam_ncp_auth
if [ -d $DESTD ]; then
  if $REMOVE ; then
    echo "Removing old code from $DESTD"
    rm -rf $DESTD
  else
    echo "pam_ncp_auth is already present in $DEST"
    echo ""
    echo "Remove pam_ncp_auth or run this program with option -y"
    exit 1
  fi
fi
mkdir $DESTD
cp Makefile.pam $DESTD/Makefile
cp COPYING README *.c $DESTD
DESTI=$DESTD/include
mkdir $DESTI
for a in config.h ipxlib.h ncp.h ncplib.h; do
  cp $INCLDIR/$a $DESTI
done
mkdir $DESTI/ext
for a in socket.h; do
  cp $INCLDIR/ext/$a $DESTI/ext
done
mkdir $DESTI/kernel
for a in fs.h if.h ipx.h ncp.h ncp_fs.h route.h types.h; do
  cp $INCLDIR/kernel/$a $DESTI/kernel
done
echo "PAM module is ready for compilation (in $DESTD)"
