#!/bin/sh # build_cbnts # # David Adams # October 2003 # For DIAL 0.60 # # Builds a CBNT dataset from each of the entries in a list of logical # files. # # E.g.: build dst_2001_10_magda # # Input: $1 - dataset name DSNAME # $2 - list of logical files (defaults to DSNAME.infiles) # Output: datasets/LFNAME.xml - DS representation for each logical file # idlists/DSNAME.ids - List of ID's for these datasets # # Output in $DSNAME.xml if [ "$1" = "-h" -o -z "$1" ]; then echo "Usage: $0 DSNAME" echo " Input: DSNAME.infiles - list of Magda logical files" exit 0 fi DSNAME=$1 INFILES=$DSNAME.infiles if [ -n "$2" ]; then INFILES=$2 fi FILE_CATALOG=MagdaFileCatalog DSDIR=datasets IDDIR=idlists IDLIST=$IDDIR/$DSNAME.ids # Make sure input file exists if [ ! -r $INFILES ]; then echo Unable to read input file $INFILES exit 1 fi # Make sure dataset directory exists if [ ! -d $DSDIR ]; then mkdir $DSDIR fi # Make sure idlist directory exists if [ ! -d $IDDIR ]; then mkdir $IDDIR fi # No action if output file already exists. if [ -r $IDLIST ]; then echo ID list already exists: echo " $IDLIST" echo "Please delete before recreating" exit 2 fi # Make CBNT datasets. for FILE in `cat $INFILES`; do XFILE=$DSDIR/$FILE.xml # make XML if it does not already exist. if [ ! -r $XFILE ]; then echo DID=`dataset_file_catalog -l $FILE 2>/dev/null` # Create dataset if it is not in the DFC. if [ -z "$DID" ]; then echo making CBNT dataset from $FILE make_cbnt_dataset -u -f $XFILE $FILE $FILE_CATALOG STAT=$? if [ $STAT != 0 ]; then echo Removing $IDLIST rm -f $IDLIST echo Error $STAT echo "Command: make_cbnt_dataset -u -f $XFILE $FILE $FILE_CATALOG" echo Updating badfiles.txt echo $FILE >> badfiles.txt echo Remove $FILE echo " from $INFILES" exit 3 fi # Put dataset in DDB echo ...inserting $XFILE in DDB DID=`dataset_insert -f $XFILE` STAT=$? if [ $STAT != 0 ]; then echo Removing $IDLIST rm -f $IDLIST echo Error $STAT echo When problem is resolved, either delete the dataset echo " "$XFILE echo or insert by hand with echo " dataset_insert -f $XFILE" exit 4 fi if [ -z "$DID" ]; then echo Insertion returned ID: $DID exit 5 fi # Add entry to DFC echo Inserting $DID in DFC dataset_file_catalog -w $DID else echo Dataset $DID is already in DDB for $FILE fi fi # Append ID to ID list. echo ...appending ID for $XFILE dataset_property -f $XFILE id >> $IDLIST STAT=$? if [ $STAT != 0 ]; then echo Error $STAT echo Removing $IDLIST rm -f $IDLIST exit 6 fi done