#!/bin/sh
# --------------------------------------------------------------------------
# Copyright 1993-1994 by Forschungszentrum Informatik (FZI)
# All rights reserved.
#
# You can use and distribute this software under the terms of the license
# you should have received along with this software; either version 1.1 of
# the license, or (at your option) any later version.
# For a copy of the license or for additional information about this software,
# write to Xcc Software, Durlacher Allee 53, D-76131 Karlsruhe, Germany;
# Email: obst@xcc-ka.de.
# --------------------------------------------------------------------------
# '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/* 

# create, clear & copy touch directory
MTAstuff=touch
rm -f $to/$MTAstuff/*
[ -d $from/$MTAstuff ] && (cd $from; tar cf - $MTAstuff) | (cd $to; tar xpf -) 

# 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 xpf -)

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

exit 0
