#!/bin/bash BROWSER="" : ${STOREFRONT_STORE=""} source @@SYSCONFDIR@@/mcore/citrix.conf if [[ -z ${STOREFRONT_STORE} ]] then STOREFRONT_STORE="${DEFAULT_STOREFRONT_STORE}" fi # prefer storebrowse if [[ -e ${STOREBROWSE_EXECUTABLE} ]] then BROWSER=${STOREBROWSE_EXECUTABLE} ADDSTORE_REQUIRED=1 # use old pnabrowse elif [[ -e ${PNABROWSE_EXECUTABLE} ]] then BROWSER=${PNABROWSE_EXECUTABLE} ADDSTORE_REQUIRED=0 else echo "No Citrix browser found." exit 1 fi USE_XMESSAGE=0 if [[ -x $(type -P xmessage) ]] then USE_XMESSAGE=1 fi storefront_list_store() { "${BROWSER}" -l | cut -d"'" -f1-3 | sed "s:'::g" } storefront_add_store() { if [[ -z $("${BROWSER}" -l "${STOREFRONT_STORE}" | grep "'${STOREFRONT_STORE}'") ]] then "${BROWSER}" -a "${STOREFRONT_STORE}" else echo "Store '${STOREFRONT_STORE}' already added." fi } storefront_delete_store() { if [[ -n $("${BROWSER}" -l "${STOREFRONT_STORE}" | grep "'${STOREFRONT_STORE}'") ]] then "${BROWSER}" -d "${STOREFRONT_STORE}" else echo "Store '${STOREFRONT_STORE}' not found." fi } storefront_subscribe_app() { # already subscribed? if [[ -z $("${BROWSER}" -S -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}" | grep "'${APP}'") ]] then "${BROWSER}" -s "${APP}" -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}" else echo "'${APP}' already subscribed.'" fi } storefront_unsubscribe_app() { # already subscribed? if [[ -n $("${BROWSER}" -S -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}" | grep "'${APP}'") ]] then "${BROWSER}" -u "${APP}" -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}" else echo "'${APP}' not subscribed.'" fi } storefront_enumerate() { "${BROWSER}" -E -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}" } storefront_launch() { "${BROWSER}" -L "${APP}" -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}" } # very basic getops for argv in $* do case $1 in --enumerate|--launch|--liststore|--addstore|--delstore) CMD="${1//--}" ;; --user) shift; USER="$1" ;; --password) shift; PASS="$1" ;; --domain) shift; DOMAIN="$1" ;; --app) shift; APP="$1" ;; --store) shift; STOREFRONT_STORE="$1" ;; #override all envvars and configuration vars esac shift done [[ -n ${CMD} ]] || die "No CMD given" # create required citrix runtime with an accepted eula # and remove all temp files install -d ~/.ICAClient touch ~/.ICAClient/.eula_accepted if [[ -d ~/ICAClient/.tmp ]] then rm -r ~/ICAClient/.tmp fi case ${CMD} in enumerate) # enumerate apps if [[ ${ADDSTORE_REQUIRED} = 1 ]] then storefront_add_store fi storefront_enumerate ;; launch) # launch apps if [[ ${USE_XMESSAGE} = 1 ]] then xmessage -center -title "ICA-Client" -buttons "" " Starting session '${APP}' ... " & fi if [[ ${ADDSTORE_REQUIRED} = 1 ]] then storefront_add_store storefront_subscribe_app else # always enumerate all apps to fill the cache or launch will not work # and always enumerate if the cache is older than one day if [ ! -f ~/.ICAClient/cache/Citrix/PNAgent/AppCache/appdata.xml ] || [[ ! -z $(find ~/.ICAClient/cache/Citrix/PNAgent/AppCache/appdata.xml -mtime +1) ]] then storefront_enumerate fi fi if storefront_launch then if [[ ${USE_XMESSAGE} = 1 ]] then killall xmessage fi else if [[ ${USE_XMESSAGE} = 1 ]] then killall xmessage xmessage -center -title "ICA-Client" -buttons " Abort" "Failed to start session '${APP}'. " & else echo "Failed to start session '${APP}'." fi fi ;; liststore) storefront_list_store ;; addstore) if [[ -n $2 ]] then STOREFRONT_STORE="$2" fi storefront_add_store ;; delstore) if [[ -n $2 ]] then STOREFRONT_STORE="$2" fi storefront_delete_store ;; *) echo "Unknown command '${CMD}'." exit 1 ;; esac