%preinstall << END

# echo Command before installing
# Only for Linux!

platform=`uname -s`

if [ "$$platform" = "Linux" ]; then
  ISUPDATE=0
  # two packages after installation -> update
  if [ "$$1" = "2" ]
  then
    ISUPDATE=1
  fi

  # remove only, if this is an update  
  if [ "$$ISUPDATE" = "1" ]; then
    PRODUCTINSTALLLOCATION="$$RPM_INSTALL_PREFIX"
    $$PRODUCTINSTALLLOCATION/PRODUCTDIRECTORYNAME/program/unopkg remove --shared ${OXTFILENAME}
  fi
fi

exit 0
END

%postinstall << END

# echo Command after installing
# Only for Linux!
platform=`uname -s`

if [ "$$platform" = "Linux" ]; then
  PRODUCTINSTALLLOCATION="$$RPM_INSTALL_PREFIX"
  $$PRODUCTINSTALLLOCATION/PRODUCTDIRECTORYNAME/program/unopkg add --shared $$PRODUCTINSTALLLOCATION/PRODUCTDIRECTORYNAME/share/extension/install/${OXTFILENAME}
fi

if [ "$$platform" = "SunOS" ]; then
  PRODUCTINSTALLLOCATION="$$BASEDIR"
  echo "Not registered" > $$PRODUCTINSTALLLOCATION/PRODUCTDIRECTORYNAME/program/register.dat
fi

exit 0
END

%preremove << END

# echo Command before removing
# Only for Linux!

platform=`uname -s`

if [ "$$platform" = "Linux" ]; then
  ISUPDATE=0	# important for RPM deinstallation
  if [ "$$1" = "1" ]	# one package left after deinstallation -> update
  then
    ISUPDATE=1
  fi
  
  # remove only, if this is no update
  if [ "$$ISUPDATE" = "0" ]; then 
    PRODUCTINSTALLLOCATION="$$RPM_INSTALL_PREFIX"
    $$PRODUCTINSTALLLOCATION/PRODUCTDIRECTORYNAME/program/unopkg remove --shared ${OXTFILENAME}
  fi
fi

if [ "$$platform" = "SunOS" ]; then
  PRODUCTINSTALLLOCATION="$$BASEDIR"
  if [ -f $$PRODUCTINSTALLLOCATION/PRODUCTDIRECTORYNAME/program/register.dat ]; then
    rm $$PRODUCTINSTALLLOCATION/PRODUCTDIRECTORYNAME/program/register.dat
  fi
fi

exit 0
END

%postremove << END
END
