#!/bin/sh
#
#
#    Scalix Public License
#
#
#    The contents of this file are subject to the Scalix Public License
#    Version 1.1 ("License"); you may not use this file except in
#    compliance with the License. You may obtain a copy of the License at
#
# 
#    http://www.scalix.com/community/licensing 
#
# 
#    Software distributed under the License is distributed on an "AS IS"
#    basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
#    the License for the specific language governing rights and limitations
#    under the License.
#
# 
#    The Original Code is Scalix Server. 
#    The Initial Developer of the Original Code is Scalix Corporation. 
#    Copyright (C) 2006 Scalix Corporation. 
#    All Rights Reserved.
#    Additional Copyrights may apply - see the notice in each file
#
#
#
#
#
#
# Copyright (C) 2008 Scalix Corporation. All rights reserved.
#
###############################################################################
# This script is used by the RES to check if the current machine is in hosting
# or if the server is capable of hosting.
###############################################################################

#
# usage help function
#
usage() {
	echo "usage: $0 [OPTION]"
    echo ""
	echo "    -a    show if hosting is available"
    echo "    -e    show if hosting is enabled"
    echo ""
	exit 1
}
#
# Function to check if the current server is in hosting "mode."
#
checkHostingStatus () {
	if [ -f `/opt/scalix/bin/omrealpath '~/sys/mailnode_hosting.on'` ]
	then
		echo "HOSTING_ENABLED=ON"
	else
		echo "HOSTING_ENABLED=OFF"
	fi
}
#
# Function to check if hosting is available on the current server.
#
checkHostingAvailable () {
	OUTPUT="`/opt/scalix/bin/sxlicense | grep MAILNODE_HOSTING`"
	if [ -z "$OUTPUT" ]
	then
		echo "HOSTING_AVAILABLE=NO"
	else
		echo "HOSTING_AVAILABLE=YES"
	fi
}
#
# parse the arguments
#
OPTERR=0
while getopts ae opt
do
	case "$opt" in
		a) checkHostingAvailable
			;;
		e) checkHostingStatus
			;;
		[?]) usage
			;;
	esac
done

exit 0
