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 236 by niro, Thu Mar 10 01:11:38 2005 UTC alx-src/branches/alxconf-060/functions/config_sessions.sh revision 2001 by niro, Mon May 9 14:51:55 2011 UTC
# Line 1  Line 1 
1  # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.1 2005-03-10 01:10:47 niro Exp $  # $Id$
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 browser_address_num
60     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     local ses_colors
68    
69     # get settings from database
70     all_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'")
71    
72     for i in ${all_ids}
73     do
74     # get settings
75     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    
82     # get the right colors
83     ses_colors=$(mysqldo "select depth from cfg_graphic where serial='${ALX_SERIAL}'")
84     # convert to ica session file values
85     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     # 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     declare -i x=0
98     for server in ${ses_browseradrs}
99     do
100     (( x++ ))
101     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     done
107     IFS="${OLD_IFS}"
108     unset x
109     unset OLD_IFS
110    
111     echo 'ScreenPercent=0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
112    
113     echo '[ApplicationServers]' >> ${ALX_ICA_SESSIONS}/${ses_filename}
114     echo "${ses_session}=" >> ${ALX_ICA_SESSIONS}/${ses_filename}
115    
116     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     echo "DesiredColor=${ses_colors}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
120     echo 'TransportDriver=TCP/IP' >> ${ALX_ICA_SESSIONS}/${ses_filename}
121     echo 'WinStationDriver=ICA 3.0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
122     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     echo 'UseFullScreen=Yes' >> ${ALX_ICA_SESSIONS}/${ses_filename}
126     echo 'NoWindowManager=True' >> ${ALX_ICA_SESSIONS}/${ses_filename}
127     done
128    }
129    
130    # 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    get_other_menuitems()
163    {
164     local x i progsh_path name exec icon workdir
165    
166     # all arrays:
167     # ->  session1 session2 ... sessionN
168    
169     # get settings from database -> now stored in ALX_PROGRAMS
170    
171     # 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    
178     # 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    
187     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    
192     # 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    }
207    
208    # helper functions for generate all desktop icons
209    generate_icon()
210    {
211     local name
212   local icon   local icon
213     local command
214     local dest
215     local yres
216     local xres
217     local iwidth
218     local iheight
219     local deficon
220    
221   # DEBUG   # very basic getops
222   declare -i i=0   for i in $*
223   echo count=${count}   do
224   echo "Number of new sessions: ${count}"   case $1 in
225   for ((i=0; i < count; i++))   --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     --default-icon) shift; deficon="$1" ;;
234             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     [ -z "${xres}" ] && xres=30
246     [ -z "${yres}" ] && xres=30
247     [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"
248     if [ -z "${icon}" ] || [ ! -f "${icon}" ]
249     then
250     # if no default icon is given use default.png
251     [ -z "${deficon}" ] && deficon="default.png"
252     icon="${ALX_SESSIONS_ICONS}/${deficon}"
253     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     local basename_item
283     local progsh_path
284    
285     # get the resolution
286     res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")
287    
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     declare -i x=30
307     declare -i y=30
308    
309     # first all ica sessions
310     local count=${#ALX_SESSIONS[*]}
311     for (( i=0; i < count; i++ ))
312     do
313     # filenames !
314     icon_list="${icon_list} ${ALX_SESSIONS[${i}]}"
315     done
316    
317     for item in ${icon_list}
318   do   do
319   echo "${i} - ${ALX_SESSIONS[${i}]}"   # abort if empty
320     [ -z "${item}" ] && continue
321    
322     # new line if x > xres
323     if [ ${x} -ge ${xres} ];then
324     x=30
325     y=$((${y} + 80))
326     fi
327    
328     # new row if y > yres
329     if [ ${y} -ge ${yres} ];then
330     x=$((${x} + 120))
331     y=30
332    
333     # re-check x
334     [ ${x} -ge ${xres} ] && x=30
335     fi
336    
337     # ica icons
338     # get basename (.ica must be suffix)
339     basename_item="$(basename ${item} .ica)"
340     generate_icon \
341     --name "${basename_item}" \
342     --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/${item}" \
343     --icon "${ALX_SESSIONS_ICONS}/${basename_item}.png" \
344     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${basename_item}.lnk" \
345     --xres "${x}" \
346     --yres "${y}"
347    
348     y=$((${y} + 80))
349     done
350    
351    
352     # 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     x=30
365     y=$((${y} + 80))
366     fi
367    
368     # new row if y > yres
369     if [ ${y} -ge ${yres} ];then
370     x=$((${x} + 120))
371     y=30
372    
373     # re-check x
374     [ ${x} -ge ${xres} ] && x=30
375     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   done
388    
389    
390    
391     # 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     hostname=$(mysqldo "select hostname from cfg_network where serial='${ALX_SERIAL}'")
398     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    config_sessions()
421    {
422     # generate ica session files
423     generate_ica_session_files
424    
425     # first of all get the vars
426     get_sessions_settings
427     get_autostart_settings
428     get_screensaver_settings
429    
430     local count=${#ALX_SESSIONS[*]}
431     local icon
432     local i
433    
434   # now setup fluxbox for user station   # now setup fluxbox for user station
435    
436   # create a fresh fluxbox directory   # create a fresh fluxbox directory
# Line 62  config_sessions() Line 447  config_sessions()
447   cat ${ALX_SKELETONS}/fluxbox/apps \   cat ${ALX_SKELETONS}/fluxbox/apps \
448   > ${ALX_UNPRIV_HOME}/.fluxbox/apps   > ${ALX_UNPRIV_HOME}/.fluxbox/apps
449    
450     # 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     # add autostart session
467     if [[ ${ALX_AUTOSTART} != "" ]]
468     then
469     echo "[startup] {nohup nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART} &}" \
470     >> ${ALX_UNPRIV_HOME}/.fluxbox/apps
471     fi
472    
473   # fluxbox hotkeys   # fluxbox hotkeys
474   cat ${ALX_SKELETONS}/fluxbox/apps \   cat ${ALX_SKELETONS}/fluxbox/keys \
475   > ${ALX_UNPRIV_HOME}/.fluxbox/keys   > ${ALX_UNPRIV_HOME}/.fluxbox/keys
476    
477   # fluxbox menu header   # fluxbox menu header
478   cat ${ALX_SKELETONS}/fluxbox/menu.header \   cat ${ALX_SKELETONS}/fluxbox/menu.header \
479   > ${ALX_UNPRIV_HOME}/.fluxbox/menu   > ${ALX_UNPRIV_HOME}/.fluxbox/menu
480    
481     # 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     # add a newline (maybe there is no crlf in the header)
487     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
488    
489   # fluxbox menu sessions   # fluxbox menu sessions
490   for (( i=0; i < count; i++ ))   for (( i=0; i < count; i++ ))
491   do   do
492   echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {wfica ${ALX_ICA_SESSIONS}/${i}}" \   [ -n "${ALX_SESSIONS[${i}]}" ] && \
493   >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \
494     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
495   done   done
496    
497     # add other menuitems
498     get_other_menuitems >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
499    
500   # fluxbox menu footer   # fluxbox menu footer
501   cat ${ALX_SKELETONS}/fluxbox/menu.footer \   cat ${ALX_SKELETONS}/fluxbox/menu.footer \
502   >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
503    
504     # add a newline (maybe there is no crlf in the footer)
505     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
506    
507   # now we generate the desktop icons   # now it's a good time to generate *all* icons :)
508   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}/${i}  
 Icon: ${icon}  
 end" > ${ALX_UNPRIV_HOME}/.idesktop/${name}.lnk  
  done  
509    
510   # set correct permissions   # set correct permissions
511   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
512   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
513   chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox   chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
514   chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop   chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
515   chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc   chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc
   
516    
517   # unset vars   # unset vars
518   unset ALX_SESSIONS   unset ALX_SESSIONS
519     unset ALX_PROGRAMS
520     unset ALX_SCRN_SAVER
521     unset ALX_SCRN_TIMEOUT
522     unset ALX_SCRN_PASSWD
523  }  }
524    

Legend:
Removed from v.236  
changed lines
  Added in v.2001