#!/bin/sh indir=datasrc descfile=$indir/datadesc outdir=data filter=$1 process() { src_path=$1 dst_path=$2 op=$3 cmd=$(echo $op | sed 's//$src_path/g;s//$dst_path/g') export src_path export dst_path if ! eval $cmd; then fname=$(basename $src_path) echo "Failed to process data file $fname" >&2 echo "Command line was: \"$cmd\"" exit 1 fi } copy() { src_path=$1 dst_path=$2 if ! cp $src_path $dst_path; then fname=$(basename $src_path) echo "Failed to copy data file $fname" >&2 exit 1 fi } if [ -z "$filter" ]; then filter='.*' fi mkdir -p $outdir while read line; do line=$(echo $line | sed 's/#.*$//' | grep "$filter") if [ -n "$line" ]; then path=$(echo $line | awk -F : '{ print $1; }') fname=$(basename $path) op=$(echo $line | awk -F : '{ print $2; }' | xargs) if [ "$op" = nop ]; then echo copying $fname mkdir -p $outdir/$(dirname $path) copy $indir/$path $outdir/$path else echo processing $fname mkdir -p $outdir/$(dirname $path) process $indir/$path $outdir/$path "$op" fi fi done <$descfile