done
        ${INSTALL} -m 644 ${top_srcdir}/examples/Makefile "${DESTDIR}${PREFIX}${prefix}/share/doc/${package}-${version}/examples/"
        ${INSTALL} -m 644 ${top_srcdir}/examples/README.examples "${DESTDIR}${PREFIX}${prefix}/share/doc/${package}-${version}/examples/"
-       ${INSTALL} -m 755 ${top_srcdir}/src/export.sh "${DESTDIR}${PREFIX}${prefix}/sbin/glite-lb-export.sh"
        ${INSTALL} -m 755 ${top_srcdir}/examples/notify.pl ${DESTDIR}${PREFIX}${prefix}/${libdir}/glite-lb/examples/glite-lb-notify.pl
        ${INSTALL} -m 755 ${top_srcdir}/examples/sandbox_transfers.sh ${DESTDIR}${PREFIX}${prefix}/${libdir}/glite-lb/examples/glite-lb-sandbox_transfers.sh
        ${INSTALL} -m 644 ${MAN_GZ} ${DESTDIR}${PREFIX}${prefix}/share/man/man1
 
 usr/bin
 usr/lib/glite-lb/examples
-usr/sbin
 
 usr/bin/*
 usr/lib/glite-lb/examples/*
-usr/sbin/*
 
 /usr/bin/glite-lb-notify
 /usr/bin/glite-lb-register_sandbox
 /usr/%{_lib}/glite-lb/examples/*
-/usr/sbin/glite-lb-export.sh
 
 
 %changelog
 
        config/glite-lb* config/my.cnf config/*.conf config/startup config/setup \
        doc/*.1 doc/*.8 \
        interface/*.h \
-       src/*.c src/*.cpp src/*.h src/*.c.T src/*.l src/*.y src/*.sh src/ws_typemap.dat \
+       src/*.c src/*.cpp src/*.h src/*.c.T src/*.l src/*.y src/*.sh src/*.sh.in src/ws_typemap.dat \
        project/.post* project/.pre* \
        test/*.cpp test/*.cpp.T test/*.sh test/oneJob.qry test/*.c \
        LICENSE Makefile
 TESTS=test_coverage test_xml test_query_events test_soap_conv test_query_parse
 
 SCRIPTS=startup setup glite-lb-server-purge.cron glite-lb-proxy-purge.cron glite-lb-notif-keeper.cron glite-lb
+SCRIPTS2=export.sh notif-keeper.sh
 SCRIPTS_SRC=$(addprefix ${top_srcdir}/config/,${SCRIPTS})
 
 glite-lb-bkserverd: ${NSMAP} ${BKSERVER_OBJS}
 glite-lb-mon-db: ${MONDB_OBJS}
        ${LINKXX} -o $@ ${MONDB_OBJS} ${MONDB_LIBS}
 
-compile: generate ${SCRIPTS} glite-lb-bkserverd glite-lb-bkindex glite-lb-mon-db ${STATIC_LIB_BK} ${LCAS_PLUGIN_LIB} ${MAN_GZ}
+compile: generate ${SCRIPTS} ${SCRIPTS2} glite-lb-bkserverd glite-lb-bkindex glite-lb-mon-db ${STATIC_LIB_BK} ${LCAS_PLUGIN_LIB} ${MAN_GZ}
 
 generate: store.c index.c 
 
        fi; \
        sed -e 's:@glite_prefix@:${sysroot}${prefix}:g' -e 's:@glite_etc@:${sysconfdir}:g' -e "s:@glite_var@:$$glite_var:g" -e 's:@defaultdir@:${sysdefaultdir}:g' ${top_srcdir}/config/$@ > $@
 
+%.sh: %.sh.in
+       glite_var="${localstatedir}/glite"; \
+       if echo "${localstatedir}" | grep 'glite'>/dev/null; then \
+               glite_var="${localstatedir}"; \
+       fi; \
+       sed -e 's:@glite_prefix@:${sysroot}${prefix}:g' -e 's:@glite_etc@:${sysconfdir}:g' -e "s:@glite_var@:$$glite_var:g" -e 's:@defaultdir@:${sysdefaultdir}:g' $< > $@
+
 check: compile test.xml test.query test.query_parse
        -echo check.query not complete yet
 
                ${INSTALL} -m 755 ${LCAS_PLUGIN_LIB} ${DESTDIR}${PREFIX}${prefix}/${libdir}/modules; \
                ln -sf liblcas_lb.so ${DESTDIR}${PREFIX}${prefix}/${libdir}/modules/lcas_lb.mod; \
        fi
-       ${INSTALL} -m 755 ${top_srcdir}/src/notif-keeper.sh ${DESTDIR}${PREFIX}${prefix}/sbin/glite-lb-notif-keeper
+       ${INSTALL} -m 755 export.sh ${DESTDIR}${PREFIX}${prefix}/sbin/glite-lb-export
+       ${INSTALL} -m 755 notif-keeper.sh ${DESTDIR}${PREFIX}${prefix}/sbin/glite-lb-notif-keeper
 
        for f in dbsetup.sql index.conf.template; do \
                ${INSTALL} -m 644 ${top_srcdir}/config/"glite-lb-$$f" ${DESTDIR}${PREFIX}${sysconfdir}/glite-lb; \
 endif
 
 clean:
-       rm -rvf *.c *.cpp *.h *.ch *.xh *.xml *.nsmap *.o *.lo .libs glite-lb-bkindex glite-lb-bkserverd glite-lb-mon-db ${STATIC_LIB_BK} ${LCAS_PLUGIN_LIB} ${TESTS} ${MAN_GZ} ${EXAMPLES} ${SCRIPTS} ${MAN_GZ}
+       rm -rvf *.c *.cpp *.h *.ch *.xh *.xml *.nsmap *.o *.lo .libs glite-lb-bkindex glite-lb-bkserverd glite-lb-mon-db ${STATIC_LIB_BK} ${LCAS_PLUGIN_LIB} ${TESTS} ${MAN_GZ} ${EXAMPLES} ${SCRIPTS} ${SCRIPTS2} ${MAN_GZ}
        rm -rvf test_xml.cpp
        rm -rvf dist ${package}-*.tar.gz
 
 
 # purge timeouts
 GLITE_LB_EXPORT_PURGE_ARGS='--cleared 2d --aborted 15d --cancelled 15d --other 60d'
 
+# glite-info
+
+#SITE_NAME=
+#SITE_EMAIL=
+
 #
 # L&B configuration
 #
 
-31 1 * * *     glite   ( test -f /etc/profile.d/grid-env.sh || exit 0; . /etc/profile.d/grid-env.sh; export GLITE_LB_EXPORT_BKSERVER=$HOSTNAME; export GLITE_LB_PURGE_TARGET_RUNTIME=84600s; export GLITE_LB_PURGE_OTHER_OPTIONS="$GLITE_LB_PURGE_OTHER_OPTIONS -x"; printf "`date "+\%b \%e \%T"` `hostname -s` glite-lb-export.sh: "; @glite_prefix@/sbin/glite-lb-export.sh ) >> /var/log/glite/glite-lb-server-purge-proxy.log 2>&1
+31 1 * * *     glite   ( export GLITE_LB_EXPORT_BKSERVER=`hostname -f`; export GLITE_LB_PURGE_TARGET_RUNTIME=84600s; export GLITE_LB_PURGE_OTHER_OPTIONS="$GLITE_LB_PURGE_OTHER_OPTIONS -x"; printf "`date "+\%b \%e \%T"` `hostname -s` glite-lb-export: "; @glite_prefix@/sbin/glite-lb-export ) >> /var/log/glite/glite-lb-server-purge-proxy.log 2>&1
 
-1 1 * * *      glite   ( test -f /etc/profile.d/grid-env.sh || exit 0; . /etc/profile.d/grid-env.sh; export GLITE_LB_EXPORT_BKSERVER=$HOSTNAME; export GLITE_LB_PURGE_TARGET_RUNTIME=84600s; printf "`date "+\%b \%e \%T"` `hostname -s` glite-lb-export.sh: "; @glite_prefix@/sbin/glite-lb-export.sh ) >> /var/log/glite/glite-lb-server-purge.log 2>&1
+1 1 * * *      glite   ( export GLITE_LB_EXPORT_BKSERVER=`hostname -f`; export GLITE_LB_PURGE_TARGET_RUNTIME=84600s; printf "`date "+\%b \%e \%T"` `hostname -s` glite-lb-export: "; @glite_prefix@/sbin/glite-lb-export ) >> /var/log/glite/glite-lb-server-purge.log 2>&1
 
 
 if test "$setup_bdii" = "1"; then
        export INFO_SERVICE_CONFIG='/etc/glite/info/service'
+       bdii=0
        if test -x /etc/init.d/bdii; then
                if test -f  ${INFO_SERVICE_CONFIG}/glite-info-service-lbserver.conf.template -a -f  ${INFO_SERVICE_CONFIG}/glite-info-glue2-lbserver.conf.template; then
                        bdii=1
                sed -i  "s#.*rootpw.*#rootpw    ${BDII_PASSWD}#" /etc/bdii/bdii-slapd.conf
 
                if test -x /sbin/service; then
+                       /sbin/chkconfig bdii on
                        out="`/sbin/service bdii restart 2>&1`"
                else
                        out="`/etc/init.d/bdii restart 2>&1`"
                fi
        else
                /sbin/chkconfig mysqld on
-               test -z "$bdii" && /sbin/chkconfig bdii on
                /sbin/chkconfig glite-lb-bkserverd on
                /sbin/chkconfig glite-lb-locallogger on
                if test x"$GLITE_LB_HARVETER_ENABLED" = x"true"; then
        if test x"$GLITE_LB_HARVESTER_ENABLED" = x"true"; then
                $GLITE_LOCATION_ETC/init.d/glite-lb-harvester restart || startup_error=1
        else
-               $GLITE_LOCATION_ETC/init.d/glite-lb-harvester stop >/dev/null
+               if test -x $GLITE_LOCATION/bin/glite-lb-harvester; then
+                       $GLITE_LOCATION_ETC/init.d/glite-lb-harvester stop >/dev/null
+               fi
        fi
 
        if test "$startup_error" = "0"; then
 
 #
 
 #
-# script for exporing jobs from bkserver which should be periodically run
-# together with running jp-importer
-#
-# it uses configuration from enviroment ==> may require a configuration wrapper
+# script for purging jobs from bkserver which should be run periodically
+# jobs export and import into Job Provenance may be optionally enabled
 #
 
+GLITE_LB_LOCATION_VAR=${GLITE_LB_LOCATION_VAR:-'@glite_var@'}
+GLITE_USER=${GLITE_USER:-'glite'}
+GLITE_HOME=`getent passwd ${GLITE_USER} | cut -d: -f6`
+GLITE_HOST_CERT=${GLITE_HOST_CERT:-"$GLITE_HOME/.certs/hostcert.pem"}
+GLITE_HOST_KEY=${GLITE_HOST_KEY:-"$GLITE_HOME/.certs/hostkey.pem"}
+
+[ -f /etc/profile.d/grid-env.sh ] && . /etc/profile.d/grid-env.sh
+[ -f @defaultdir@/glite-lb ] && . @defaultdir@/glite-lb
+
 #autodetect the prefix
 PREFIX=${GLITE_LOCATION:-`dirname $0`/..}
 
 
 # limitations under the License.
 #
 
-GLITE_LOCATION=${GLITE_LOCATION:-"/opt/glite"}
+GLITE_LOCATION=${GLITE_LOCATION:-"@glite_prefix@"}
+[ -f /etc/profile.d/grid-env.sh ] && . /etc/profile.d/grid-env.sh
+[ -f @defaultdir@/glite-lb ] && . @defaultdir@/glite-lb
+
 NOTIFY=${GLITE_LB_NOTIFY:-"$GLITE_LOCATION/bin/glite-lb-notify"}
 
 # This function reads the full list of notifications to maintain into an array