#!/bin/bash
# Intended to be run on a replica machine to rsync shelved files where the verify -t schedules the wrong file.
export SDP_INSTANCE=${SDP_INSTANCE:-Undefined}
export SDP_INSTANCE=${1:-$SDP_INSTANCE}
if [[ $SDP_INSTANCE == Undefined ]]; then
   echo "Instance parameter not supplied." 
   echo "You must supply the Perforce instance as a parameter to this script." 
   exit 1
fi

source /p4/common/bin/p4_vars $SDP_INSTANCE

$P4BIN info | grep insensitive > /dev/null 2>&1

if [[ $? -eq 0 ]]; then
    grep MISSING $LOGS/p4verify.log | cut -d "#" -f 1 | sed "s#^info: /##g" | sed "s/\(.*\)/\L\1/g" | sed "s#\(^.*$\)#rsync -av \${RSYNCUSER}@\${P4MASTERHOST}:/p4/\${SDP_INSTANCE}/depots\1,d/ /p4/\${SDP_INSTANCE}/depots\1,d/#g" > ${P4TMP}/temp_rsync.sh
else
    grep MISSING $LOGS/p4verify.log | cut -d "#" -f 1 | sed "s#^info: /##g" | sed "s#\(^.*$\)#rsync -av \${RSYNCUSER}@\${P4MASTERHOST}:/p4/\${SDP_INSTANCE}/depots\1,d/ /p4/\${SDP_INSTANCE}/depots\1,d/#g" > ${P4TMP}/temp_rsync.sh
fi
bash ${P4TMP}/temp_rsync.sh > /dev/null 2>&1
rm ${P4TMP}/temp_rsync.sh
