#!/bin/sh -e
#
# Copyright (c) 1999 Software Engineering Research Laboratory,
# Department of Computer Science, University of Colorado at Boulder.
# All rights reserved.
# 
# This software was developed by the Software Engineering Research
# Laboratory of the University of Colorado at Boulder.  Redistribution
# and use in source and binary forms are permitted provided that:
# 
#    1. The above copyright notice and these paragraphs are duplicated 
#       in all such forms and that any documentation, and other 
#       materials related to such distribution and use acknowledge 
#       that the software was developed by the Software Engineering 
#       Research Laboratory of the University of Colorado at Boulder.
#    2. The redistribution and use of this software are solely for 
#       non-commercial purposes.
# 
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#

#
# Script to create a new, empty, repository.
#
# $Id: createrepository,v 1.1 2002/05/02 14:42:32 carzanig Exp $
#

#
# Check number of arguments.
#
if [ $# -ne 1 ]
    then
	echo "Usage: $0 <repository directory>"
	exit 1
fi

#
# Check for possible existing directory.
#
if [ -d $1 ]
    then
	echo "$0: $1 repository exists already"
	exit 1
fi

#
# Checks for printf
#
ECHO=printf
$ECHO "\n" > /dev/null 2>&1 || ECHO='echo -n'

#
# Create the empty repository.
#
mkdir $1
chmod 700 $1
mkdir $1/ndb_artifacts
chmod 700 $1/ndb_artifacts
$ECHO "0" > $1/ndb_artifacts/ndb_artifactcntr
chmod 600 $1/ndb_artifacts/ndb_artifactcntr
ARTIFACT=$1/ndb_artifacts/ndb_artifact_nucm_root
mkdir $ARTIFACT
chmod 700 $ARTIFACT
touch $ARTIFACT.lock
chmod 600 $ARTIFACT.lock
$ECHO "1" > $ARTIFACT/ndb_versioncntr
chmod 600 $ARTIFACT/ndb_versioncntr
$ECHO "1" > $ARTIFACT/ndb_type
chmod 600 $ARTIFACT/ndb_type
VERSION=$ARTIFACT/ndb_version_1
mkdir $VERSION
chmod 700 $VERSION
touch $VERSION.lock
chmod 600 $VERSION.lock
touch $VERSION/ndb_contents
chmod 600 $VERSION/ndb_contents
touch $VERSION/ndb_contents.lock
chmod 600 $VERSION/ndb_contents.lock
$ECHO "1" > $VERSION/ndb_refcntr
chmod 600 $VERSION/ndb_refcntr
mkdir $VERSION/ndb_exports
chmod 700 $VERSION/ndb_exports
mkdir $VERSION/ndb_attributes
chmod 700 $VERSION/ndb_attributes
signature="NUCM REPOSITORY: $1/ndb_signature"
echo $signature > $1/ndb_signature
chmod 600 $1/ndb_signature
touch $1/ndb_log
chmod 600 $1/ndb_log
