1#!/bin/sh
2#
3# Copyright 2000, 2010 Oracle and/or its affiliates.
4# All rights reserved.
5#
6
7if [ `uname -s` = "SunOS" ]; then
8  STCLIENT=/usr/bin/stclient
9else
10  STCLIENT=/opt/sun/servicetag/bin/stclient
11fi
12
13TARGET_URN=
14PRODUCT_NAME=
15PRODUCT_VERSION=
16PRODUCT_SOURCE=
17PARENT_PRODUCT_NAME=
18INSTANCE_URN=
19
20while [ $# -gt 0 ]
21do
22  case "$1" in
23    -t)  TARGET_URN="$2"; shift;;
24	-p)  PRODUCT_NAME="$2"; shift;;
25	-e)  PRODUCT_VERSION="$2"; shift;;
26	-i)  INSTANCE_URN="$2"; shift;;
27	-P)  PARENT_PRODUCT_NAME="$2"; shift;;
28	-S)  PRODUCT_SOURCE="$2"; shift;;
29	--)	 shift; break;;
30	-*)
31	    echo >&2 \
32	    "usage: $0 -p <product name> -e <product version> -t <urn> -S <source> -P <parent product name> [-i <instance urn>]"
33	    exit 1;;
34	*)  break;;
35    esac
36    shift
37done
38
39[ -x "$STCLIENT" ] || exit 1
40
41# test if already registered
42if [ ! -n $INSTANCE_URN ]; then
43  TEST=`${STCLIENT} -f -t ${TARGET_URN}`; EXITCODE=$?
44
45  # retry on unexpected error codes
46  [ ${EXITCODE} -eq 0 -o  ${EXITCODE} -eq 225 ] || exit 1
47
48  # early versions did not have a dedicated exitcode, so need to compare text output
49  [ ${EXITCODE} -eq 225 -o "${TEST}" = "No records found" ] || echo "${TEST}"; exit 0
50fi
51
52uname=`uname -p`
53zone="global"
54
55if [ `uname -s` = "SunOS" ]; then
56  if [ -x /usr/bin/zonename ]; then
57    zone=`/usr/bin/zonename`
58  fi
59fi
60
61output=`"${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=$?
62
63[ "${INSTANCE_URN}" = "" -a ${EXITCODE} -eq 226 ] && exit 0
64
65exit ${EXITCODE}
66
67