Magellan Linux

Contents of /mcore-src/trunk/mcore-tools/src/modules/citrix/storefront-resolver.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2766 - (show annotations) (download)
Wed Feb 10 15:12:13 2016 UTC (8 years, 3 months ago) by niro
File size: 4524 byte(s)
-storefront-resolver: print a better message for wrong username/password combinations
1 #!/bin/bash
2
3 BROWSER=""
4 : ${STOREFRONT_STORE=""}
5 : ${REMOVE_STOREFRONT_TMP=1}
6
7 source @@SYSCONFDIR@@/mcore/citrix.conf
8
9 if [[ -z ${STOREFRONT_STORE} ]]
10 then
11 STOREFRONT_STORE="${DEFAULT_STOREFRONT_STORE}"
12 fi
13
14 # prefer storebrowse
15 if [[ -e ${STOREBROWSE_EXECUTABLE} ]]
16 then
17 BROWSER=${STOREBROWSE_EXECUTABLE}
18 # use old pnabrowse
19 elif [[ -e ${PNABROWSE_EXECUTABLE} ]]
20 then
21 BROWSER=${PNABROWSE_EXECUTABLE}
22 # newer use storefront subscriptions with pnabrowse
23 STOREFRONT_ADDSTORE_REQUIRED=0
24 STOREFRONT_SUBSCRIBE_APP=0
25 else
26 echo "No Citrix browser found."
27 exit 1
28 fi
29
30 USE_XMESSAGE=0
31 if [[ -x $(type -P xmessage) ]]
32 then
33 USE_XMESSAGE=1
34 fi
35
36 die() { echo "ERROR: $@"; exit 1; }
37
38 storefront_list_store()
39 {
40 "${BROWSER}" -l | cut -d"'" -f1-3 | sed "s:'::g"
41 }
42
43 storefront_add_store()
44 {
45 if [[ -z $("${BROWSER}" -l "${STOREFRONT_STORE}" | grep "'${STOREFRONT_STORE}'") ]]
46 then
47 "${BROWSER}" -a "${STOREFRONT_STORE}"
48 else
49 echo "Store '${STOREFRONT_STORE}' already added."
50 fi
51 }
52
53 storefront_delete_store()
54 {
55 if [[ -n $("${BROWSER}" -l "${STOREFRONT_STORE}" | grep "'${STOREFRONT_STORE}'") ]]
56 then
57 "${BROWSER}" -d "${STOREFRONT_STORE}"
58 else
59 echo "Store '${STOREFRONT_STORE}' not found."
60 fi
61 }
62
63 storefront_subscribe_app()
64 {
65 # already subscribed?
66 if [[ -z $("${BROWSER}" -S -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}" | grep "'${APP}'") ]]
67 then
68 "${BROWSER}" -s "${APP}" -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}"
69 else
70 echo "'${APP}' already subscribed.'"
71 fi
72 }
73
74 storefront_unsubscribe_app()
75 {
76 # already subscribed?
77 if [[ -n $("${BROWSER}" -S -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}" | grep "'${APP}'") ]]
78 then
79 "${BROWSER}" -u "${APP}" -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}"
80 else
81 echo "'${APP}' not subscribed.'"
82 fi
83 }
84
85 storefront_enumerate()
86 {
87 "${BROWSER}" -E -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}"
88 }
89
90 storefront_launch()
91 {
92 "${BROWSER}" -L "${APP}" -U "${USER}" -P "${PASS}" -D "${DOMAIN}" "${STOREFRONT_STORE}"
93 }
94
95 # very basic getops
96 for argv in $*
97 do
98 case $1 in
99 --enumerate|--launch|--liststore|--addstore|--delstore) CMD="${1//--}" ;;
100 --user) shift; USER="$1" ;;
101 --password) shift; PASS="$1" ;;
102 --domain) shift; DOMAIN="$1" ;;
103 --app) shift; APP="$1" ;;
104 --store) shift; STOREFRONT_STORE="$1" ;; #override all envvars and configuration vars
105 esac
106 shift
107 done
108
109 [[ -n ${CMD} ]] || die "No CMD given"
110
111 # create required citrix runtime with an accepted eula
112 # and remove all temp files
113 install -d ~/.ICAClient
114 touch ~/.ICAClient/.eula_accepted
115 if [[ ${REMOVE_STOREFRONT_TMP} = 1 ]]
116 then
117 if [[ -d ~/.ICAClient/.tmp ]]
118 then
119 rm -r ~/.ICAClient/.tmp
120 fi
121 fi
122
123 case ${CMD} in
124 enumerate)
125 # enumerate apps
126 if [[ ${STOREFRONT_ADDSTORE_REQUIRED} = 1 ]]
127 then
128 storefront_add_store
129 fi
130 storefront_enumerate
131 ;;
132
133 launch)
134 # launch apps
135 if [[ ${USE_XMESSAGE} = 1 ]]
136 then
137 xmessage -center -title "ICA-Client" -buttons "" "
138 Starting session '${APP}' ...
139
140 " &
141 fi
142 if [[ ${STOREFRONT_ADDSTORE_REQUIRED} = 1 ]]
143 then
144 storefront_add_store
145 fi
146 if [[ ${STOREFRONT_SUBSCRIBE_APP} = 1 ]]
147 then
148 storefront_subscribe_app
149 fi
150 if [[ ${BROWSER} = ${PNABROWSE_EXECUTABLE} ]]
151 then
152 # always enumerate all apps to fill the cache or launch will not work
153 # and always enumerate if the cache is older than one day
154 if [ ! -f ~/.ICAClient/cache/Citrix/PNAgent/AppCache/appdata.xml ] ||
155 [[ ! -z $(find ~/.ICAClient/cache/Citrix/PNAgent/AppCache/appdata.xml -mtime +1) ]]
156 then
157 storefront_enumerate
158 fi
159 fi
160 storefront_launch
161 retval=$?
162 case ${retval} in
163 0)
164 if [[ ${USE_XMESSAGE} = 1 ]]
165 then
166 killall xmessage
167 fi
168 ;;
169 248)
170 if [[ ${USE_XMESSAGE} = 1 ]]
171 then
172 killall xmessage
173 xmessage -center -title "ICA-Client" -buttons "
174 Abort" "Wrong username or password for '${APP}'.
175
176 " &
177 else
178 echo "Wrong username or password for '${APP}'."
179 fi
180 ;;
181 *)
182 if [[ ${USE_XMESSAGE} = 1 ]]
183 then
184 killall xmessage
185 xmessage -center -title "ICA-Client" -buttons "
186 Abort" "Failed to start session '${APP}'.
187
188 " &
189 else
190 echo "Failed to start session '${APP}'."
191 fi
192 ;;
193 esac
194 ;;
195
196 liststore)
197 storefront_list_store
198 ;;
199
200 addstore)
201 if [[ -n $2 ]]
202 then
203 STOREFRONT_STORE="$2"
204 fi
205 storefront_add_store
206 ;;
207
208 delstore)
209 if [[ -n $2 ]]
210 then
211 STOREFRONT_STORE="$2"
212 fi
213 storefront_delete_store
214 ;;
215
216 *)
217 echo "Unknown command '${CMD}'."
218 exit 1
219 ;;
220 esac