Contents of /mcore-src/trunk/mcore-tools/src/modules/citrix/storefront-cron.in
Parent Directory | Revision Log
Revision 2522 -
(show annotations)
(download)
Mon Sep 14 13:16:02 2015 UTC (8 years, 7 months ago) by niro
File size: 3023 byte(s)
Mon Sep 14 13:16:02 2015 UTC (8 years, 7 months ago) by niro
File size: 3023 byte(s)
-fixed session import into database and disable all non-imported sessions, because they do not exist on the storefront-server and are not available for clients
1 | #!/bin/bash |
2 | |
3 | MCORE_LIBDIR="@@MCORE_LIBDIR@@" |
4 | source @@SYSCONFDIR@@/mcore/mcore.conf |
5 | source @@SYSCONFDIR@@/mcore/citrix.conf |
6 | source @@SYSCONFDIR@@/mcore/control.conf |
7 | source ${MCORE_LIBDIR}/include/common.global.class |
8 | source ${MCORE_LIBDIR}/include/daemon.global.class |
9 | source ${MCORE_LIBDIR}/include/mysqlfunctions.global.class |
10 | |
11 | : ${STOREFRONT_STORE=""} |
12 | : ${STOREFRONT_USER=""} |
13 | : ${STOREFRONT_PASS=""} |
14 | : ${STOREFRONT_DOMAIN=""} |
15 | |
16 | export IMPORTED_IDS="" |
17 | |
18 | is_not_an_import_id() |
19 | { |
20 | local id="$1" |
21 | local entry |
22 | |
23 | for entry in ${IMPORTED_IDS} |
24 | do |
25 | if [[ ${entry} = ${id} ]] |
26 | then |
27 | return 1 |
28 | fi |
29 | done |
30 | |
31 | return 0 |
32 | } |
33 | |
34 | # get default store |
35 | if [[ -z ${STOREFRONT_STORE} ]] |
36 | then |
37 | export STOREFRONT_STORE="${DEFAULT_STOREFRONT_STORE}" |
38 | fi |
39 | |
40 | if ! storebrowse &> /dev/null |
41 | then |
42 | if [ -d ~/.ICAClient ] |
43 | then |
44 | rm -r ~/.ICAClient |
45 | fi |
46 | |
47 | install -d ~/.ICAClient |
48 | touch ~/.ICAClient/.eula_accepted |
49 | |
50 | # kill running instances |
51 | pidof AuthManagerDaemon > /dev/null && killall AuthManagerDaemon |
52 | pidof ServiceRecord > /dev/null && killall ServiceRecord |
53 | pidof storebrowse > /dev/null && killall storebrowse |
54 | |
55 | # register eula and add default store |
56 | xvfb-run -a -s "-extension RANDR" storebrowse -a "${STOREFRONT_STORE}" > /dev/null |
57 | fi |
58 | |
59 | # get all sessions |
60 | if [[ -z $(storebrowse -l | grep -i ${STOREFRONT_STORE}) ]] |
61 | then |
62 | echo "Store ${STOREFRONT_STORE} unknown, perhaps not added. Run 'rm -r ~/.ICAClient'." |
63 | else |
64 | OPT="" |
65 | [[ -n ${STOREFRONT_USER} ]] && OPT+=" -U ${STOREFRONT_USER}" |
66 | [[ -n ${STOREFRONT_PASS} ]] && OPT+=" -P ${STOREFRONT_PASS}" |
67 | [[ -n ${STOREFRONT_DOMAIN} ]] && OPT+=" -D ${STOREFRONT_DOMAIN}" |
68 | SESSION_LIST=$(storebrowse -E ${OPT} ${STOREFRONT_STORE} 2> /dev/null) |
69 | if [[ $? != 0 ]] |
70 | then |
71 | echo "could not retrieve session list" |
72 | exit 1 |
73 | fi |
74 | |
75 | # exclude the desktop session, which is always the first |
76 | declare -i counter=0 |
77 | while read line |
78 | do |
79 | if [[ ${counter} -gt 0 ]] |
80 | then |
81 | session=$(echo ${line} | cut -d"'" -f 2) |
82 | description=$(echo ${line} | cut -d"'" -f 4) |
83 | echo "Session: '${session}' -> Description '${description}'" |
84 | |
85 | # import or update db entry |
86 | id=$(mysqldo "select id from values_storefront_session where session='${session}';") |
87 | if [[ -z ${id} ]] |
88 | then |
89 | mysqldo "insert into values_storefront_session (session,description,enabled) values('${session}','${description}','1');" |
90 | else |
91 | mysqldo "update values_storefront_session set session='${session}',description='${description}',enabled='1' where id='${id}';" |
92 | fi |
93 | |
94 | # get and save id |
95 | id=$(mysqldo "select id from values_storefront_session where session='${session}';") |
96 | export IMPORTED_IDS+=" ${id}" |
97 | fi |
98 | (( counter++ )) |
99 | done << EOF |
100 | $(echo "${SESSION_LIST}") |
101 | EOF |
102 | |
103 | # now disable all other ids in the database |
104 | DATABASE_IDS=$(mysqldo "select id from values_storefront_session") |
105 | for id in ${DATABASE_IDS} |
106 | do |
107 | if is_not_an_import_id "${id}" |
108 | then |
109 | # disable this one, not imported=not existing on the storefront-server in the moment |
110 | mysqldo "update values_storefront_session set enabled='0' where id='${id}';" |
111 | fi |
112 | done |
113 | fi |