# osgi-runner-extras-90-regrouped-bundles-activator from osgi-runner-merging-bundle-activator
#
# if $OSGI_PERFORM_REGROUP_BUNDLES is not set to "yes" this script does nothing.
# 
# usually only osgi* scripts that start a osgi-runner process set that variable to "yes".
# other osgi* scripts that stop a osgi-runner process or send signals to set it to "no".
#
#
# regroups (merges) bundles from 
#   /usr/share/osgi-bundles/bundles 
#   $OSGI_REGROUP_BUNDLES_DIRS
#   $OSGI_REGROUP_BUNDLES_FILES
# into
#   /tmp/osgi-runner-regrouped-bundles
# making sure only the newest version of any bundle is used.
#
# Please build $OSGI_REGROUP_BUNDLES_DIRS and/or $OSGI_REGROUP_BUNDLES_FILES in
# /etc/default/osgi-runner directly or /etc/default/osgi-runner-extras-01-*
# so it is set before this script is sourced from /etc/default/osgi-runner
#
# There's no actual difference between the environemnt variables
# $OSGI_REGROUP_BUNDLES_DIRS and $OSGI_REGROUP_BUNDLES_FILES,
# we didn't want to use '_SOURCES' (might be misleading)
# but didn't want to go too short or monster long neither.

if [ "${OSGI_PERFORM_REGROUP_BUNDLES}" = "yes" ] ; then

  echo "Actually regrouping bundles."

  rm -rf /tmp/osgi-runner-regrouped-bundles
  #mkdir -pv /tmp/osgi-runner-regrouped-bundles

  jt-regroup-bundles -l -n -v \
    ${OSGI_REGROUP_BUNDLES_DIRS} ${OSGI_REGROUP_BUNDLES_FILES} \
    /usr/share/osgi-bundles/bundles \
    /tmp/osgi-runner-regrouped-bundles

else

  echo "Not regrouping bundles."

fi

