#!/bin/sh
# --------------------------------------------------------------------------
# Copyright 1993-1994 by Forschungszentrum Informatik (FZI)
#
# You can use and distribute this software under the terms of the license
# version 1 you should have received along with this software.
# If not or if you want additional information, write to
# Forschungszentrum Informatik, "OBST", Haid-und-Neu-Strasse 10-14,
# D-76131 Karlsruhe, Germany.
# --------------------------------------------------------------------------
# 'obst-cpcnt - 10.03.93 - Oliver Spatscheck'
#
# obst-cpcnt
#
# Copies the containers from $1 into $2.
# ('cp' denies copying a file onto itself.)
#
# Installs an empty a subdirectory 'process' in $2 and copies data
# managed by the OBST USE environment.

[ $# != 2 ] &&  \
   { echo >&2 "*** usage: obst-cpcnt source_dir destination_dir"; exit 1;}

from=$1
  to=$2

# check $from and create/check $to 
[ -d $from ] || { echo >&2 "$from is not a valid directory"; exit 1;}
[ -f $to ]   || [ -d $to ] || mkdir $to
[ -d $to ]   || { echo >&2 "can not create directory $to"; exit 1;}

# clear cnts & copy
rm -f $to/[0-9]*
cp -p $from/[0-9]* $to

# create & clear process directory
[ -d $to/process ] || mkdir $to/process
rm -f $to/process/* 

# clear & copy the version file (if available)
rm -f $to/version
[ -f $from/version ] && cp -p $from/version "$to"

# clear & copy USE data
USEstuff=.OBST_Browser

rm -rf $to/$USEstuff
[ -d $from/$USEstuff ] && (cd $from; tar cf - $USEstuff) | (cd $to; tar xf -)

# finalize: make writeable, mark containers as modified
chmod -Rf u+w  $to/[0-9]*  $to/$USEstuff
chmod -f  u+wx $to/process $to/$USEstuff
touch $to/[0-9]* $to/$USEstuff/* 2>/dev/null

exit 0

