#!/bin/sh
if [ "$1" == "" ]
then
	echo error: type of access unknown >&2
	exit 1
fi
type=$1

if [ "$type" != "get" -a "$type" != "put" ]
then
	echo error: $type type of access unknown >&2
	exit 1
fi
shift
if [ "$1" == "" ]
then
	echo error: path unknown >&2
	exit 1
fi
path=$1

shift
if [ "$#" -eq 0 ]
then
	echo error: user and protocols unknown >&2
	exit 1
fi
user=$1

shift
protocol=""
while [ "$#" -ne 0 ]
do
	if [ "$1" == "file" ]
	then
		protocol="file"
		break
	fi
	shift
done

if [ ! "$protocol" == "file" ]
then
	echo no supported protocols provided >&2
	exit 1
fi

if [ "$type" == "get" ]
then 
	if [ ! -f $path  ]
	then
		echo file $path does not exists >&2
		exit 1
	fi
else
	if [ -f $path ]
	then
		echo file $path exists, can not overwrite >&2
		exit 1
	fi

	dir=`dirname $path`
	if [ ! -d $dir ]
	then
		echo directory $dir does not exists or is not a directory >&2
		exit 1
	fi
fi

turl="file:///"$path
echo $turl
exit 0

