#!/bin/bash BROWSER="" : ${STOREFRONT_STORE=""} : ${REMOVE_STOREFRONT_TMP=1} 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} # use old pnabrowse elif [[ -e ${PNABROWSE_EXECUTABLE} ]] then BROWSER=${PNABROWSE_EXECUTABLE} # newer use storefront subscriptions with pnabrowse STOREFRONT_ADDSTORE_REQUIRED=0 STOREFRONT_SUBSCRIBE_APP=0 else echo "No Citrix browser found." exit 1 fi USE_XMESSAGE=0 if [[ -x $(type -P xmessage) ]] then USE_XMESSAGE=1 fi die() { echo "ERROR: $@"; exit 1; } 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 [[ ${REMOVE_STOREFRONT_TMP} = 1 ]] then if [[ -d ~/.ICAClient/.tmp ]] then rm -r ~/.ICAClient/.tmp fi fi case ${CMD} in enumerate) # enumerate apps if [[ ${STOREFRONT_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 [[ ${STOREFRONT_ADDSTORE_REQUIRED} = 1 ]] then storefront_add_store fi if [[ ${STOREFRONT_SUBSCRIBE_APP} = 1 ]] then storefront_subscribe_app fi if [[ ${BROWSER} = ${PNABROWSE_EXECUTABLE} ]] then # 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 storefront_launch retval=$? case ${retval} in 0) if [[ ${USE_XMESSAGE} = 1 ]] then killall xmessage fi ;; 248) if [[ ${USE_XMESSAGE} = 1 ]] then killall xmessage xmessage -center -title "ICA-Client" -buttons " Abort" "Wrong username or password for '${APP}'. " & else echo "Wrong username or password for '${APP}'." fi ;; *) 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 ;; esac ;; 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