#!/bin/sh
set -e
# Install default config file
#

ECHO="echo"
CHMOD="/bin/chmod"
CP="/bin/cp"
CMP="/usr/bin/cmp"
MKDIR="/bin/mkdir -p"
RM="rm -f"
RMDIR="/bin/rmdir"
TEST="test"

OMNIORB_ETCDIR="/opt/openrobots/etc"
OMNIORB_CONFIG="/opt/openrobots/etc/omniORB.cfg"
SAMPLE_CONFIG="${PKG_PREFIX}/share/examples/omniORB/sample.cfg"

case $2 in
  POST-INSTALL)
    if ! ${TEST} -f ${OMNIORB_CONFIG}; then
      ${ECHO} "$1: installing default configuration file in ${OMNIORB_CONFIG}"
      ${TEST} -d "${OMNIORB_ETCDIR}" || ${MKDIR} "${OMNIORB_ETCDIR}"
      ${CP} "${SAMPLE_CONFIG}" "${OMNIORB_CONFIG}"
      ${CHMOD} 644 "${OMNIORB_CONFIG}"
    fi
    ;;

  DEINSTALL)
    if ${TEST} -f ${OMNIORB_CONFIG}; then
      if ${CMP} -s "${OMNIORB_CONFIG}" "${SAMPLE_CONFIG}"; then
        ${ECHO} "$1: removing default configuration file in ${OMNIORB_CONFIG}"
        ${RM} -f "${OMNIORB_CONFIG}"
        ${RMDIR} -p "${OMNIORB_ETCDIR}" >/dev/null 2>&1 ||:
      else
        ${ECHO} "$1: keeping configuration file in ${OMNIORB_CONFIG}"
      fi
    fi
    ;;
esac
exit 0
