Contents of /alx-src/trunk/alxconfig-ng/functions/config_sessions.sh
Parent Directory | Revision Log
Revision 311 -
(show annotations)
(download)
(as text)
Sun Aug 28 22:50:09 2005 UTC (19 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 11714 byte(s)
Sun Aug 28 22:50:09 2005 UTC (19 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 11714 byte(s)
fixed a typo
1 | # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.12 2005-08-28 22:50:09 niro Exp $ |
2 | # configures ica-sessions on the host via mysql db settings |
3 | |
4 | get_sessions_settings() |
5 | { |
6 | local x i all count |
7 | |
8 | # all arrays: |
9 | # -> session1 session2 ... sessionN |
10 | |
11 | # get settings from database |
12 | all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
13 | "select filename from cfg_sessions where serial='${ALX_SERIAL}'") |
14 | |
15 | # split'em up and put in an array (only if $all not zero) |
16 | declare -i i=0 |
17 | if [ -n "${all}" ] |
18 | then |
19 | for x in ${all} |
20 | do |
21 | ALX_SESSIONS[${i}]=${x} |
22 | ((i++)) |
23 | done |
24 | count=${i} |
25 | else |
26 | count=0 |
27 | fi |
28 | |
29 | export ALX_SESSIONS |
30 | } |
31 | |
32 | get_autostart_settings() |
33 | { |
34 | # get settings from database |
35 | ALX_AUTOSTART=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
36 | "select session from cfg_autostart where serial='${ALX_SERIAL}'") |
37 | |
38 | export ALX_AUTOSTART |
39 | } |
40 | |
41 | generate_ica_session_files() |
42 | { |
43 | local all_ids |
44 | local i |
45 | local x |
46 | local server |
47 | local ses_session |
48 | local ses_filename |
49 | local ses_username |
50 | local ses_domain |
51 | local ses_password |
52 | local ses_browseradrs |
53 | local ses_colors |
54 | |
55 | # get settings from database |
56 | all_ids=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
57 | "select id from cfg_sessions where serial='${ALX_SERIAL}'") |
58 | |
59 | for i in ${all_ids} |
60 | do |
61 | # get settings |
62 | ses_session=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
63 | "select session from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") |
64 | |
65 | ses_filename=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
66 | "select filename from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") |
67 | |
68 | ses_username=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
69 | "select username from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") |
70 | |
71 | ses_domain=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
72 | "select domain from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") |
73 | |
74 | ses_password=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
75 | "select password from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") |
76 | |
77 | ses_browseradrs=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
78 | "select browseradrs from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") |
79 | |
80 | # get the right colors |
81 | ses_colors=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
82 | "select depth from cfg_graphic where serial='${ALX_SERIAL}'") |
83 | case ${ses_colors} in |
84 | 24) ses_colors="8";; |
85 | 16) ses_colors="4";; |
86 | 8) ses_colors="2";; |
87 | *) ses_colors="2";; |
88 | esac |
89 | |
90 | # write session files |
91 | echo '[WFClient]' > ${ALX_ICA_SESSIONS}/${ses_filename} |
92 | echo 'Version=2' >> ${ALX_ICA_SESSIONS}/${ses_filename} |
93 | OLD_IFS="$IFS" |
94 | IFS=";" |
95 | declare -i x=0 |
96 | for server in ${ses_browseradrs} |
97 | do |
98 | (( x++ )) |
99 | echo "TcpBrowserAddress${x}=${server}" >> ${ALX_ICA_SESSIONS}/${ses_filename} |
100 | done |
101 | IFS="${OLD_IFS}" |
102 | unset x |
103 | unset OLD_IFS |
104 | |
105 | echo 'ScreenPercent=0' >> ${ALX_ICA_SESSIONS}/${ses_filename} |
106 | |
107 | echo '[ApplicationServers]' >> ${ALX_ICA_SESSIONS}/${ses_filename} |
108 | echo "${ses_session}=" >> ${ALX_ICA_SESSIONS}/${ses_filename} |
109 | |
110 | echo "[${ses_session}]" >> ${ALX_ICA_SESSIONS}/${ses_filename} |
111 | echo "Address=${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename} |
112 | echo "InitialProgram=#${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename} |
113 | echo "DesiredColor=${ses_colors}" >> ${ALX_ICA_SESSIONS}/${ses_filename} |
114 | echo 'TransportDriver=TCP/IP' >> ${ALX_ICA_SESSIONS}/${ses_filename} |
115 | echo 'WinStationDriver=ICA 3.0' >> ${ALX_ICA_SESSIONS}/${ses_filename} |
116 | echo "ClearPassword=${ses_password}" >> ${ALX_ICA_SESSIONS}/${ses_filename} |
117 | echo "Username=${ses_username}" >> ${ALX_ICA_SESSIONS}/${ses_filename} |
118 | echo "Domain=${ses_domain}" >> ${ALX_ICA_SESSIONS}/${ses_filename} |
119 | echo 'UseFullScreen=Yes' >> ${ALX_ICA_SESSIONS}/${ses_filename} |
120 | echo 'NoWindowManager=True' >> ${ALX_ICA_SESSIONS}/${ses_filename} |
121 | done |
122 | } |
123 | |
124 | get_other_menuitems() |
125 | { |
126 | local x i count name exec icon workdir |
127 | |
128 | # all arrays: |
129 | # -> session1 session2 ... sessionN |
130 | |
131 | # get settings from database |
132 | count=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
133 | "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'") |
134 | |
135 | # get all instances and put them into an array |
136 | if [ -n "${count}" ] |
137 | then |
138 | for x in ${count} |
139 | do |
140 | # to be sure |
141 | unset name |
142 | unset exec |
143 | unset workdir |
144 | unset icon |
145 | |
146 | name=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
147 | "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") |
148 | |
149 | exec=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
150 | "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") |
151 | |
152 | workdir=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
153 | "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") |
154 | |
155 | icon=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
156 | "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") |
157 | |
158 | # debug only |
159 | #echo "DEBUG: ${x}: name:'${name}' exec:'${exec}' workdir:'${workdir}' ic$ |
160 | |
161 | # now echo config line for fluxbox-menu |
162 | # make it "configureable" :P |
163 | [ -n "${workdir}" ] && workdir="cd ${workdir};" |
164 | [ -n "${icon}" ] && icon="[${icon}]" |
165 | echo "[exec] (${name}) {${workdir}${exec}} ${icon}" |
166 | done |
167 | fi |
168 | } |
169 | |
170 | |
171 | # helper functions for generate all desktop icons |
172 | generate_icon() |
173 | { |
174 | local name |
175 | local icon |
176 | local command |
177 | local dest |
178 | local yres |
179 | local xres |
180 | local iwidth |
181 | local iheight |
182 | |
183 | # very basic getops |
184 | for i in $* |
185 | do |
186 | case $1 in |
187 | --name|-n) shift; name="$1" ;; |
188 | --command|-c) shift; command="$1" ;; |
189 | --icon|-i) shift; icon="$1" ;; |
190 | --dest|-d) shift; dest="$1" ;; |
191 | --xres|-x) shift; xres="$1" ;; |
192 | --yres|-y) shift; yres="$1" ;; |
193 | --icon-width|-w) shift; iwidth="$1" ;; |
194 | --icon-height|-h) shift; iheight="$1" ;; |
195 | esac |
196 | shift |
197 | done |
198 | |
199 | # some sanity checks : |
200 | |
201 | # abort if name or command not given |
202 | [ -z "${name}" ] && return 1 |
203 | [ -z "${command}" ] && return 1 |
204 | |
205 | # use some defaults for icon, dest, {x,y}res |
206 | [ -z "${xres}" ] && xres=20 |
207 | [ -z "${yres}" ] && xres=20 |
208 | [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk" |
209 | if [ -z "${icon}" ] || [ ! -f "${icon}" ] |
210 | then |
211 | icon="${ALX_SESSIONS_ICONS}/default.png" |
212 | fi |
213 | |
214 | echo "table Icon" > ${dest} |
215 | echo " Type: Program" >> ${dest} |
216 | echo " Caption: ${name}" >> ${dest} |
217 | echo " Command: ${command}" >> ${dest} |
218 | echo " Icon: ${icon}" >> ${dest} |
219 | echo " X: ${xres}" >> ${dest} |
220 | echo " Y: ${yres}" >> ${dest} |
221 | |
222 | # add these only if not zero |
223 | if [ -n "${iwidth}" ] && [ -n "${iheight}" ] |
224 | then |
225 | echo " IconWidth: ${iwidth}" >> ${dest} |
226 | echo " IconHeight: ${iheight}" >> ${dest} |
227 | fi |
228 | |
229 | echo "end" >> ${dest} |
230 | } |
231 | |
232 | generate_all_desktop_icons() |
233 | { |
234 | local res |
235 | local xres |
236 | local yres |
237 | local icon_list |
238 | local x |
239 | local y |
240 | local item |
241 | |
242 | # get the resolution |
243 | res=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
244 | "select resolution from cfg_graphic where serial='${ALX_SERIAL}'") |
245 | |
246 | # split res to x & y |
247 | xres="$(echo ${res} | cut -dx -f1)" |
248 | yres="$(echo ${res} | cut -dx -f2)" |
249 | |
250 | # top left edge of the icon is given in config file |
251 | # remove a little bit to simulate the bottom-right edge |
252 | xres="$(( ${xres} - 120 ))" |
253 | yres="$(( ${yres} - 80 ))" |
254 | |
255 | # basic config |
256 | cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc |
257 | |
258 | # clean desktop icon location |
259 | [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop |
260 | install -d ${ALX_UNPRIV_HOME}/.xtdesktop |
261 | |
262 | |
263 | # default settings |
264 | declare -i x=20 |
265 | declare -i y=20 |
266 | |
267 | # first all ica sessions |
268 | local count=${#ALX_SESSIONS[*]} |
269 | for (( i=0; i < count; i++ )) |
270 | do |
271 | icon_list="${icon_list} $(basename ${ALX_SESSIONS[${i}]} .ica)" |
272 | done |
273 | |
274 | for item in ${icon_list} |
275 | do |
276 | # abort if empty |
277 | [ -z "${item}" ] && continue |
278 | |
279 | # new line if x > xres |
280 | if [ ${x} -ge ${xres} ];then |
281 | x=20 |
282 | y=$((${y} + 80)) |
283 | fi |
284 | |
285 | # new row if y > yres |
286 | if [ ${y} -ge ${yres} ];then |
287 | x=$((${x} + 120)) |
288 | y=20 |
289 | |
290 | # re-check x |
291 | [ ${x} -ge ${xres} ] && x=20 |
292 | fi |
293 | |
294 | generate_icon \ |
295 | --name "${item}" \ |
296 | --command "wfica ${ALX_ICA_SESSIONS}/${item}.ica" \ |
297 | --icon "${ALX_SESSIONS_ICONS}/${item}.png" \ |
298 | --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \ |
299 | --xres "${x}" \ |
300 | --yres "${y}" |
301 | |
302 | y=$((${y} + 80)) |
303 | done |
304 | |
305 | |
306 | # last but not least gen a icon with some sys informations |
307 | local sysinfo |
308 | local hostname |
309 | local osversion |
310 | |
311 | osversion="$(< /etc/mageversion)" |
312 | hostname=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
313 | "select hostname from cfg_network where serial='${ALX_SERIAL}'") |
314 | sysinfo="Hostname: ${hostname} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)" |
315 | |
316 | # now get the right position: |
317 | # restore orig values of xres |
318 | xres="$(( ${xres} + 120 ))" |
319 | # default y pos (full yres -22 = cur yres + 58 !) |
320 | yres="$(( ${yres} + 58 ))" |
321 | # middle of the screen |
322 | # (no txt - length required, xtdesk manage that itself) |
323 | xres="$(( ${xres} / 2))" |
324 | |
325 | generate_icon \ |
326 | --name "${sysinfo}" \ |
327 | --command "exit 0" \ |
328 | --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \ |
329 | --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \ |
330 | --xres "${xres}" \ |
331 | --yres "${yres}" \ |
332 | --icon-width "1" \ |
333 | --icon-height "1" |
334 | } |
335 | |
336 | config_sessions() |
337 | { |
338 | # generate ica session files |
339 | generate_ica_session_files |
340 | |
341 | # first of all get the vars |
342 | get_sessions_settings |
343 | get_autostart_settings |
344 | |
345 | local count=${#ALX_SESSIONS[*]} |
346 | local icon |
347 | local i |
348 | |
349 | # DEBUG |
350 | # declare -i i=0 |
351 | # echo count=${count} |
352 | # echo "Number of new sessions: ${count}" |
353 | # for ((i=0; i < count; i++)) |
354 | # do |
355 | # echo "${i} - ${ALX_SESSIONS[${i}]}" |
356 | # done |
357 | |
358 | # now setup fluxbox for user station |
359 | |
360 | # create a fresh fluxbox directory |
361 | [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox |
362 | install -d ${ALX_UNPRIV_HOME}/.fluxbox |
363 | |
364 | # now generate fluxbox config files |
365 | |
366 | # fluxbox main config |
367 | cat ${ALX_SKELETONS}/fluxbox/init \ |
368 | > ${ALX_UNPRIV_HOME}/.fluxbox/init |
369 | |
370 | # fluxbox autostart |
371 | cat ${ALX_SKELETONS}/fluxbox/apps \ |
372 | > ${ALX_UNPRIV_HOME}/.fluxbox/apps |
373 | |
374 | # add autostart session |
375 | if [[ ${ALX_AUTOSTART} != "" ]] |
376 | then |
377 | echo "[startup] {wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART}}" \ |
378 | >> ${ALX_UNPRIV_HOME}/.fluxbox/apps |
379 | fi |
380 | |
381 | # fluxbox hotkeys |
382 | cat ${ALX_SKELETONS}/fluxbox/apps \ |
383 | > ${ALX_UNPRIV_HOME}/.fluxbox/keys |
384 | |
385 | # fluxbox menu header |
386 | cat ${ALX_SKELETONS}/fluxbox/menu.header \ |
387 | > ${ALX_UNPRIV_HOME}/.fluxbox/menu |
388 | |
389 | # now fix it with proper messages :P |
390 | local ver="$(< /etc/mageversion)" |
391 | sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" \ |
392 | ${ALX_UNPRIV_HOME}/.fluxbox/menu |
393 | |
394 | # add a newline (maybe there is no crlf in the header) |
395 | echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu |
396 | |
397 | # fluxbox menu sessions |
398 | for (( i=0; i < count; i++ )) |
399 | do |
400 | [ -n "${ALX_SESSIONS[${i}]}" ] && \ |
401 | echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \ |
402 | >> ${ALX_UNPRIV_HOME}/.fluxbox/menu |
403 | done |
404 | |
405 | # add other menuitems |
406 | get_other_menuitems >> ${ALX_UNPRIV_HOME}/.fluxbox/menu |
407 | |
408 | # fluxbox menu footer |
409 | cat ${ALX_SKELETONS}/fluxbox/menu.footer \ |
410 | >> ${ALX_UNPRIV_HOME}/.fluxbox/menu |
411 | |
412 | # add a newline (maybe there is no crlf in the footer) |
413 | echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu |
414 | |
415 | # now it's a good time to generate *all* icons :) |
416 | generate_all_desktop_icons |
417 | |
418 | # set correct permissions |
419 | chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME} |
420 | chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox |
421 | chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox |
422 | chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop |
423 | chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc |
424 | |
425 | # unset vars |
426 | unset ALX_SESSIONS |
427 | } |