Magellan Linux

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

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

revision 304 by niro, Sun Aug 28 19:29:35 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.11 2005-08-28 19:29:35 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()
# 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 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()  get_other_menuitems()
176  {  {
177   local x i count name exec icon workdir   local x i progsh_path name exec icon workdir
178    
179   # all arrays:   # all arrays:
180   # ->  session1 session2 ... sessionN   # ->  session1 session2 ... sessionN
181    
182   # get settings from database   # get settings from database -> now stored in ALX_PROGRAMS
  count=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
  "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'")  
183    
184   # get all instances and put them into an array   # abort if empty
185   if [ -n "${count}" ]   [ -z "${ALX_PROGRAMS}" ] && return 0
186   then  
187   for x in ${count}   progsh_path=${ALX_UNPRIV_HOME}/.alxprogs
188   do   [ -d ${progsh_path} ] && rm -rf ${progsh_path}
189   # to be sure   install -d ${progsh_path}
  unset name  
  unset exec  
  unset workdir  
  unset icon  
   
  name=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
  "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")  
   
  exec=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
  "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")  
   
  workdir=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
  "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")  
   
  icon=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
  "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")  
   
  # debug only  
  #echo "DEBUG: ${x}: name:'${name}' exec:'${exec}' workdir:'${workdir}' ic$  
   
  # now echo config line for fluxbox-menu  
  # make it "configureable" :P  
  [ -n "${workdir}" ] && workdir="cd ${workdir};"  
  [ -n "${icon}" ] && icon="[${icon}]"  
  echo "[exec] (${name}) {${workdir}${exec}} ${icon}"  
  done  
  fi  
 }  
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  # helper functions for generate all desktop icons
233  generate_icon()  generate_icon()
# Line 179  generate_icon() Line 240  generate_icon()
240   local xres   local xres
241   local iwidth   local iwidth
242   local iheight   local iheight
243     local deficon
244    
245   # very basic getops   # very basic getops
246   for i in $*   for i in $*
# Line 192  generate_icon() Line 254  generate_icon()
254   --yres|-y) shift; yres="$1" ;;   --yres|-y) shift; yres="$1" ;;
255   --icon-width|-w) shift; iwidth="$1" ;;   --icon-width|-w) shift; iwidth="$1" ;;
256   --icon-height|-h) shift; iheight="$1" ;;   --icon-height|-h) shift; iheight="$1" ;;
257     --default-icon) shift; deficon="$1" ;;
258           esac           esac
259   shift   shift
260   done   done
# Line 208  generate_icon() Line 271  generate_icon()
271   [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"   [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"
272   if [ -z "${icon}" ] || [ ! -f "${icon}" ]   if [ -z "${icon}" ] || [ ! -f "${icon}" ]
273   then   then
274   icon="${ALX_SESSIONS_ICONS}/default.png"   # if no default icon is given use default.png
275     [ -z "${deficon}" ] && deficon="default.png"
276     icon="${ALX_SESSIONS_ICONS}/${deficon}"
277   fi   fi
278    
279   echo "table Icon" > ${dest}   echo "table Icon" > ${dest}
# Line 238  generate_all_desktop_icons() Line 303  generate_all_desktop_icons()
303   local x   local x
304   local y   local y
305   local item   local item
306     local basename_item
307     local progsh_path
308    
309   # get the resolution   # get the resolution
310   res=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   res=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
# Line 268  generate_all_desktop_icons() Line 335  generate_all_desktop_icons()
335   local count=${#ALX_SESSIONS[*]}   local count=${#ALX_SESSIONS[*]}
336   for (( i=0; i < count; i++ ))   for (( i=0; i < count; i++ ))
337   do   do
338   icon_list="${icon_list} $(basename ${ALX_SESSIONS[${i}] .ica})"   # filenames !
339     icon_list="${icon_list} ${ALX_SESSIONS[${i}]}"
340   done   done
341    
342   for item in ${icon_list}   for item in ${icon_list}
# Line 291  generate_all_desktop_icons() Line 359  generate_all_desktop_icons()
359   [ ${x} -ge ${xres} ] && x=20   [ ${x} -ge ${xres} ] && x=20
360   fi   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 \   generate_icon \
403   --name "${item}" \   --name "${item}" \
404   --command "wfica ${ALX_ICA_SESSIONS}/${item}.ica" \   --command "${progsh_path}/${item}" \
405   --icon "${ALX_SESSIONS_ICONS}/${item}.png" \   --icon "${ALX_SESSIONS_ICONS}/${item}.png" \
406   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \
407   --xres "${x}" \   --xres "${x}" \
408   --yres "${y}"   --yres "${y}" \
409     --default-icon "default_item.png"
410    
411   y=$((${y} + 80))   y=$((${y} + 80))
412   done   done
413    
414    
415    
416   # last but not least gen a icon with some sys informations   # last but not least gen a icon with some sys informations
417   local sysinfo   local sysinfo
418   local hostname   local hostname
# Line 341  config_sessions() Line 451  config_sessions()
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 371  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 379  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
# Line 419  config_sessions() Line 546  config_sessions()
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}/.xtdesktop   chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
550   chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc   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.304  
changed lines
  Added in v.338