#!/bin/bash

#INSTALL_ROOT
#PACKAGE_ROOT


NO_CHECK=/tmp/edr_pkg_free

function get_release()
{
	local sec=$1
	local key=$2

	$INSTALL_ROOT/bin/rwini -r -s "$sec" -k "$key" -f "$PACKAGE_ROOT/release"
}

function check()
{
	if [ -f $NO_CHECK ]; then
		return 0
	fi

	$PACKAGE_ROOT/check
}

function install()
{
	rm -f $NO_CHECK

	$PACKAGE_ROOT/install
}

function readme()
{
	cat $PACKAGE_ROOT/readme
}

function version()
{
	local name=`get_release common name`
	local id=`get_release $name id`

	echo "$id"
}

function name()
{
	local name=`get_release common name`
	echo "$name"
}

# package unique identifier
function puid()
{
	version
}

if [ -z "$1" ]; then
	exit 1
elif [ "$1" == "-c" ]; then
	check
elif [ "$1" == "-i" ]; then
	install
elif [ "$1" == "-r" ]; then
	readme
elif [ "$1" == "-v" ]; then
	version
elif [ "$1" == "-n" ]; then
	name
elif [ "$1" == "-p" ]; then
	puid
else
	exit 1
fi
