Magellan Linux

Annotation of /alx-src/branches/alxconf-060/functions/config_sessions.sh

Parent Directory Parent Directory | Revision Log Revision Log


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