#! /bin/bash -xv
#! /bin/bash -xv

# Modify file and keep time stamp
# usage: retouch file [handler]
#        tries to select a default handler by mime type
#        [handler] overrides selection by mime type

if [[ ! -z  "$2"  ]] ; then
	handler=$2
else
    mimeType=$(file -b --mime-type $1)
    case $mimeType in
        text/plain | text/xml)
            handler="/usr/bin/xed"
            ;;
        application/zip)
            handler=""/usr/bin/engrampa""
            ;;
        *)
            echo "usage: " $(basename $0) " file [handler]"
            echo "no provision to handle $mimeType"
            exit 1
    esac
fi

tempf=$(mktemp -d)
echo $tempf
cp -p $1 $tempf
$handler $1
touch -r $tempf/$(basename $1) $1
cd $tempf
rm -f *
cd ..
rmdir $tempf
exit 0

