Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 317 - (hide annotations) (download) (as text)
Thu Sep 1 18:27:44 2005 UTC (18 years, 8 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_sessions.sh
File MIME type: application/x-sh
File size: 13602 byte(s)
- added option --default-icon to generate_icon()
- now creating also program desktop icons
- simplify creation of menuitem and desktop icons for program with help of generate_program_sh()
- fetching list of program now earlier to minimize the overhead of mysql calls

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