#! /bin/sh
##
## sipxcommserverlib-config
##
## Copyright (C) 2007 Pingtel Corp., certain elements licensed under a Contributor Agreement.
## Copyright (C) 2009 Nortel Networks, certain elements licensed under a Contributor Agreement.
## Contributors retain copyright to elements licensed under a Contributor Agreement.
## Licensed to the User under the LGPL license.
##
##

# Print configuration information about sipXecs.
# Configuration information about the underlying platform, used by sipXecs,
# is printed by sipx-config.

# The default operation is PRINT, with ${Info} being the line of words to print.
Action=PRINT
Info=""

# Check to see if there is an extension for this package, and if so,
# read it.
ExtensionExists=no
[ -r /usr/bin/sipxcommserverlib-config-ext ] &&
    ExtensionExists=yes
if [ ${ExtensionExists} = yes ]
then
    # The extension file should define three shell functions:
    # sipxcommserverlib_config_extension_usage - print additional usage information
    # sipxcommserverlib_config_extension_operations - perform additional operations
    # sipxcommserverlib_config_extension_options - process an extension option
    # Currently, there are no extensions used.  An example extension
    # is in sipXpbx/doc/developer/sipxecs-config-ext.in.
    source /usr/bin/sipxcommserverlib-config-ext
fi

while [ $# -ne 0 ]
do
    case ${1} in
        --bin)
            Info="${Info} /usr/bin"
            ;;

        --include)
            Info="${Info} /usr/include"
            ;;

        --lib)
            Info="${Info} /usr/lib"
            ;;

        --host)
            Info="${Info} i686-suse-linux-gnu"
            ;;

        --version)
            Info="${Info} 4.2.1-018930"
            ;;

        --build)
            Info="${Info} 2010-07-31T01:11:36 build16 abuild "
            ;;

        --conf)
            Info="${Info} /etc/sipxpbx"
            ;;

        --data)
            Info="${Info} /usr/share/sipxecs"
            ;;

        --log)
            Info="${Info} /var/log/sipxpbx"
            ;;

        --run)
            Info="${Info} /var/run/sipxpbx"
            ;;

        --db)
            Info="${Info} /var/sipxdata/sipdb"
            ;;

        --all)
            Action=ALL
            break
            ;;

        --configopts)
            Info="${Info}  --host=i686-suse-linux-gnu --build=i686-suse-linux-gnu --target=i586-suse-linux --program-prefix= --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/lib --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --with-distdir=../dist SIPX_BUILD_LABEL=open"
            ;;

        --help)
            Action=USAGE
            break
            ;;

        ##
        ## handle an unknown switch
        ##
        -*)
	    # If an extension exists for this package, call its option function.
	    # If the option function thinks the option is valid, it returns
	    # success; otherwise it returns failure.
	    # This script's current arguments are given to it as arguments
	    # The returned value of ${AdditionalShift} is given to
	    # "shift" to allow the function to shift additional arguments.
	    if  [ ${ExtensionExists} = yes ] &&
		sipxcommserverlib_config_extension_options "$@"
	    then
		:
	    else
		# If the option was not valid, give an error message and print
		# the usage message.
		echo "Unknown switch '${1}'" 1>&2
		Action=USAGE
		AdditionalShift=0
	    fi
	    shift ${AdditionalShift}
            ;;
    esac

    shift # always consume 1 argument
done

if [ "${Action}" = "PRINT" -a "${Info}" = "" ]
then
    Action=USAGE
fi

case ${Action} in

    USAGE)
        cat <<EOF
Usage: sipxcommserverlib-config [OPTIONS]

     Option:      Displays:

    --bin         executable installation directory
    --include     header file installation directory
    --lib         object-code installation directory
    --conf        configuration directory
    --data        run time data directory
    --log         log directory
    --run         pid directory
    --db          database directory
    --host        host information
    --version     version information
    --build       build information

    --all         all of the above, with labels
    --configopts  options passed to the configure script when this was built

    --help        this message
EOF

	# If an extension exists for this package, append its usage message.
	if [ ${ExtensionExists} = yes ]
	then
	    sipxcommserverlib_config_extension_usage
	fi

	# Give success exit, as did earlier versions of this script.
	# (Without the '0', exit would return the exit status of the previous
	# command.)
        exit 0
        ;;

    PRINT)
        echo ${Info}
        ;;

    ALL)
        cat <<EOF
sipxcommserverlib version  4.2.1-018930
sipxcommserverlib build    2010-07-31T01:11:36 build16 abuild 
sipxcommserverlib bin      /usr/bin
sipxcommserverlib include  /usr/include
sipxcommserverlib lib      /usr/lib
sipxcommserverlib host     i686-suse-linux-gnu
sipxcommserverlib conf     /etc/sipxpbx
sipxcommserverlib data     /usr/share/sipxecs
sipxcommserverlib log      /var/log/sipxpbx
sipxcommserverlib run      /var/run/sipxpbx
sipxcommserverlib db       /var/sipxdata/sipdb
sipxcommserverlib cfgopts   --host=i686-suse-linux-gnu --build=i686-suse-linux-gnu --target=i586-suse-linux --program-prefix= --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/lib --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --with-distdir=../dist SIPX_BUILD_LABEL=open
EOF
        ;;

    *)
	# Other values of ${Action} can invoke addtional operations that
	# are defined in the extension file.
	sipxcommserverlib_config_extension_operations
	;;

esac

exit
