Magellan Linux

Diff of /alx-src/trunk/alxconfig-ng/functions/config_sessions.sh

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

revision 272 by niro, Thu Apr 28 22:45:05 2005 UTC revision 338 by niro, Tue Sep 27 22:50:36 2005 UTC
# Line 1  Line 1 
1  # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.7 2005-04-28 22:45:05 niro Exp $  # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.16 2005-09-27 22:50:36 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=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
13   "select filename from cfg_sessions where serial='${ALX_SERIAL}'")   "select filename from cfg_sessions where serial='${ALX_SERIAL}'")
14    
15   #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)
16   declare -i i=0   declare -i i=0
17   if [ -n "${all}" ]   if [ -n "${all}" ]
18   then   then
# Line 26  get_sessions_settings() Line 26  get_sessions_settings()
26   count=0   count=0
27   fi   fi
28    
29     # 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   export ALX_SESSIONS   export ALX_SESSIONS
34     export ALX_PROGRAMS
35  }  }
36    
37  get_autostart_settings()  get_autostart_settings()
38  {  {
39   #get settings from database   # get settings from database
40   ALX_AUTOSTART=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   ALX_AUTOSTART=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
41   "select session from cfg_autostart where serial='${ALX_SERIAL}'")   "select session from cfg_autostart where serial='${ALX_SERIAL}'")
42    
43   export ALX_AUTOSTART   export ALX_AUTOSTART
44  }  }
45    
46    get_screensaver_settings()
47    {
48     ALX_SCRN_SAVER=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
49     "select screensaver from cfg_screensaver where serial='${ALX_SERIAL}'")
50     ALX_SCRN_TIMEOUT=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
51     "select timeout from cfg_screensaver where serial='${ALX_SERIAL}'")
52     ALX_SCRN_PASSWD=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
53     "select password from cfg_screensaver where serial='${ALX_SERIAL}'")
54    
55     export ALX_SCRN_SAVER
56     export ALX_SCRN_TIMEOUT
57     export ALX_SCRN_PASSWD
58    }
59    
60  generate_ica_session_files()  generate_ica_session_files()
61  {  {
62   local all_ids   local all_ids
# Line 52  generate_ica_session_files() Line 71  generate_ica_session_files()
71   local ses_browseradrs   local ses_browseradrs
72   local ses_colors   local ses_colors
73    
74   #get settings from database   # get settings from database
75   all_ids=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   all_ids=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
76   "select id from cfg_sessions where serial='${ALX_SERIAL}'")   "select id from cfg_sessions where serial='${ALX_SERIAL}'")
77    
# Line 110  generate_ica_session_files() Line 129  generate_ica_session_files()
129   echo "[${ses_session}]" >> ${ALX_ICA_SESSIONS}/${ses_filename}   echo "[${ses_session}]" >> ${ALX_ICA_SESSIONS}/${ses_filename}
130   echo "Address=${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename}   echo "Address=${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
131   echo "InitialProgram=#${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename}   echo "InitialProgram=#${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
132   echo 'DesiredColor=${ses_colors}' >> ${ALX_ICA_SESSIONS}/${ses_filename}   echo "DesiredColor=${ses_colors}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
133   echo 'TransportDriver=TCP/IP' >> ${ALX_ICA_SESSIONS}/${ses_filename}   echo 'TransportDriver=TCP/IP' >> ${ALX_ICA_SESSIONS}/${ses_filename}
134   echo 'WinStationDriver=ICA 3.0' >> ${ALX_ICA_SESSIONS}/${ses_filename}   echo 'WinStationDriver=ICA 3.0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
135   echo "ClearPassword=${ses_password}" >> ${ALX_ICA_SESSIONS}/${ses_filename}   echo "ClearPassword=${ses_password}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
# Line 121  generate_ica_session_files() Line 140  generate_ica_session_files()
140   done   done
141  }  }
142    
143    # generates a sh file to start programs
144    generate_program_sh()
145    {
146     local dest
147     local name
148     local exec
149     local workdir
150    
151     # very basic getops
152     for i in $*
153     do
154     case $1 in
155     --name|-n) shift; name="$1" ;;
156     --exec|-x) shift; exec="$1" ;;
157     --dest|-d) shift; dest="$1" ;;
158     --workdir|-w) shift; workdir="$1" ;;
159             esac
160     shift
161     done
162    
163     # abort if name, dest or exec not given
164     [ -z "${name}" ] && return 1
165     [ -z "${exec}" ] && return 1
166     [ -z "${dest}" ] && return 1
167    
168     echo "#!/bin/sh" > ${dest}
169     [ -n "${workdir}" ] && echo "cd ${workdir}" >> ${dest}
170     echo "exec ${exec}" >> ${dest}
171    
172     chmod 0755 ${dest}
173    }
174    
175    get_other_menuitems()
176    {
177     local x i progsh_path name exec icon workdir
178    
179     # all arrays:
180     # ->  session1 session2 ... sessionN
181    
182     # get settings from database -> now stored in ALX_PROGRAMS
183    
184     # abort if empty
185     [ -z "${ALX_PROGRAMS}" ] && return 0
186    
187     progsh_path=${ALX_UNPRIV_HOME}/.alxprogs
188     [ -d ${progsh_path} ] && rm -rf ${progsh_path}
189     install -d ${progsh_path}
190    
191     # gen menu items
192     for x in ${ALX_PROGRAMS}
193     do
194     # to be sure
195     unset name
196     unset exec
197     unset workdir
198     unset icon
199    
200     name=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
201     "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
202    
203     exec=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
204     "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
205    
206     workdir=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
207     "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
208    
209     icon=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
210     "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
211    
212     # debug only
213     #echo "DEBUG: ${x}: name:'${name}' exec:'${exec}' workdir:'${workdir}' ic$
214    
215     # now echo config line for fluxbox-menu
216     # make it "configureable" :P
217     #[ -n "${workdir}" ] && workdir="cd ${workdir};"
218     [ -n "${workdir}" ] && workdir="--workdir ${workdir}"
219     [ -n "${icon}" ] && icon="<${icon}>"
220    
221     # gen prog startup wrapper
222     generate_program_sh \
223     --name "${name}" \
224     --exec "${exec}" \
225     --dest "${progsh_path}/${name}" \
226     "${workdir}"
227    
228     echo "[exec] (${name}) {${progsh_path}/${name}} ${icon}"
229     done
230    }
231    
232    # helper functions for generate all desktop icons
233    generate_icon()
234    {
235     local name
236     local icon
237     local command
238     local dest
239     local yres
240     local xres
241     local iwidth
242     local iheight
243     local deficon
244    
245     # very basic getops
246     for i in $*
247     do
248     case $1 in
249     --name|-n) shift; name="$1" ;;
250     --command|-c) shift; command="$1" ;;
251     --icon|-i) shift; icon="$1" ;;
252     --dest|-d) shift; dest="$1" ;;
253     --xres|-x) shift; xres="$1" ;;
254     --yres|-y) shift; yres="$1" ;;
255     --icon-width|-w) shift; iwidth="$1" ;;
256     --icon-height|-h) shift; iheight="$1" ;;
257     --default-icon) shift; deficon="$1" ;;
258             esac
259     shift
260     done
261    
262     # some sanity checks :
263    
264     # abort if name or command not given
265     [ -z "${name}" ] && return 1
266     [ -z "${command}" ] && return 1
267    
268     # use some defaults for icon, dest, {x,y}res
269     [ -z "${xres}" ] && xres=20
270     [ -z "${yres}" ] && xres=20
271     [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"
272     if [ -z "${icon}" ] || [ ! -f "${icon}" ]
273     then
274     # if no default icon is given use default.png
275     [ -z "${deficon}" ] && deficon="default.png"
276     icon="${ALX_SESSIONS_ICONS}/${deficon}"
277     fi
278    
279     echo "table Icon" > ${dest}
280     echo "  Type: Program" >> ${dest}
281     echo "  Caption: ${name}" >> ${dest}
282     echo "  Command: ${command}" >> ${dest}
283     echo "  Icon: ${icon}" >> ${dest}
284     echo "  X: ${xres}" >> ${dest}
285     echo "  Y: ${yres}" >> ${dest}
286    
287     # add these only if not zero
288     if [ -n "${iwidth}" ] && [ -n "${iheight}" ]
289     then
290     echo "  IconWidth: ${iwidth}" >> ${dest}
291     echo "  IconHeight: ${iheight}" >> ${dest}
292     fi
293    
294     echo "end" >> ${dest}
295    }
296    
297    generate_all_desktop_icons()
298    {
299     local res
300     local xres
301     local yres
302     local icon_list
303     local x
304     local y
305     local item
306     local basename_item
307     local progsh_path
308    
309     # get the resolution
310     res=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
311     "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")
312    
313     # split res to x & y
314     xres="$(echo ${res} | cut -dx -f1)"
315     yres="$(echo ${res} | cut -dx -f2)"
316    
317     # top left edge of the icon is given in config file
318     # remove a little bit to simulate the bottom-right edge
319     xres="$(( ${xres} - 120 ))"
320     yres="$(( ${yres} - 80 ))"
321    
322     # basic config
323     cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc
324    
325     # clean desktop icon location
326     [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop
327     install -d ${ALX_UNPRIV_HOME}/.xtdesktop
328    
329    
330     # default settings
331     declare -i x=20
332     declare -i y=20
333    
334     # first all ica sessions
335     local count=${#ALX_SESSIONS[*]}
336     for (( i=0; i < count; i++ ))
337     do
338     # filenames !
339     icon_list="${icon_list} ${ALX_SESSIONS[${i}]}"
340     done
341    
342     for item in ${icon_list}
343     do
344     # abort if empty
345     [ -z "${item}" ] && continue
346    
347     # new line if x > xres
348     if [ ${x} -ge ${xres} ];then
349     x=20
350     y=$((${y} + 80))
351     fi
352    
353     # new row if y > yres
354     if [ ${y} -ge ${yres} ];then
355     x=$((${x} + 120))
356     y=20
357    
358     # re-check x
359     [ ${x} -ge ${xres} ] && x=20
360     fi
361    
362     # ica icons
363     # get basename (.ica must be suffix)
364     basename_item="$(basename ${item} .ica)"
365     generate_icon \
366     --name "${basename_item}" \
367     --command "wfica ${ALX_ICA_SESSIONS}/${item}" \
368     --icon "${ALX_SESSIONS_ICONS}/${basename_item}.png" \
369     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${basename_item}.lnk" \
370     --xres "${x}" \
371     --yres "${y}"
372    
373     y=$((${y} + 80))
374     done
375    
376    
377     # generate program icons
378     icon_list="${ALX_PROGRAMS}"
379    
380     progsh_path=${ALX_UNPRIV_HOME}/.alxprogs
381    
382     for item in ${icon_list}
383     do
384     # abort if empty
385     [ -z "${item}" ] && continue
386    
387     # new line if x > xres
388     if [ ${x} -ge ${xres} ];then
389     x=20
390     y=$((${y} + 80))
391     fi
392    
393     # new row if y > yres
394     if [ ${y} -ge ${yres} ];then
395     x=$((${x} + 120))
396     y=20
397    
398     # re-check x
399     [ ${x} -ge ${xres} ] && x=20
400     fi
401    
402     generate_icon \
403     --name "${item}" \
404     --command "${progsh_path}/${item}" \
405     --icon "${ALX_SESSIONS_ICONS}/${item}.png" \
406     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \
407     --xres "${x}" \
408     --yres "${y}" \
409     --default-icon "default_item.png"
410    
411     y=$((${y} + 80))
412     done
413    
414    
415    
416     # last but not least gen a icon with some sys informations
417     local sysinfo
418     local hostname
419     local osversion
420    
421     osversion="$(< /etc/mageversion)"
422     hostname=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
423     "select hostname from cfg_network where serial='${ALX_SERIAL}'")
424     sysinfo="Hostname: ${hostname} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)"
425    
426     # now get the right position:
427     # restore orig values of xres
428     xres="$(( ${xres} + 120 ))"
429     # default y pos (full yres -22 = cur yres + 58 !)
430     yres="$(( ${yres} + 58 ))"
431     # middle of the screen
432     # (no txt - length required, xtdesk manage that itself)
433     xres="$(( ${xres} / 2))"
434    
435     generate_icon \
436     --name "${sysinfo}" \
437     --command "exit 0" \
438     --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \
439     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \
440     --xres "${xres}" \
441     --yres "${yres}" \
442     --icon-width "1" \
443     --icon-height "1"
444    }
445    
446  config_sessions()  config_sessions()
447  {  {
448   # generate ica session files   # generate ica session files
449   generate_ica_session_files   generate_ica_session_files
450    
451   #first of all get the vars   # first of all get the vars
452   get_sessions_settings   get_sessions_settings
453   get_autostart_settings   get_autostart_settings
454     get_screensaver_settings
455    
456   local count=${#ALX_SESSIONS[*]}   local count=${#ALX_SESSIONS[*]}
457   local icon   local icon
# Line 159  config_sessions() Line 482  config_sessions()
482   cat ${ALX_SKELETONS}/fluxbox/apps \   cat ${ALX_SKELETONS}/fluxbox/apps \
483   > ${ALX_UNPRIV_HOME}/.fluxbox/apps   > ${ALX_UNPRIV_HOME}/.fluxbox/apps
484    
485     # add screensaver
486     if [[ -n ${ALX_SCRN_SAVER} ]] && [[ -n ${ALX_SCRN_TIMEOUT} ]]
487     then
488     local ALX_PASSWD_CMD
489    
490     if [[ -z ${ALX_SCRN_PASSWD} ]] || [[ ${ALX_SCRN_PASSWD} = NULL ]]
491     then
492     ALX_PASSWD_CMD="-nolock"
493     else
494     ALX_PASSWD_CMD="-cpasswd $(openssl passwd ${ALX_SCRN_PASSWD})"
495     fi
496    
497     echo "[startup] {nohup xautolock -time ${ALX_SCRN_TIMEOUT} -locker 'xlock -mode ${ALX_SCRN_SAVER} ${ALX_PASSWD_CMD}' > /dev/null &}" \
498     >> ${ALX_UNPRIV_HOME}/.fluxbox/apps
499     fi
500    
501   # add autostart session   # add autostart session
502   if [[ ${ALX_AUTOSTART} != "" ]]   if [[ ${ALX_AUTOSTART} != "" ]]
503   then   then
# Line 167  config_sessions() Line 506  config_sessions()
506   fi   fi
507    
508   # fluxbox hotkeys   # fluxbox hotkeys
509   cat ${ALX_SKELETONS}/fluxbox/apps \   cat ${ALX_SKELETONS}/fluxbox/keys \
510   > ${ALX_UNPRIV_HOME}/.fluxbox/keys   > ${ALX_UNPRIV_HOME}/.fluxbox/keys
511    
512   # fluxbox menu header   # fluxbox menu header
513   cat ${ALX_SKELETONS}/fluxbox/menu.header \   cat ${ALX_SKELETONS}/fluxbox/menu.header \
514   > ${ALX_UNPRIV_HOME}/.fluxbox/menu   > ${ALX_UNPRIV_HOME}/.fluxbox/menu
515    
516     # now fix it with proper messages :P
517     local ver="$(< /etc/mageversion)"
518     sed -i "s:@CHANGEME@:alx-${ver}  #${ALX_SERIAL}:g" \
519     ${ALX_UNPRIV_HOME}/.fluxbox/menu
520    
521   # add a newline (maybe there is no crlf in the header)   # add a newline (maybe there is no crlf in the header)
522   echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
523    
524   # fluxbox menu sessions   # fluxbox menu sessions
525   for (( i=0; i < count; i++ ))   for (( i=0; i < count; i++ ))
526   do   do
527   echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \   [ -n "${ALX_SESSIONS[${i}]}" ] && \
528   >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \
529     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
530   done   done
531    
532     # add other menuitems
533     get_other_menuitems >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
534    
535   # fluxbox menu footer   # fluxbox menu footer
536   cat ${ALX_SKELETONS}/fluxbox/menu.footer \   cat ${ALX_SKELETONS}/fluxbox/menu.footer \
537   >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
# Line 191  config_sessions() Line 539  config_sessions()
539   # add a newline (maybe there is no crlf in the footer)   # add a newline (maybe there is no crlf in the footer)
540   echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
541    
542   # now we generate the desktop icons   # now it's a good time to generate *all* icons :)
543   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  
544    
545   # set correct permissions   # set correct permissions
546   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
547   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
548   chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox   chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
549   chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop   chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
550   chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc   chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc
   
551    
552   # unset vars   # unset vars
553   unset ALX_SESSIONS   unset ALX_SESSIONS
554     unset ALX_PROGRAMS
555     unset ALX_SCRN_SAVER
556     unset ALX_SCRN_TIMEOUT
557     unset ALX_SCRN_PASSWD
558  }  }
559    

Legend:
Removed from v.272  
changed lines
  Added in v.338