#!/bin/bash

##################################
#   Author - Kulbir Saini        #
#   Home - http://saini.co.in/   #
##################################


if [ $1 == -i ] || [ $1 == -f ];then          
if [ ! -s $2 ] && [ ! -f $2 ] && [ ! -d $2 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "file:$2 doesn't exist.\nCan't copy...\nPress any key..." 5 30; read
elif [ ! $3 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "Invalid arguements...\nCan't copy...\nPress any key..." 5 30; read
elif [ -d $3 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "$3: is a directory.\nCan't copy...\nPress any key..." 5 30; read
elif [ -d $2 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "$2: is a directory.\nCan't copy...\nPress any key..." 5 30; read
elif [ -s $3 -o -f $3 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --yesno "Do you want to overwrite file:$3" 10 60;
select=$?
case $select in 
	0) echo -e "i'm ordered to overwrite file:$3 \noverwriting...\noverwritten file:$3" ; cp -f $2 $3 ;;
	1) echo "i'm ordered not to overwrite.";;
	255) echo "cancelled by you by pressing [Esc].";;
esac
else
	dialog --title "Copy daemon" --backtitle "copy:" --yesno "Do you want to copy the file:$2 to file:$3" 10 60 ;
select1=$?
case $select1 in
	0) echo -e "i'm ordered to copy file:$2 to file:$3 \ncopying...\ncopied to file:$3" ; cp $2 $3 ;;
	1) echo "i'm ordered not to copy.";;
	255) echo "cancelled by you by pressing [Esc].";;
esac
fi
elif [ ! -s $1 ] && [ ! -f $1 ] && [ ! -d $1 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "file:$1 doesn't exist.\nCan't copy...\nPress any key..." 5 30; read
elif [ ! $2 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "Invalid arguements...\nCan't copy...\nPress any key..." 5 30; read
elif [ -d $2 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "$2: is a directory.\nCan't copy...\nPress any key..." 5 30; read
elif [ -d $1 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --infobox "$1: is a directory.\nCan't copy...\nPress any key..." 5 30; read
elif [ -s $2 -o -f $2 ];then
	dialog --title "Copy daemon" --backtitle "copy:" --yesno "Do you want to overwrite file:$2" 10 60;
select=$?
case $select in 
	0) echo -e "i'm ordered to overwrite file:$2 \noverwriting...\noverwritten file:$2" ; cp -f $1 $2 ;;
	1) echo "i'm ordered not to overwrite.";;
	255) echo "cancelled by you by pressing [Esc].";;
esac
else
	dialog --title "Copy daemon" --backtitle "copy:" --yesno "Do you want to copy the file:$1 to file:$2" 10 60 ;
select1=$?
case $select1 in
	0) echo -e "i'm ordered to copy file:$1 to file:$2 \ncopying...\ncopied to file:$2" ; cp $1 $2 ;;
	1) echo "i'm ordered not to copy.";;
	255) echo "cancelled by you by pressing [Esc].";;
esac
fi

