#!/bin/bash MCORE_LIBDIR="@@MCORE_LIBDIR@@" source @@SYSCONFDIR@@/mcore/mcore.conf source @@SYSCONFDIR@@/mcore/citrix.conf source @@SYSCONFDIR@@/mcore/citrix-enumerate.conf source @@SYSCONFDIR@@/mcore/control.conf source ${MCORE_LIBDIR}/include/common.global.class source ${MCORE_LIBDIR}/include/daemon.global.class source ${MCORE_LIBDIR}/include/mysqlfunctions.global.class : ${STOREFRONT_STORE=""} : ${STOREFRONT_USER=""} : ${STOREFRONT_PASS=""} : ${STOREFRONT_DOMAIN=""} export IMPORTED_IDS="" LOCKFILE="@@RUNDIR@@/lock/storefront-cron.lock" is_not_an_import_id() { local id="$1" local entry for entry in ${IMPORTED_IDS} do if [[ ${entry} = ${id} ]] then return 1 fi done return 0 } # the lockfile is not meant to be perfect, it's just in case the # two cron scripts get run close to each other to keep # them from stepping on each other's toes. [[ -f ${LOCKFILE} ]] && exit 0 trap "{ rm -f ${LOCKFILE}; exit 0; }" EXIT touch ${LOCKFILE} # get default settings from configs [[ -z ${STOREFRONT_STORE} ]] && export STOREFRONT_STORE="${DEFAULT_STOREFRONT_STORE}" [[ -z ${STOREFRONT_USER} ]] && export STOREFRONT_USER="${MCORE_STOREFRONT_USER}" [[ -z ${STOREFRONT_PASS} ]] && export STOREFRONT_PASS="${MCORE_STOREFRONT_PASS}" [[ -z ${STOREFRONT_DOMAIN} ]] && export STOREFRONT_DOMAIN="${MCORE_STOREFRONT_DOMAIN}" # register eula and add default store as MCORE_UNPRIV_USER ${MCORE_LIBDIR}/storefront-store --add --store ${STOREFRONT_STORE} ${MCORE_LIBDIR}/storefront-store --regen # get all sessions if [[ -z $(su - ${MCORE_UNPRIV_USER} -c "storebrowse -l" | grep -i ${STOREFRONT_STORE}) ]] then echo "Store ${STOREFRONT_STORE} unknown, perhaps not added. Run 'rm -r ~/.ICAClient'." else OPT="" [[ -n ${STOREFRONT_USER} ]] && OPT+=" -U ${STOREFRONT_USER}" [[ -n ${STOREFRONT_PASS} ]] && OPT+=" -P ${STOREFRONT_PASS}" [[ -n ${STOREFRONT_DOMAIN} ]] && OPT+=" -D ${STOREFRONT_DOMAIN}" SESSION_LIST=$(su - ${MCORE_UNPRIV_USER} -c "storebrowse -E ${OPT} ${STOREFRONT_STORE}" 2> /dev/null) if [[ $? != 0 ]] then echo "could not retrieve session list" exit 1 fi while read line do session=$(echo ${line} | cut -d"'" -f 2) description=$(echo ${line} | cut -d"'" -f 4) decho "Session: '${session}' -> Description '${description}'" # import or update db entry id=$(mysqldo "select id from values_storefront_session where session='${session}';") if [[ -z ${id} ]] then mysqldo "insert into values_storefront_session (session,description,store,enabled) values('${session}','${description}','${STOREFRONT_STORE}','1');" else mysqldo "update values_storefront_session set session='${session}',description='${description}',store='${STOREFRONT_STORE}',enabled='1' where id='${id}';" fi # get and save id id=$(mysqldo "select id from values_storefront_session where session='${session}';") export IMPORTED_IDS+=" ${id}" done << EOF $(echo "${SESSION_LIST}") EOF # now disable all other ids in the database DATABASE_IDS=$(mysqldo "select id from values_storefront_session") for id in ${DATABASE_IDS} do if is_not_an_import_id "${id}" then # disable this one, not imported=not existing on the storefront-server in the moment mysqldo "update values_storefront_session set enabled='0' where id='${id}';" fi done fi exit 0