#!/bin/sh

MODE=$1
SRC_PATH=$2
DES_PATH=$3
FILE_NAME=$4
FILE_NAME2=$5
echo "#### copy file : $MODE,$SRC_PATH,$DES_PATH,$FILE_NAME,$FILE_NAME2"
if [ -n "$DES_PATH" ]; then
        mkdir -p $DES_PATH
fi

case $MODE in
FILE) #1 file copy
        if [ -z "$FILE_NAME" ]; then
                echo "error empty file name"
                exit 1
        fi

        if [ -z "$FILE_NAME2" ]; then
                cp  $SRC_PATH/$FILE_NAME $DES_PATH/$FILE_NAME
        else 
                cp  $SRC_PATH/$FILE_NAME $DES_PATH/$FILE_NAME2
        fi;;
FILE2) #2 file copy
        if [ -z "$FILE_NAME" ]; then
                echo "error empty file name"
                exit 1
        fi

        if [ -z "$FILE_NAME2" ]; then
                cp  $SRC_PATH/$FILE_NAME* $DES_PATH/
        else 
                cp  $SRC_PATH/$FILE_NAME* $DES_PATH/
        fi;;
DIR) #2 dir copy
        cp -fr $SRC_PATH/* $DES_PATH;;
TAR) #3 use tar
        if [ -z "$FILE_NAME" ]; then
                echo "error empty file name"
                exit 1
        fi
        tar xf $SRC_PATH/$FILE_NAME -C $DES_PATH;;
*) # error unkown mode
        echo "error unkown mode"
        exit 1;;
esac
