Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2766 - (hide 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 niro 2352 #!/bin/bash
2    
3     BROWSER=""
4     : ${STOREFRONT_STORE=""}
5 niro 2513 : ${REMOVE_STOREFRONT_TMP=1}
6 niro 2352
7 niro 2391 source @@SYSCONFDIR@@/mcore/citrix.conf
8    
9 niro 2352 if [[ -z ${STOREFRONT_STORE} ]]
10     then
11 niro 2391 STOREFRONT_STORE="${DEFAULT_STOREFRONT_STORE}"
12 niro 2352 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 niro 2402 # newer use storefront subscriptions with pnabrowse
23     STOREFRONT_ADDSTORE_REQUIRED=0
24     STOREFRONT_SUBSCRIBE_APP=0
25 niro 2352 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 niro 2512 die() { echo "ERROR: $@"; exit 1; }
37    
38 niro 2353 storefront_list_store()
39     {
40     "${BROWSER}" -l | cut -d"'" -f1-3 | sed "s:'::g"
41     }
42    
43 niro 2352 storefront_add_store()
44     {
45 niro 2353 if [[ -z $("${BROWSER}" -l "${STOREFRONT_STORE}" | grep "'${STOREFRONT_STORE}'") ]]
46 niro 2352 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 niro 2353 if [[ -n $("${BROWSER}" -l "${STOREFRONT_STORE}" | grep "'${STOREFRONT_STORE}'") ]]
56 niro 2352 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 niro 2391 # 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 niro 2396 # create required citrix runtime with an accepted eula
112     # and remove all temp files
113     install -d ~/.ICAClient
114     touch ~/.ICAClient/.eula_accepted
115 niro 2513 if [[ ${REMOVE_STOREFRONT_TMP} = 1 ]]
116 niro 2396 then
117 niro 2513 if [[ -d ~/.ICAClient/.tmp ]]
118     then
119     rm -r ~/.ICAClient/.tmp
120     fi
121 niro 2396 fi
122    
123 niro 2352 case ${CMD} in
124     enumerate)
125     # enumerate apps
126 niro 2402 if [[ ${STOREFRONT_ADDSTORE_REQUIRED} = 1 ]]
127 niro 2352 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 niro 2402 if [[ ${STOREFRONT_ADDSTORE_REQUIRED} = 1 ]]
143 niro 2352 then
144     storefront_add_store
145 niro 2402 fi
146     if [[ ${STOREFRONT_SUBSCRIBE_APP} = 1 ]]
147     then
148 niro 2352 storefront_subscribe_app
149 niro 2402 fi
150     if [[ ${BROWSER} = ${PNABROWSE_EXECUTABLE} ]]
151     then
152 niro 2352 # 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 niro 2766 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 niro 2352 Abort" "Failed to start session '${APP}'.
187    
188     " &
189 niro 2766 else
190     echo "Failed to start session '${APP}'."
191     fi
192     ;;
193     esac
194 niro 2352 ;;
195    
196 niro 2353 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 niro 2352 *)
217     echo "Unknown command '${CMD}'."
218     exit 1
219     ;;
220     esac