1#!/bin/sh
2#**************************************************************
3#
4#  Licensed to the Apache Software Foundation (ASF) under one
5#  or more contributor license agreements.  See the NOTICE file
6#  distributed with this work for additional information
7#  regarding copyright ownership.  The ASF licenses this file
8#  to you under the Apache License, Version 2.0 (the
9#  "License"); you may not use this file except in compliance
10#  with the License.  You may obtain a copy of the License at
11#
12#    http://www.apache.org/licenses/LICENSE-2.0
13#
14#  Unless required by applicable law or agreed to in writing,
15#  software distributed under the License is distributed on an
16#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17#  KIND, either express or implied.  See the License for the
18#  specific language governing permissions and limitations
19#  under the License.
20#
21#**************************************************************
22
23if [ `uname -s` = "SunOS" ]; then
24  STCLIENT=/usr/bin/stclient
25else
26  STCLIENT=/opt/sun/servicetag/bin/stclient
27fi
28
29TARGET_URN=
30PRODUCT_NAME=
31PRODUCT_VERSION=
32PRODUCT_SOURCE=
33PARENT_PRODUCT_NAME=
34INSTANCE_URN=
35
36while [ $# -gt 0 ]
37do
38  case "$1" in
39    -t)  TARGET_URN="$2"; shift;;
40	-p)  PRODUCT_NAME="$2"; shift;;
41	-e)  PRODUCT_VERSION="$2"; shift;;
42	-i)  INSTANCE_URN="$2"; shift;;
43	-P)  PARENT_PRODUCT_NAME="$2"; shift;;
44	-S)  PRODUCT_SOURCE="$2"; shift;;
45	--)	 shift; break;;
46	-*)
47	    echo >&2 \
48	    "usage: $0 -p <product name> -e <product version> -t <urn> -S <source> -P <parent product name> [-i <instance urn>]"
49	    exit 1;;
50	*)  break;;
51    esac
52    shift
53done
54
55[ -x "$STCLIENT" ] || exit 1
56
57# test if already registered
58if [ ! -n $INSTANCE_URN ]; then
59  TEST=`${STCLIENT} -f -t ${TARGET_URN}`; EXITCODE=$?
60
61  # retry on unexpected error codes
62  [ ${EXITCODE} -eq 0 -o  ${EXITCODE} -eq 225 ] || exit 1
63
64  # early versions did not have a dedicated exitcode, so need to compare text output
65  [ ${EXITCODE} -eq 225 -o "${TEST}" = "No records found" ] || echo "${TEST}"; exit 0
66fi
67
68uname=`uname -p`
69zone="global"
70
71if [ `uname -s` = "SunOS" ]; then
72  if [ -x /usr/bin/zonename ]; then
73    zone=`/usr/bin/zonename`
74  fi
75fi
76
77output=`"${STCLIENT}" -a -p "${PRODUCT_NAME}" -e "${PRODUCT_VERSION}" -t ${TARGET_URN} -S "${PRODUCT_SOURCE}" -P "${PARENT_PRODUCT_NAME}" ${INSTANCE_URN:+"-i"} ${INSTANCE_URN} -m "Sun Microsystems, Inc." -A "${uname}" -z "${zone}"`; EXITCODE=$?
78
79[ "${INSTANCE_URN}" = "" -a ${EXITCODE} -eq 226 ] && exit 0
80
81exit ${EXITCODE}
82
83