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