2 |
|
|
3 |
MCORE_LIBDIR="@@MCORE_LIBDIR@@" |
MCORE_LIBDIR="@@MCORE_LIBDIR@@" |
4 |
source @@SYSCONFDIR@@/mcore/mcore.conf |
source @@SYSCONFDIR@@/mcore/mcore.conf |
5 |
|
source @@SYSCONFDIR@@/mcore/citrix.conf |
6 |
|
source @@SYSCONFDIR@@/mcore/citrix-enumerate.conf |
7 |
|
source @@SYSCONFDIR@@/mcore/control.conf |
8 |
source ${MCORE_LIBDIR}/include/common.global.class |
source ${MCORE_LIBDIR}/include/common.global.class |
9 |
source ${MCORE_LIBDIR}/include/daemon.global.class |
source ${MCORE_LIBDIR}/include/daemon.global.class |
10 |
|
source ${MCORE_LIBDIR}/include/mysqlfunctions.global.class |
11 |
|
|
12 |
if [ ! -d ~/.ICAClient ] |
: ${STOREFRONT_STORE=""} |
13 |
then |
: ${STOREFRONT_USER=""} |
14 |
install -d ~/.ICAClient |
: ${STOREFRONT_PASS=""} |
15 |
fi |
: ${STOREFRONT_DOMAIN=""} |
16 |
|
|
17 |
if [ ! -f ~/.ICAClient ] |
export IMPORTED_IDS="" |
18 |
then |
|
19 |
touch ~/.ICAClient/.eula_accepted |
LOCKFILE="@@RUNDIR@@/lock/storefront-cron.lock" |
20 |
fi |
|
21 |
|
is_not_an_import_id() |
22 |
|
{ |
23 |
|
local id="$1" |
24 |
|
local entry |
25 |
|
|
26 |
|
for entry in ${IMPORTED_IDS} |
27 |
|
do |
28 |
|
if [[ ${entry} = ${id} ]] |
29 |
|
then |
30 |
|
return 1 |
31 |
|
fi |
32 |
|
done |
33 |
|
|
34 |
|
return 0 |
35 |
|
} |
36 |
|
|
37 |
|
# the lockfile is not meant to be perfect, it's just in case the |
38 |
|
# two cron scripts get run close to each other to keep |
39 |
|
# them from stepping on each other's toes. |
40 |
|
[[ -f ${LOCKFILE} ]] && exit 0 |
41 |
|
|
42 |
|
trap "{ rm -f ${LOCKFILE}; exit 0; }" EXIT |
43 |
|
touch ${LOCKFILE} |
44 |
|
|
45 |
|
# get default settings from configs |
46 |
|
[[ -z ${STOREFRONT_STORE} ]] && export STOREFRONT_STORE="${DEFAULT_STOREFRONT_STORE}" |
47 |
|
[[ -z ${STOREFRONT_USER} ]] && export STOREFRONT_USER="${MCORE_STOREFRONT_USER}" |
48 |
|
[[ -z ${STOREFRONT_PASS} ]] && export STOREFRONT_PASS="${MCORE_STOREFRONT_PASS}" |
49 |
|
[[ -z ${STOREFRONT_DOMAIN} ]] && export STOREFRONT_DOMAIN="${MCORE_STOREFRONT_DOMAIN}" |
50 |
|
|
51 |
|
# register eula and add default store as MCORE_UNPRIV_USER |
52 |
|
${MCORE_LIBDIR}/storefront-store --add --store ${STOREFRONT_STORE} |
53 |
|
${MCORE_LIBDIR}/storefront-store --regen |
54 |
|
|
55 |
if ! storebrowse > /dev/null |
# get all sessions |
56 |
|
if [[ -z $(su - ${MCORE_UNPRIV_USER} -c "storebrowse -l" | grep -i ${STOREFRONT_STORE}) ]] |
57 |
then |
then |
58 |
if [ -d ~/.ICAClient/.tmp ] |
echo "Store ${STOREFRONT_STORE} unknown, perhaps not added. Run 'rm -r ~/.ICAClient'." |
59 |
|
else |
60 |
|
OPT="" |
61 |
|
[[ -n ${STOREFRONT_USER} ]] && OPT+=" -U ${STOREFRONT_USER}" |
62 |
|
[[ -n ${STOREFRONT_PASS} ]] && OPT+=" -P ${STOREFRONT_PASS}" |
63 |
|
[[ -n ${STOREFRONT_DOMAIN} ]] && OPT+=" -D ${STOREFRONT_DOMAIN}" |
64 |
|
SESSION_LIST=$(su - ${MCORE_UNPRIV_USER} -c "storebrowse -E ${OPT} ${STOREFRONT_STORE}" 2> /dev/null) |
65 |
|
if [[ $? != 0 ]] |
66 |
then |
then |
67 |
rm -r ~/ICAClient/.tmp |
echo "could not retrieve session list" |
68 |
|
exit 1 |
69 |
fi |
fi |
70 |
|
|
71 |
# kill running instances |
# exclude the desktop session, which is always the first |
72 |
pidof AuthServiceDaemon > /dev/null && killall AuthServiceDaemon |
declare -i counter=0 |
73 |
pidof ServiceRecord > /dev/null && killall ServiceRecord |
while read line |
74 |
pidof storebrowse > /dev/null && killall storebrowse |
do |
75 |
|
if [[ ${counter} -gt 0 ]] |
76 |
# register eula |
then |
77 |
xvfb-run -a -s "-extension RANDR" storebrowse |
session=$(echo ${line} | cut -d"'" -f 2) |
78 |
|
description=$(echo ${line} | cut -d"'" -f 4) |
79 |
|
decho "Session: '${session}' -> Description '${description}'" |
80 |
|
|
81 |
|
# import or update db entry |
82 |
|
id=$(mysqldo "select id from values_storefront_session where session='${session}';") |
83 |
|
if [[ -z ${id} ]] |
84 |
|
then |
85 |
|
mysqldo "insert into values_storefront_session (session,description,store,enabled) values('${session}','${description}','${STOREFRONT_STORE}','1');" |
86 |
|
else |
87 |
|
mysqldo "update values_storefront_session set session='${session}',description='${description}',store='${STOREFRONT_STORE}',enabled='1' where id='${id}';" |
88 |
|
fi |
89 |
|
|
90 |
|
# get and save id |
91 |
|
id=$(mysqldo "select id from values_storefront_session where session='${session}';") |
92 |
|
export IMPORTED_IDS+=" ${id}" |
93 |
|
fi |
94 |
|
(( counter++ )) |
95 |
|
done << EOF |
96 |
|
$(echo "${SESSION_LIST}") |
97 |
|
EOF |
98 |
|
|
99 |
|
# now disable all other ids in the database |
100 |
|
DATABASE_IDS=$(mysqldo "select id from values_storefront_session") |
101 |
|
for id in ${DATABASE_IDS} |
102 |
|
do |
103 |
|
if is_not_an_import_id "${id}" |
104 |
|
then |
105 |
|
# disable this one, not imported=not existing on the storefront-server in the moment |
106 |
|
mysqldo "update values_storefront_session set enabled='0' where id='${id}';" |
107 |
|
fi |
108 |
|
done |
109 |
fi |
fi |
110 |
|
|
111 |
# get all sessions of default store |
exit 0 |
|
export STOREFRONT_STORE="${DEFAULT_STOREFRONT_STORE}" |
|
|
${MCORE_LIBDIR}/storefront-resolver |
|