Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2822 - (hide annotations) (download)
Fri Jul 28 09:58:24 2017 UTC (6 years, 9 months ago) by niro
File size: 3294 byte(s)
-do not exclude the first session anymore, just retrieve all. to disable a session use the enable row in the database
1 niro 2511 #!/bin/bash
2    
3     MCORE_LIBDIR="@@MCORE_LIBDIR@@"
4     source @@SYSCONFDIR@@/mcore/mcore.conf
5 niro 2514 source @@SYSCONFDIR@@/mcore/citrix.conf
6 niro 2524 source @@SYSCONFDIR@@/mcore/citrix-enumerate.conf
7 niro 2521 source @@SYSCONFDIR@@/mcore/control.conf
8 niro 2511 source ${MCORE_LIBDIR}/include/common.global.class
9 niro 2515 source ${MCORE_LIBDIR}/include/daemon.global.class
10 niro 2514 source ${MCORE_LIBDIR}/include/mysqlfunctions.global.class
11 niro 2511
12 niro 2514 : ${STOREFRONT_STORE=""}
13     : ${STOREFRONT_USER=""}
14     : ${STOREFRONT_PASS=""}
15     : ${STOREFRONT_DOMAIN=""}
16 niro 2511
17 niro 2522 export IMPORTED_IDS=""
18    
19 niro 2697 LOCKFILE="@@RUNDIR@@/lock/storefront-cron.lock"
20    
21 niro 2522 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 niro 2697 # 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 niro 2524 # 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 niro 2511
51 niro 2821 # 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 niro 2511
55 niro 2514 # get all sessions
56 niro 2821 if [[ -z $(su - ${MCORE_UNPRIV_USER} -c "storebrowse -l" | grep -i ${STOREFRONT_STORE}) ]]
57 niro 2514 then
58     echo "Store ${STOREFRONT_STORE} unknown, perhaps not added. Run 'rm -r ~/.ICAClient'."
59     else
60     OPT=""
61 niro 2517 [[ -n ${STOREFRONT_USER} ]] && OPT+=" -U ${STOREFRONT_USER}"
62     [[ -n ${STOREFRONT_PASS} ]] && OPT+=" -P ${STOREFRONT_PASS}"
63     [[ -n ${STOREFRONT_DOMAIN} ]] && OPT+=" -D ${STOREFRONT_DOMAIN}"
64 niro 2821 SESSION_LIST=$(su - ${MCORE_UNPRIV_USER} -c "storebrowse -E ${OPT} ${STOREFRONT_STORE}" 2> /dev/null)
65 niro 2521 if [[ $? != 0 ]]
66     then
67     echo "could not retrieve session list"
68     exit 1
69     fi
70 niro 2518
71 niro 2522 while read line
72 niro 2518 do
73 niro 2822 session=$(echo ${line} | cut -d"'" -f 2)
74     description=$(echo ${line} | cut -d"'" -f 4)
75     decho "Session: '${session}' -> Description '${description}'"
76    
77     # import or update db entry
78     id=$(mysqldo "select id from values_storefront_session where session='${session}';")
79     if [[ -z ${id} ]]
80 niro 2518 then
81 niro 2822 mysqldo "insert into values_storefront_session (session,description,store,enabled) values('${session}','${description}','${STOREFRONT_STORE}','1');"
82     else
83     mysqldo "update values_storefront_session set session='${session}',description='${description}',store='${STOREFRONT_STORE}',enabled='1' where id='${id}';"
84     fi
85 niro 2521
86 niro 2822 # get and save id
87     id=$(mysqldo "select id from values_storefront_session where session='${session}';")
88     export IMPORTED_IDS+=" ${id}"
89 niro 2522 done << EOF
90     $(echo "${SESSION_LIST}")
91     EOF
92 niro 2521
93     # now disable all other ids in the database
94 niro 2522 DATABASE_IDS=$(mysqldo "select id from values_storefront_session")
95     for id in ${DATABASE_IDS}
96     do
97     if is_not_an_import_id "${id}"
98     then
99     # disable this one, not imported=not existing on the storefront-server in the moment
100     mysqldo "update values_storefront_session set enabled='0' where id='${id}';"
101     fi
102     done
103 niro 2514 fi
104 niro 2697
105     exit 0