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