File loadmof.sh of Package tog-pegasus

#!/bin/sh
# 
# options:
# loadmof.sh <MOF_PATH> <NAMESPACE> <FILES>
#
# - or -
#
# options:
# loadmof.sh -n <NAMESPACE> <FILES> [...]
#
# The former is preserved for compatibility with Pegasus and 
# sblim providers.  The latter is preferred.  If $1 is "-n",
# the latter code path is executed.  Otherwise the former is 
# executed.
#
if [ -x /usr/lib/python/site-packages/pywbem/mof_compiler.py ]; then
  CIMMOF="/usr/sbin/pegutil /usr/lib/python/site-packages/pywbem/mof_compiler.py"
elif [ -x /usr/lib64/python/site-packages/pywbem/mof_compiler.py ]; then
  CIMMOF="/usr/sbin/pegutil /usr/lib64/python/site-packages/pywbem/mof_compiler.py"
else
  print "Error: Can't find mof_compiler.py"
  exit 1
fi

PROVIDER_REGISTER="/usr/share/Pegasus/scripts/provider-register.sh"
DBDIR="/var/lib/Pegasus"
REPOSITORY="$DBDIR/repository"
LOGFILE=$DBDIR/loadmof.log

if [ "x$1" != "x-n" -a "x$1" != "x-v" -a "x$1" != "x-r" ]; then
# OLD STYLE
  CIMOM=$1
  shift
  case "$CIMOM" in
      openwbem)
          exit 0
      ;;
  esac

  MOF_PATH=$1
  shift
  NS=$1
  shift

  while [ "$#" -gt 0 ]
  do
      echo -n "Loading  $MOF_PATH/$1..."
      #/usr/bin/cimmofl -uc -W -R$REPOSITORY -I$MOF_PATH -n$NS $MOF_PATH/$1
      $PROVIDER_REGISTER  -t pegasus -r "${1%%.mof}.registration" -m "$1"
      shift
  done
else
# NEW STYLE
VERBOSE=0
NS=''
REMOVE=0
  while true; do
    case "$1" in 
      -v)
      VERBOSE=1
      shift
      ;;
      -n)
      shift
      NS=$1
      shift
      ;;
      -r)
      REMOVE=1
      shift
      ;;
      *)
      break
    esac
  done
  if [ "x$1" = "x" ]; then
      echo "Usage: $0 -n <NAMESPACE> <FILES> [...]"
      exit 1
  fi

  rm -f $LOGFILE.9
  for i in 8 7 6 5 4 3 2 1 0; do
    let newI=$i+1
    if [ -f $LOGFILE.$i ]; then
      mv $LOGFILE.$i $LOGFILE.$newI
    fi
  done
  if [ -f $LOGFILE ]; then
    mv $LOGFILE $LOGFILE.0
  fi
  REG=""
  case "$1" in
    "/usr/share/sblim-cmpi-base/Linux_Base.mof")
      REG="/usr/share/sblim-cmpi-base/Linux_BaseIndication.registration"
    ;;
    *)
      REG="${1%%.mof}.registration"
    ;;
  esac

  if [ -f "$REG" ]; then
    if [ "x$VERBOSE" = "x1" ]; then
       $PROVIDER_REGISTER -t pegasus -r "$REG" -m "$1" -v 
    else
       $PROVIDER_REGISTER -t pegasus -r "$REG" -m "$1"       &> $LOGFILE
    fi
  else
    if [ "x$REMOVE" = "x1" ]; then
      OPTS="-r"
    else
      OPTS="-s /usr/share/mof/cim-current"
    fi
    if [ "x$VERBOSE" = "x1" ]; then
#       $CIMMOF -uc -aEV -n $NS $@ 
       $CIMMOF -v -n $NS $OPTS -u /var/run/tog-pegasus/cimxml.socket $@
    else
#       $CIMMOF -uc -aEV -n $NS $@  &> $LOGFILE
       $CIMMOF -n $NS $OPTS -u /var/run/tog-pegasus/cimxml.socket $@ &> $LOGFILE
    fi
  fi
  RVAL=$?
  if [ "x$RVAL" != "x0" -a "x$VERBOSE" != "x1" ]; then
    echo "MOF import failed!  Check $LOGFILE for details."
  fi
  exit $RVAL
fi

openSUSE Build Service is sponsored by