#!/bin/sh

# $Id$

#For all registered failed multiple copies, make the multiple copy.

set -u  # force better programming and ability to use check for not set
if [ "${1:-}" = "-x" ] ; then set -xv; shift; fi


#Make sure to set a timeout.
timeout='--timeout 10 --retries 3'

#First obtain the directory to write the output.
spool_dir=`enstore conf $timeout --show crons spool_dir`
if [ $? -ne 0 -o -z "$spool_dir" ]; then
    echo Spool directory not specified in configuration.  1>&2
    echo Add spool_dir to the crons section in the configuration.  1>&2
    exit 1
fi
if [ ! -d "$spool_dir" ]; then
    echo Spool directory $spool_dir not found.  Creating. 1>&2
    mkdir -p $spool_dir
    if [ $? -ne 0 ]; then
        echo Unable to create spool directory.  Aborting. 1>&2
        exit 1
    fi
fi


#  Run the duplication to make the lost multiple copies after the fact.

$ENSTORE_DIR/src/duplicate_chimera.py --with-final-scan --spool-dir $spool_dir --make-failed-copies
