#!/bin/bash
#
# PICALib installation tool
# $Id: install,v 1.1 2002/06/22 18:33:31 cvs Exp $

# Read version
. VERSION

# Installation directories
if [ -z $LIBDIR ]; then
   LIBDIR=/opt/picalib/lib
fi
if [ -z $CONFDIR ]; then
   CONFDIR=/opt/picalib
fi

echo "Installing PICALib in:"
echo "  LIBDIR  : $LIBDIR"
echo "  CONFDIR : $CONFDIR"

modules=`find -type d -maxdepth 1`

for module in $modules; do
   if [ -f $module/MODINFO ]; then
      . $module/MODINFO
      echo "Installing Module: $MODULE"
      
      # Create target directories
      mkdir -p $LIBDIR/$MODULE
      mkdir -p $CONFDIR/$MODULE
      
      # Install LIBFILES
      for file in $LIBFILES; do
	 cp -a $module/$file $LIBDIR/$MODULE/$file
      done
      
      # Install CONFFILES
      for file in $CONFFILES; do
         if [ -f $CONFDIR/$MODULE/$file ]; then
	    if ! cmp -s $module/$file $CONFDIR/$MODULE/$file; then
	       echo "  Installing as $CONFDIR/$MODULE/$file.new"
	       cp -a $module/$file $CONFDIR/$MODULE/$file.new
	    fi
	 else
	    cp -a $module/$file $CONFDIR/$MODULE/$file
	 fi
      done
   fi
done

