#!/bin/bash MCORE_LIBDIR="@@MCORE_LIBDIR@@" source @@SYSCONFDIR@@/mcore/mcore.conf source @@SYSCONFDIR@@/mcore/citrix.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="" 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 } # get default store if [[ -z ${STOREFRONT_STORE} ]] then export STOREFRONT_STORE="${DEFAULT_STOREFRONT_STORE}" fi if ! storebrowse &> /dev/null then if [ -d ~/.ICAClient ] then rm -r ~/.ICAClient fi install -d ~/.ICAClient touch ~/.ICAClient/.eula_accepted # kill running instances pidof AuthManagerDaemon > /dev/null && killall AuthManagerDaemon pidof ServiceRecord > /dev/null && killall ServiceRecord pidof storebrowse > /dev/null && killall storebrowse # register eula and add default store xvfb-run -a -s "-extension RANDR" storebrowse -a "${STOREFRONT_STORE}" > /dev/null fi # get all sessions if [[ -z $(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=$(storebrowse -E ${OPT} ${STOREFRONT_STORE} 2> /dev/null) if [[ $? != 0 ]] then echo "could not retrieve session list" exit 1 fi # exclude the desktop session, which is always the first declare -i counter=0 while read line do if [[ ${counter} -gt 0 ]] then session=$(echo ${line} | cut -d"'" -f 2) description=$(echo ${line} | cut -d"'" -f 4) echo "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,enabled) values('${session}','${description}','1');" else mysqldo "update values_storefront_session set session='${session}',description='${description}',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}" fi (( counter++ )) 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