#!/bin/bash

#Company:       PowerCraft Technology
#Author:        Copyright Jelle de Jong <jelledejong@powercraft.nl>
#Note:          Please send me an email if you enhanced this script
#Version:       0.0.2
#Date:          05-09-2006
#System:        Ubuntu/Debian GNU/Linux
#Information:   man cp
#Category       Thunar scripts (thunar->edit->custom actions)
#Name:          Copy to /media/disk
#Description:   Copy selected items to directory /media/disk
#Command:       xfce4-terminal --disable-server --hide-toolbars --execute /usr/share/pct-thunar-scripts/scripts/copy-to-disk %F
#Patterns:      *
#Directories:   True
#Audio Files:   True
#Image Files:   True
#Text Files:    True
#Video Files:   True
#Other Files:   True

# Did the script work for you?
# Yes
# Yes, but with some errors
# Yes, but I had to change some things
# Not at all

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=${0##*/}

LOCATION="/media/disk"

NAME=$"Copy to $LOCATION"
DESCRIPTION=$"Copy selected items to directory $LOCATION"

cecho()
{
    case "$1" in
        "black")
               echo -ne "\E[30m"
               ;;
        "red")
               echo -ne "\E[31m"
               ;;
        "green")
               echo -ne "\E[32m"
               ;;
        "yellow")
               echo -ne "\E[33m"
               ;;
        "blue")
               echo -ne "\E[34m"
               ;;
        "magenta")
               echo -ne "\E[35m"
               ;;
        "cyan")
               echo -ne "\E[36m"
               ;;
         *)
               echo -ne "\E[30m"
               exit
               ;;
    esac

    echo "$2" "$3"
    tput sgr0
}

cecho "green" $"program:"
echo "$0"

cecho "green" $"description:"
echo "$DESCRIPTION"

cecho "green" $"copy these directory(s) or file(s):"
for I in "$@"
do
    echo "$I"
done

for I in "$@"
do
    cecho "green" $"starting with: "
    echo "$I"

    if [ ! -d "$LOCATION" ]; then
        cecho "red" 1>&2 $"error, location: $LOCATION does not exist!"
        continue
    fi

    cp -a "$I" "$LOCATION"

    if [ $? -eq 1 ]
    then
        cecho "red" $"retry with superuser rights"

        sudo cp -a "$I" "$LOCATION"

        if [ $? -eq 1 ]
        then
            cecho "red" 1>&2 $"error, exit in 30 seconds without success"
            continue
        fi
    fi

    cecho "green" $"completed with:"
    echo "$I"
done

cecho "green"  -n $"finished, please press the [enter] key to close and exit this window"
read input

exit 0