#!/bin/sh

if [ $# -lt 2 ] ; then
  echo "Usage: tc-image-copy <src_img> <dst/[img]> [img_size]"
  exit 1
fi

CREATECACHE=/home/tc/bin/tc-create-cache
FASTCOPY=/home/tc/bin/tc-fastcopy

src_img=$1
cache_file=/tmp/fastcopy.cache
blk_size=4096

if [ -d $2 ] ; then
  dst_img=$2/`basename $1`
else
  dst_img=$2
fi

if [ -z $3 ] ; then
  img_size=`stat -c %s "$src_img"`
else
  img_size=$3
fi

$CREATECACHE $src_img $img_size $cache_file $blk_size
ret=$?
if [ $ret -ne 0 ] ; then
  echo "create cache failed"
  exit $ret
fi

$FASTCOPY $src_img $dst_img $img_size $cache_file $blk_size

