Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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