Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

alx-src/trunk/alxconfig-ng/functions/config_sessions.sh revision 239 by niro, Tue Apr 12 20:46:52 2005 UTC alx-src/tags/alxconf_20060908_1/alxconfig-ng/functions/config_sessions.sh revision 375, Mon Feb 20 14:49:31 2006 UTC
# Line 1  Line 1 
1  # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.3 2005-04-12 20:45:55 niro Exp $  # $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  # configures ica-sessions on the host via mysql db settings  # configures ica-sessions on the host via mysql db settings
3    
4  get_sessions_settings()  get_sessions_settings()
5  {  {
6   local x i all count   local x i all count
7    
8   #all arrays:   # all arrays:
9   # ->  session1 session2 ... sessionN   # ->  session1 session2 ... sessionN
10    
11   #get settings from database   # get settings from database
12   all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   all=$(mysqldo "select filename from cfg_sessions where serial='${ALX_SERIAL}'")
  "select session from cfg_sessions where serial='${ALX_SERIAL}'")  
13    
14   #split'em up and put in an array (only if $all not zero)   # split'em up and put in an array (only if $all not zero)
15   declare -i i=0   declare -i i=0
16   if [ -n "${all}" ]   if [ -n "${all}" ]
17   then   then
# Line 26  get_sessions_settings() Line 25  get_sessions_settings()
25   count=0   count=0
26   fi   fi
27    
28     # get settings from database
29     ALX_PROGRAMS=$(mysqldo "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'")
30    
31   export ALX_SESSIONS   export ALX_SESSIONS
32     export ALX_PROGRAMS
33  }  }
34    
35  config_sessions()  get_autostart_settings()
36  {  {
37   #first of all get the vars   # get settings from database
38   get_sessions_settings   ALX_AUTOSTART=$(mysqldo "select session from cfg_autostart where serial='${ALX_SERIAL}'")
39    
40   local count=${#ALX_SESSIONS[*]}   export ALX_AUTOSTART
41    }
42    
43    get_screensaver_settings()
44    {
45     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    
49     export ALX_SCRN_SAVER
50     export ALX_SCRN_TIMEOUT
51     export ALX_SCRN_PASSWD
52    }
53    
54    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     local ses_colors
67    
68     # get settings from database
69     all_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'")
70    
71     for i in ${all_ids}
72     do
73     # get settings
74     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    
81     # get the right colors
82     ses_colors=$(mysqldo "select depth from cfg_graphic where serial='${ALX_SERIAL}'")
83     # convert to ica session file values
84     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     # 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     declare -i x=0
97     for server in ${ses_browseradrs}
98     do
99     (( x++ ))
100     echo "TcpBrowserAddress${x}=${server}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
101     done
102     IFS="${OLD_IFS}"
103     unset x
104     unset OLD_IFS
105    
106     echo 'ScreenPercent=0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
107    
108     echo '[ApplicationServers]' >> ${ALX_ICA_SESSIONS}/${ses_filename}
109     echo "${ses_session}=" >> ${ALX_ICA_SESSIONS}/${ses_filename}
110    
111     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     echo "DesiredColor=${ses_colors}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
115     echo 'TransportDriver=TCP/IP' >> ${ALX_ICA_SESSIONS}/${ses_filename}
116     echo 'WinStationDriver=ICA 3.0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
117     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     echo 'UseFullScreen=Yes' >> ${ALX_ICA_SESSIONS}/${ses_filename}
121     echo 'NoWindowManager=True' >> ${ALX_ICA_SESSIONS}/${ses_filename}
122     done
123    }
124    
125    # 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    get_other_menuitems()
158    {
159     local x i progsh_path name exec icon workdir
160    
161     # all arrays:
162     # ->  session1 session2 ... sessionN
163    
164     # get settings from database -> now stored in ALX_PROGRAMS
165    
166     # 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    
173     # 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    
182     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    
187     # 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    }
202    
203    # helper functions for generate all desktop icons
204    generate_icon()
205    {
206     local name
207   local icon   local icon
208     local command
209     local dest
210     local yres
211     local xres
212     local iwidth
213     local iheight
214     local deficon
215    
216   # DEBUG   # very basic getops
217   declare -i i=0   for i in $*
218   echo count=${count}   do
219   echo "Number of new sessions: ${count}"   case $1 in
220   for ((i=0; i < count; i++))   --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     --default-icon) shift; deficon="$1" ;;
229             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     # if no default icon is given use default.png
246     [ -z "${deficon}" ] && deficon="default.png"
247     icon="${ALX_SESSIONS_ICONS}/${deficon}"
248     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     local basename_item
278     local progsh_path
279    
280     # get the resolution
281     res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")
282    
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   do
308   echo "${i} - ${ALX_SESSIONS[${i}]}"   # filenames !
309     icon_list="${icon_list} ${ALX_SESSIONS[${i}]}"
310   done   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     # ica icons
333     # get basename (.ica must be suffix)
334     basename_item="$(basename ${item} .ica)"
335     generate_icon \
336     --name "${basename_item}" \
337     --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/${item}" \
338     --icon "${ALX_SESSIONS_ICONS}/${basename_item}.png" \
339     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${basename_item}.lnk" \
340     --xres "${x}" \
341     --yres "${y}"
342    
343     y=$((${y} + 80))
344     done
345    
346    
347     # 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     # 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     hostname=$(mysqldo "select hostname from cfg_network where serial='${ALX_SERIAL}'")
393     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    config_sessions()
416    {
417     # generate ica session files
418     generate_ica_session_files
419    
420     # first of all get the vars
421     get_sessions_settings
422     get_autostart_settings
423     get_screensaver_settings
424    
425     local count=${#ALX_SESSIONS[*]}
426     local icon
427     local i
428    
429   # now setup fluxbox for user station   # now setup fluxbox for user station
430    
431   # create a fresh fluxbox directory   # create a fresh fluxbox directory
# Line 62  config_sessions() Line 442  config_sessions()
442   cat ${ALX_SKELETONS}/fluxbox/apps \   cat ${ALX_SKELETONS}/fluxbox/apps \
443   > ${ALX_UNPRIV_HOME}/.fluxbox/apps   > ${ALX_UNPRIV_HOME}/.fluxbox/apps
444    
445     # 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     # add autostart session
462     if [[ ${ALX_AUTOSTART} != "" ]]
463     then
464     echo "[startup] {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART}}" \
465     >> ${ALX_UNPRIV_HOME}/.fluxbox/apps
466     fi
467    
468   # fluxbox hotkeys   # fluxbox hotkeys
469   cat ${ALX_SKELETONS}/fluxbox/apps \   cat ${ALX_SKELETONS}/fluxbox/keys \
470   > ${ALX_UNPRIV_HOME}/.fluxbox/keys   > ${ALX_UNPRIV_HOME}/.fluxbox/keys
471    
472   # fluxbox menu header   # fluxbox menu header
473   cat ${ALX_SKELETONS}/fluxbox/menu.header \   cat ${ALX_SKELETONS}/fluxbox/menu.header \
474   > ${ALX_UNPRIV_HOME}/.fluxbox/menu   > ${ALX_UNPRIV_HOME}/.fluxbox/menu
475    
476     # 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   # add a newline (maybe there is no crlf in the header)   # add a newline (maybe there is no crlf in the header)
482   echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
483    
484   # fluxbox menu sessions   # fluxbox menu sessions
485   for (( i=0; i < count; i++ ))   for (( i=0; i < count; i++ ))
486   do   do
487   echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \   [ -n "${ALX_SESSIONS[${i}]}" ] && \
488   >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \
489     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
490   done   done
491    
492     # add other menuitems
493     get_other_menuitems >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
494    
495   # fluxbox menu footer   # fluxbox menu footer
496   cat ${ALX_SKELETONS}/fluxbox/menu.footer \   cat ${ALX_SKELETONS}/fluxbox/menu.footer \
497   >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
# Line 87  config_sessions() Line 499  config_sessions()
499   # add a newline (maybe there is no crlf in the footer)   # add a newline (maybe there is no crlf in the footer)
500   echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
501    
502   # now we generate the desktop icons   # now it's a good time to generate *all* icons :)
503   cat ${ALX_SKELETONS}/idesk/ideskrc \   generate_all_desktop_icons
  > ${ALX_UNPRIV_HOME}/.ideskrc  
   
  # whipe out old stuff and install a fresh directory  
  [ -d ${ALX_UNPRIV_HOME}/.idesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.idesktop  
  install -d ${ALX_UNPRIV_HOME}/.idesktop  
   
  local name  
  for (( i=0; i < count; i++ ))  
  do  
  name="$(basename ${ALX_SESSIONS[${i}]} .ica)"  
   
  if [ -f ${ALX_SESSIONS_ICONS}/${name}.png ]  
  then  
  icon="${ALX_SESSIONS_ICONS}/${name}.png"  
  else  
  icon="${ALX_SESSIONS_ICONS}/default.png"  
  fi  
   
  echo "table Icon  
 Caption: ${name}  
 Command: wfica ${ALX_ICA_SESSIONS}/${name}.ica  
 Icon: ${icon}  
 end" > ${ALX_UNPRIV_HOME}/.idesktop/${name}.lnk  
  done  
504    
505   # set correct permissions   # set correct permissions
506   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
507   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
508   chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox   chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
509   chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop   chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
510   chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc   chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc
   
511    
512   # unset vars   # unset vars
513   unset ALX_SESSIONS   unset ALX_SESSIONS
514     unset ALX_PROGRAMS
515     unset ALX_SCRN_SAVER
516     unset ALX_SCRN_TIMEOUT
517     unset ALX_SCRN_PASSWD
518  }  }
519    

Legend:
Removed from v.239  
changed lines
  Added in v.375