Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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