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 |
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 |
source ${MCORE_LIBDIR}/include/mysqlfunctions.global.class |
14 |
: ${STOREFRONT_PASS=""} |
: ${STOREFRONT_PASS=""} |
15 |
: ${STOREFRONT_DOMAIN=""} |
: ${STOREFRONT_DOMAIN=""} |
16 |
|
|
17 |
# get default store |
export IMPORTED_IDS="" |
18 |
if [[ -z ${STOREFRONT_STORE} ]] |
|
19 |
then |
LOCKFILE="@@RUNDIR@@/lock/storefront-cron.lock" |
20 |
export STOREFRONT_STORE="${DEFAULT_STOREFRONT_STORE}" |
|
21 |
fi |
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 |
if ! storebrowse &> /dev/null |
if ! storebrowse &> /dev/null |
52 |
then |
then |
64 |
pidof storebrowse > /dev/null && killall storebrowse |
pidof storebrowse > /dev/null && killall storebrowse |
65 |
|
|
66 |
# register eula and add default store |
# register eula and add default store |
67 |
xvfb-run -a -s "-extension RANDR" storebrowse -a "${STOREFRONT_STORE}" |
xvfb-run -a -s "-extension RANDR" storebrowse -a "${STOREFRONT_STORE}" > /dev/null |
68 |
fi |
fi |
69 |
|
|
70 |
# get all sessions |
# get all sessions |
76 |
[[ -n ${STOREFRONT_USER} ]] && OPT+=" -U ${STOREFRONT_USER}" |
[[ -n ${STOREFRONT_USER} ]] && OPT+=" -U ${STOREFRONT_USER}" |
77 |
[[ -n ${STOREFRONT_PASS} ]] && OPT+=" -P ${STOREFRONT_PASS}" |
[[ -n ${STOREFRONT_PASS} ]] && OPT+=" -P ${STOREFRONT_PASS}" |
78 |
[[ -n ${STOREFRONT_DOMAIN} ]] && OPT+=" -D ${STOREFRONT_DOMAIN}" |
[[ -n ${STOREFRONT_DOMAIN} ]] && OPT+=" -D ${STOREFRONT_DOMAIN}" |
79 |
SESSION_LIST=$(storebrowse -E ${OPT} ${STOREFRONT_STORE}) |
SESSION_LIST=$(storebrowse -E ${OPT} ${STOREFRONT_STORE} 2> /dev/null) |
80 |
|
if [[ $? != 0 ]] |
81 |
|
then |
82 |
|
echo "could not retrieve session list" |
83 |
|
exit 1 |
84 |
|
fi |
85 |
|
|
86 |
# exclude the desktop session, which is always the first |
# exclude the desktop session, which is always the first |
87 |
declare -i counter=0 |
declare -i counter=0 |
88 |
echo "${SESSION_LIST}" | while read line |
while read line |
89 |
do |
do |
90 |
if [[ ${counter} -gt 0 ]] |
if [[ ${counter} -gt 0 ]] |
91 |
then |
then |
92 |
session=$(echo ${line} | cut -d"'" -f 2) |
session=$(echo ${line} | cut -d"'" -f 2) |
93 |
description=$(echo ${line} | cut -d"'" -f 4) |
description=$(echo ${line} | cut -d"'" -f 4) |
94 |
echo "Session: '${session}' -> Description '${description}'" |
decho "Session: '${session}' -> Description '${description}'" |
95 |
|
|
96 |
|
# import or update db entry |
97 |
|
id=$(mysqldo "select id from values_storefront_session where session='${session}';") |
98 |
|
if [[ -z ${id} ]] |
99 |
|
then |
100 |
|
mysqldo "insert into values_storefront_session (session,description,store,enabled) values('${session}','${description}','${STOREFRONT_STORE}','1');" |
101 |
|
else |
102 |
|
mysqldo "update values_storefront_session set session='${session}',description='${description}',store='${STOREFRONT_STORE}',enabled='1' where id='${id}';" |
103 |
|
fi |
104 |
|
|
105 |
|
# get and save id |
106 |
|
id=$(mysqldo "select id from values_storefront_session where session='${session}';") |
107 |
|
export IMPORTED_IDS+=" ${id}" |
108 |
fi |
fi |
109 |
(( counter++ )) |
(( counter++ )) |
110 |
|
done << EOF |
111 |
|
$(echo "${SESSION_LIST}") |
112 |
|
EOF |
113 |
|
|
114 |
|
# now disable all other ids in the database |
115 |
|
DATABASE_IDS=$(mysqldo "select id from values_storefront_session") |
116 |
|
for id in ${DATABASE_IDS} |
117 |
|
do |
118 |
|
if is_not_an_import_id "${id}" |
119 |
|
then |
120 |
|
# disable this one, not imported=not existing on the storefront-server in the moment |
121 |
|
mysqldo "update values_storefront_session set enabled='0' where id='${id}';" |
122 |
|
fi |
123 |
done |
done |
124 |
fi |
fi |
125 |
|
|
126 |
|
exit 0 |