Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 377 - (hide annotations) (download) (as text)
Thu Jun 28 12:49:32 2007 UTC (16 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 14506 byte(s)
-added support for several display options

1 niro 377 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.19 2007-06-28 12:49:32 niro Exp $
2 niro 236 # configures ica-sessions on the host via mysql db settings
3    
4     get_sessions_settings()
5     {
6     local x i all count
7    
8 niro 291 # all arrays:
9 niro 236 # -> session1 session2 ... sessionN
10    
11 niro 291 # get settings from database
12 niro 342 all=$(mysqldo "select filename from cfg_sessions where serial='${ALX_SERIAL}'")
13 niro 236
14 niro 291 # split'em up and put in an array (only if $all not zero)
15 niro 236 declare -i i=0
16     if [ -n "${all}" ]
17     then
18     for x in ${all}
19     do
20     ALX_SESSIONS[${i}]=${x}
21     ((i++))
22     done
23     count=${i}
24     else
25     count=0
26     fi
27    
28 niro 317 # get settings from database
29 niro 342 ALX_PROGRAMS=$(mysqldo "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'")
30 niro 317
31 niro 236 export ALX_SESSIONS
32 niro 317 export ALX_PROGRAMS
33 niro 236 }
34    
35 niro 246 get_autostart_settings()
36     {
37 niro 291 # get settings from database
38 niro 342 ALX_AUTOSTART=$(mysqldo "select session from cfg_autostart where serial='${ALX_SERIAL}'")
39 niro 246
40 niro 272 export ALX_AUTOSTART
41 niro 246 }
42    
43 niro 338 get_screensaver_settings()
44     {
45 niro 342 ALX_SCRN_SAVER=$(mysqldo "select screensaver from cfg_screensaver where serial='${ALX_SERIAL}'")
46     ALX_SCRN_TIMEOUT=$(mysqldo "select timeout from cfg_screensaver where serial='${ALX_SERIAL}'")
47     ALX_SCRN_PASSWD=$(mysqldo "select password from cfg_screensaver where serial='${ALX_SERIAL}'")
48 niro 338
49     export ALX_SCRN_SAVER
50     export ALX_SCRN_TIMEOUT
51     export ALX_SCRN_PASSWD
52     }
53    
54 niro 246 generate_ica_session_files()
55     {
56     local all_ids
57     local i
58     local x
59     local server
60     local ses_session
61     local ses_filename
62     local ses_username
63     local ses_domain
64     local ses_password
65     local ses_browseradrs
66 niro 272 local ses_colors
67 niro 377 local ses_display_mode
68     local ses_display_x
69     local ses_display_y
70 niro 246
71 niro 291 # get settings from database
72 niro 342 all_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'")
73 niro 246
74     for i in ${all_ids}
75     do
76     # get settings
77 niro 342 ses_session=$(mysqldo "select session from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
78     ses_filename=$(mysqldo "select filename from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
79     ses_username=$(mysqldo "select username from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
80     ses_domain=$(mysqldo "select domain from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
81     ses_password=$(mysqldo "select password from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
82     ses_browseradrs=$(mysqldo "select browseradrs from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
83 niro 246
84 niro 377 # get the session display mode seamless|fullscreen|or an resolution
85     ses_display_mode=$(mysqldo "select displaymode from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
86    
87 niro 272 # get the right colors
88 niro 342 ses_colors=$(mysqldo "select depth from cfg_graphic where serial='${ALX_SERIAL}'")
89     # convert to ica session file values
90 niro 272 case ${ses_colors} in
91     24) ses_colors="8";;
92     16) ses_colors="4";;
93     8) ses_colors="2";;
94     *) ses_colors="2";;
95     esac
96    
97 niro 246 # write session files
98     echo '[WFClient]' > ${ALX_ICA_SESSIONS}/${ses_filename}
99     echo 'Version=2' >> ${ALX_ICA_SESSIONS}/${ses_filename}
100     OLD_IFS="$IFS"
101     IFS=";"
102 niro 272 declare -i x=0
103     for server in ${ses_browseradrs}
104 niro 246 do
105 niro 272 (( x++ ))
106     echo "TcpBrowserAddress${x}=${server}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
107 niro 246 done
108     IFS="${OLD_IFS}"
109 niro 272 unset x
110 niro 246 unset OLD_IFS
111 niro 377
112 niro 246 echo 'ScreenPercent=0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
113    
114     echo '[ApplicationServers]' >> ${ALX_ICA_SESSIONS}/${ses_filename}
115 niro 272 echo "${ses_session}=" >> ${ALX_ICA_SESSIONS}/${ses_filename}
116 niro 377
117 niro 272 echo "[${ses_session}]" >> ${ALX_ICA_SESSIONS}/${ses_filename}
118     echo "Address=${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
119     echo "InitialProgram=#${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
120 niro 273 echo "DesiredColor=${ses_colors}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
121 niro 246 echo 'TransportDriver=TCP/IP' >> ${ALX_ICA_SESSIONS}/${ses_filename}
122     echo 'WinStationDriver=ICA 3.0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
123 niro 272 echo "ClearPassword=${ses_password}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
124     echo "Username=${ses_username}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
125     echo "Domain=${ses_domain}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
126 niro 377
127     # use the right display settings
128     case ${ses_display_mode} in
129     # fullscreen mode
130     fullscreen)
131     echo 'UseFullScreen=Yes' >> ${ALX_ICA_SESSIONS}/${ses_filename}
132     echo 'NoWindowManager=True' >> ${ALX_ICA_SESSIONS}/${ses_filename}
133     ;;
134     # seamless window mode
135     seamless)
136     echo 'TWIMode=On' >> ${ALX_ICA_SESSIONS}/${ses_filename}
137     ;;
138     # a desired resolution
139     *x*)
140     # split the resolutions
141     ses_display_x=$(echo ${ses_display_mode} | cut -dx -f1)
142     ses_display_y=$(echo ${ses_display_mode} | cut -dx -f2)
143     echo "DesiredHRES=${ses_display_x}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
144     echo "DesiredVRES=${ses_display_x}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
145     ;;
146     # but default to fullscreen if nothing met
147     *)
148     echo 'UseFullScreen=Yes' >> ${ALX_ICA_SESSIONS}/${ses_filename}
149     echo 'NoWindowManager=True' >> ${ALX_ICA_SESSIONS}/${ses_filename}
150     ;;
151     esac
152 niro 246 done
153     }
154    
155 niro 317 # generates a sh file to start programs
156     generate_program_sh()
157     {
158     local dest
159     local name
160     local exec
161     local workdir
162    
163     # very basic getops
164     for i in $*
165     do
166     case $1 in
167     --name|-n) shift; name="$1" ;;
168     --exec|-x) shift; exec="$1" ;;
169     --dest|-d) shift; dest="$1" ;;
170     --workdir|-w) shift; workdir="$1" ;;
171     esac
172     shift
173     done
174    
175     # abort if name, dest or exec not given
176     [ -z "${name}" ] && return 1
177     [ -z "${exec}" ] && return 1
178     [ -z "${dest}" ] && return 1
179    
180     echo "#!/bin/sh" > ${dest}
181     [ -n "${workdir}" ] && echo "cd ${workdir}" >> ${dest}
182     echo "exec ${exec}" >> ${dest}
183    
184     chmod 0755 ${dest}
185     }
186    
187 niro 277 get_other_menuitems()
188     {
189 niro 317 local x i progsh_path name exec icon workdir
190 niro 277
191 niro 291 # all arrays:
192 niro 277 # -> session1 session2 ... sessionN
193    
194 niro 317 # get settings from database -> now stored in ALX_PROGRAMS
195 niro 277
196 niro 317 # abort if empty
197     [ -z "${ALX_PROGRAMS}" ] && return 0
198    
199     progsh_path=${ALX_UNPRIV_HOME}/.alxprogs
200     [ -d ${progsh_path} ] && rm -rf ${progsh_path}
201     install -d ${progsh_path}
202 niro 277
203 niro 317 # gen menu items
204     for x in ${ALX_PROGRAMS}
205     do
206     # to be sure
207     unset name
208     unset exec
209     unset workdir
210     unset icon
211 niro 277
212 niro 342 name=$(mysqldo "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
213     exec=$(mysqldo "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
214     workdir=$(mysqldo "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
215     icon=$(mysqldo "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
216 niro 277
217 niro 317 # now echo config line for fluxbox-menu
218     # make it "configureable" :P
219     [ -n "${workdir}" ] && workdir="--workdir ${workdir}"
220     [ -n "${icon}" ] && icon="<${icon}>"
221    
222     # gen prog startup wrapper
223     generate_program_sh \
224     --name "${name}" \
225     --exec "${exec}" \
226     --dest "${progsh_path}/${name}" \
227     "${workdir}"
228    
229     echo "[exec] (${name}) {${progsh_path}/${name}} ${icon}"
230     done
231 niro 277 }
232    
233 niro 304 # helper functions for generate all desktop icons
234     generate_icon()
235     {
236     local name
237     local icon
238     local command
239     local dest
240     local yres
241     local xres
242     local iwidth
243     local iheight
244 niro 317 local deficon
245 niro 304
246     # very basic getops
247     for i in $*
248     do
249     case $1 in
250     --name|-n) shift; name="$1" ;;
251     --command|-c) shift; command="$1" ;;
252     --icon|-i) shift; icon="$1" ;;
253     --dest|-d) shift; dest="$1" ;;
254     --xres|-x) shift; xres="$1" ;;
255     --yres|-y) shift; yres="$1" ;;
256     --icon-width|-w) shift; iwidth="$1" ;;
257     --icon-height|-h) shift; iheight="$1" ;;
258 niro 317 --default-icon) shift; deficon="$1" ;;
259 niro 304 esac
260     shift
261     done
262    
263     # some sanity checks :
264    
265     # abort if name or command not given
266     [ -z "${name}" ] && return 1
267     [ -z "${command}" ] && return 1
268    
269     # use some defaults for icon, dest, {x,y}res
270     [ -z "${xres}" ] && xres=20
271     [ -z "${yres}" ] && xres=20
272     [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"
273     if [ -z "${icon}" ] || [ ! -f "${icon}" ]
274     then
275 niro 317 # if no default icon is given use default.png
276     [ -z "${deficon}" ] && deficon="default.png"
277     icon="${ALX_SESSIONS_ICONS}/${deficon}"
278 niro 304 fi
279    
280     echo "table Icon" > ${dest}
281     echo " Type: Program" >> ${dest}
282     echo " Caption: ${name}" >> ${dest}
283     echo " Command: ${command}" >> ${dest}
284     echo " Icon: ${icon}" >> ${dest}
285     echo " X: ${xres}" >> ${dest}
286     echo " Y: ${yres}" >> ${dest}
287    
288     # add these only if not zero
289     if [ -n "${iwidth}" ] && [ -n "${iheight}" ]
290     then
291     echo " IconWidth: ${iwidth}" >> ${dest}
292     echo " IconHeight: ${iheight}" >> ${dest}
293     fi
294    
295     echo "end" >> ${dest}
296     }
297    
298     generate_all_desktop_icons()
299     {
300     local res
301     local xres
302     local yres
303     local icon_list
304     local x
305     local y
306     local item
307 niro 324 local basename_item
308 niro 317 local progsh_path
309 niro 304
310     # get the resolution
311 niro 342 res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")
312 niro 304
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 niro 324 # filenames !
339     icon_list="${icon_list} ${ALX_SESSIONS[${i}]}"
340 niro 304 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 niro 324 # ica icons
363     # get basename (.ica must be suffix)
364     basename_item="$(basename ${item} .ica)"
365 niro 304 generate_icon \
366 niro 327 --name "${basename_item}" \
367 niro 373 --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/${item}" \
368 niro 324 --icon "${ALX_SESSIONS_ICONS}/${basename_item}.png" \
369     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${basename_item}.lnk" \
370 niro 304 --xres "${x}" \
371     --yres "${y}"
372    
373     y=$((${y} + 80))
374     done
375    
376    
377 niro 317 # 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 niro 304 # 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 niro 342 hostname=$(mysqldo "select hostname from cfg_network where serial='${ALX_SERIAL}'")
423 niro 304 sysinfo="Hostname: ${hostname} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)"
424    
425     # now get the right position:
426     # restore orig values of xres
427     xres="$(( ${xres} + 120 ))"
428     # default y pos (full yres -22 = cur yres + 58 !)
429     yres="$(( ${yres} + 58 ))"
430     # middle of the screen
431     # (no txt - length required, xtdesk manage that itself)
432     xres="$(( ${xres} / 2))"
433    
434     generate_icon \
435     --name "${sysinfo}" \
436     --command "exit 0" \
437     --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \
438     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \
439     --xres "${xres}" \
440     --yres "${yres}" \
441     --icon-width "1" \
442     --icon-height "1"
443     }
444    
445 niro 236 config_sessions()
446     {
447 niro 246 # generate ica session files
448     generate_ica_session_files
449    
450 niro 291 # first of all get the vars
451 niro 236 get_sessions_settings
452 niro 246 get_autostart_settings
453 niro 338 get_screensaver_settings
454 niro 236
455     local count=${#ALX_SESSIONS[*]}
456     local icon
457 niro 272 local i
458 niro 236
459     # now setup fluxbox for user station
460    
461     # create a fresh fluxbox directory
462     [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox
463     install -d ${ALX_UNPRIV_HOME}/.fluxbox
464    
465     # now generate fluxbox config files
466    
467     # fluxbox main config
468     cat ${ALX_SKELETONS}/fluxbox/init \
469     > ${ALX_UNPRIV_HOME}/.fluxbox/init
470    
471     # fluxbox autostart
472     cat ${ALX_SKELETONS}/fluxbox/apps \
473     > ${ALX_UNPRIV_HOME}/.fluxbox/apps
474    
475 niro 338 # add screensaver
476     if [[ -n ${ALX_SCRN_SAVER} ]] && [[ -n ${ALX_SCRN_TIMEOUT} ]]
477     then
478     local ALX_PASSWD_CMD
479    
480     if [[ -z ${ALX_SCRN_PASSWD} ]] || [[ ${ALX_SCRN_PASSWD} = NULL ]]
481     then
482     ALX_PASSWD_CMD="-nolock"
483     else
484     ALX_PASSWD_CMD="-cpasswd $(openssl passwd ${ALX_SCRN_PASSWD})"
485     fi
486    
487     echo "[startup] {nohup xautolock -time ${ALX_SCRN_TIMEOUT} -locker 'xlock -mode ${ALX_SCRN_SAVER} ${ALX_PASSWD_CMD}' > /dev/null &}" \
488     >> ${ALX_UNPRIV_HOME}/.fluxbox/apps
489     fi
490    
491 niro 246 # add autostart session
492     if [[ ${ALX_AUTOSTART} != "" ]]
493     then
494 niro 373 echo "[startup] {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART}}" \
495 niro 246 >> ${ALX_UNPRIV_HOME}/.fluxbox/apps
496     fi
497    
498 niro 236 # fluxbox hotkeys
499 niro 338 cat ${ALX_SKELETONS}/fluxbox/keys \
500 niro 236 > ${ALX_UNPRIV_HOME}/.fluxbox/keys
501    
502     # fluxbox menu header
503     cat ${ALX_SKELETONS}/fluxbox/menu.header \
504     > ${ALX_UNPRIV_HOME}/.fluxbox/menu
505    
506 niro 291 # now fix it with proper messages :P
507     local ver="$(< /etc/mageversion)"
508     sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" \
509     ${ALX_UNPRIV_HOME}/.fluxbox/menu
510    
511 niro 239 # add a newline (maybe there is no crlf in the header)
512     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
513    
514 niro 236 # fluxbox menu sessions
515     for (( i=0; i < count; i++ ))
516     do
517 niro 277 [ -n "${ALX_SESSIONS[${i}]}" ] && \
518 niro 373 echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \
519 niro 277 >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
520 niro 236 done
521    
522 niro 277 # add other menuitems
523     get_other_menuitems >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
524    
525 niro 236 # fluxbox menu footer
526     cat ${ALX_SKELETONS}/fluxbox/menu.footer \
527     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
528    
529 niro 239 # add a newline (maybe there is no crlf in the footer)
530     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
531 niro 236
532 niro 304 # now it's a good time to generate *all* icons :)
533     generate_all_desktop_icons
534 niro 236
535     # set correct permissions
536     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
537     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
538     chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
539 niro 338 chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
540     chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc
541 niro 236
542     # unset vars
543     unset ALX_SESSIONS
544 niro 317 unset ALX_PROGRAMS
545 niro 338 unset ALX_SCRN_SAVER
546     unset ALX_SCRN_TIMEOUT
547     unset ALX_SCRN_PASSWD
548 niro 236 }
549 niro 338