#!/bin/bash
# 
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
# 
# The contents of this file are subject to the Mozilla 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.zimbra.com/license
# 
# 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: Zimbra Collaboration Suite Server.
# 
# The Initial Developer of the Original Code is Zimbra, Inc.
# Portions created by Zimbra are Copyright (C) 2006 Zimbra, Inc.
# All Rights Reserved.
# 
# Contributor(s):
# 
# ***** END LICENSE BLOCK *****
# 
# look for the entitlement data from the ZCS license
license=/opt/zimbra/conf/ZCSLicense.xml
if ! [ -f "$license" ]; then
    echo "error: unable to read license information" > /dev/stderr
    exit 1
fi
# pull the license UUID from the license file
key=$(cat $license | grep LicenseId | awk -F= '{print $NF}' | awk -F\" '{print $2}')
# calculate how we were called (e.g. /etc/conary/entitlements/conary.rpath.com)
server=$(basename $0)
case $server in
  products.rpath.com)
    class=zimbra-zcs
    ;;
  conary.rpath.com)
    class=zimbra-zcs
    ;;
  zimbra.liquidsys.com)
    class=zimbra-zcs
    ;;
  *)
    echo "error: script was called as $0. it should only be called via a symlink that matches the server name"
    exit 1
    ;;
esac

cat << EOF
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE entitlement [
<!ELEMENT entitlement (server, class, key)>
<!ELEMENT server (#PCDATA)>
<!ELEMENT class (#PCDATA)>
<!ELEMENT key (#PCDATA)>
]>
<entitlement>
  <server>$server</server>
  <class>$class</class>
  <key>$key</key>
</entitlement>
EOF
