Magellan Linux

Contents of /alx-src/trunk/alxconfig-ng/functions/config_sessions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 338 - (show annotations) (download) (as text)
Tue Sep 27 22:50:36 2005 UTC (18 years, 7 months ago) by niro
File MIME type: application/x-sh
File size: 14887 byte(s)
- fixed wrong fluxbox keys import
- added screensaver selection support  with optional passwd

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