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 342 by niro, Sun Oct 9 21:30:41 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.17 2005-10-09 21:30:25 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 9  get_sessions_settings() Line 9  get_sessions_settings()
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 filename 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
# 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  get_autostart_settings()  get_autostart_settings()
36  {  {
37   # get settings from database   # get settings from database
38   ALX_AUTOSTART=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   ALX_AUTOSTART=$(mysqldo "select session from cfg_autostart where serial='${ALX_SERIAL}'")
  "select session from cfg_autostart where serial='${ALX_SERIAL}'")  
39    
40   export ALX_AUTOSTART   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()  generate_ica_session_files()
55  {  {
56   local all_ids   local all_ids
# Line 53  generate_ica_session_files() Line 66  generate_ica_session_files()
66   local ses_colors   local ses_colors
67    
68   # get settings from database   # get settings from database
69   all_ids=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   all_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'")
  "select id from cfg_sessions where serial='${ALX_SERIAL}'")  
70    
71   for i in ${all_ids}   for i in ${all_ids}
72   do   do
73   # get settings   # get settings
74   ses_session=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   ses_session=$(mysqldo "select session from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
75   "select session from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")   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_filename=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   ses_domain=$(mysqldo "select domain from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
78   "select filename from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")   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}'")
  ses_username=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
  "select username from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")  
   
  ses_domain=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
  "select domain from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")  
   
  ses_password=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
  "select password from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")  
   
  ses_browseradrs=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
  "select browseradrs from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")  
80    
81   # get the right colors   # get the right colors
82   ses_colors=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   ses_colors=$(mysqldo "select depth from cfg_graphic where serial='${ALX_SERIAL}'")
83   "select depth from cfg_graphic where serial='${ALX_SERIAL}'")   # convert to ica session file values
84   case ${ses_colors} in   case ${ses_colors} in
85   24) ses_colors="8";;   24) ses_colors="8";;
86   16) ses_colors="4";;   16) ses_colors="4";;
# Line 121  generate_ica_session_files() Line 122  generate_ica_session_files()
122   done   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()  get_other_menuitems()
158  {  {
159   local x i count name exec icon workdir   local x i progsh_path name exec icon workdir
160    
161   # all arrays:   # all arrays:
162   # ->  session1 session2 ... sessionN   # ->  session1 session2 ... sessionN
163    
164   # 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}'")  
165    
166   # get all instances and put them into an array   # abort if empty
167   if [ -n "${count}" ]   [ -z "${ALX_PROGRAMS}" ] && return 0
168   then  
169   for x in ${count}   progsh_path=${ALX_UNPRIV_HOME}/.alxprogs
170   do   [ -d ${progsh_path} ] && rm -rf ${progsh_path}
171   # to be sure   install -d ${progsh_path}
172   unset name  
173   unset exec   # gen menu items
174   unset workdir   for x in ${ALX_PROGRAMS}
175   unset icon   do
176     # to be sure
177   name=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   unset name
178   "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")   unset exec
179     unset workdir
180   exec=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   unset icon
181   "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")  
182     name=$(mysqldo "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
183   workdir=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   exec=$(mysqldo "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
184   "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")   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   icon=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
187   "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")   # now echo config line for fluxbox-menu
188     # make it "configureable" :P
189   # debug only   [ -n "${workdir}" ] && workdir="--workdir ${workdir}"
190   #echo "DEBUG: ${x}: name:'${name}' exec:'${exec}' workdir:'${workdir}' ic$   [ -n "${icon}" ] && icon="<${icon}>"
191    
192   # now echo config line for fluxbox-menu   # gen prog startup wrapper
193   # make it "configureable" :P   generate_program_sh \
194   [ -n "${workdir}" ] && workdir="cd ${workdir};"   --name "${name}" \
195   [ -n "${icon}" ] && icon="[${icon}]"   --exec "${exec}" \
196   echo "[exec] (${name}) {${workdir}${exec}} ${icon}"   --dest "${progsh_path}/${name}" \
197   done   "${workdir}"
  fi  
 }  
198    
199     echo "[exec] (${name}) {${progsh_path}/${name}} ${icon}"
200     done
201    }
202    
203  # helper functions for generate all desktop icons  # helper functions for generate all desktop icons
204  generate_icon()  generate_icon()
# Line 179  generate_icon() Line 211  generate_icon()
211   local xres   local xres
212   local iwidth   local iwidth
213   local iheight   local iheight
214     local deficon
215    
216   # very basic getops   # very basic getops
217   for i in $*   for i in $*
# Line 192  generate_icon() Line 225  generate_icon()
225   --yres|-y) shift; yres="$1" ;;   --yres|-y) shift; yres="$1" ;;
226   --icon-width|-w) shift; iwidth="$1" ;;   --icon-width|-w) shift; iwidth="$1" ;;
227   --icon-height|-h) shift; iheight="$1" ;;   --icon-height|-h) shift; iheight="$1" ;;
228     --default-icon) shift; deficon="$1" ;;
229           esac           esac
230   shift   shift
231   done   done
# Line 208  generate_icon() Line 242  generate_icon()
242   [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"   [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"
243   if [ -z "${icon}" ] || [ ! -f "${icon}" ]   if [ -z "${icon}" ] || [ ! -f "${icon}" ]
244   then   then
245   icon="${ALX_SESSIONS_ICONS}/default.png"   # if no default icon is given use default.png
246     [ -z "${deficon}" ] && deficon="default.png"
247     icon="${ALX_SESSIONS_ICONS}/${deficon}"
248   fi   fi
249    
250   echo "table Icon" > ${dest}   echo "table Icon" > ${dest}
# Line 238  generate_all_desktop_icons() Line 274  generate_all_desktop_icons()
274   local x   local x
275   local y   local y
276   local item   local item
277     local basename_item
278     local progsh_path
279    
280   # get the resolution   # get the resolution
281   res=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")
  "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")  
282    
283   # split res to x & y   # split res to x & y
284   xres="$(echo ${res} | cut -dx -f1)"   xres="$(echo ${res} | cut -dx -f1)"
# Line 268  generate_all_desktop_icons() Line 305  generate_all_desktop_icons()
305   local count=${#ALX_SESSIONS[*]}   local count=${#ALX_SESSIONS[*]}
306   for (( i=0; i < count; i++ ))   for (( i=0; i < count; i++ ))
307   do   do
308   icon_list="${icon_list} $(basename ${ALX_SESSIONS[${i}] .ica})"   # filenames !
309     icon_list="${icon_list} ${ALX_SESSIONS[${i}]}"
310   done   done
311    
312   for item in ${icon_list}   for item in ${icon_list}
# Line 291  generate_all_desktop_icons() Line 329  generate_all_desktop_icons()
329   [ ${x} -ge ${xres} ] && x=20   [ ${x} -ge ${xres} ] && x=20
330   fi   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 "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 \   generate_icon \
373   --name "${item}" \   --name "${item}" \
374   --command "wfica ${ALX_ICA_SESSIONS}/${item}.ica" \   --command "${progsh_path}/${item}" \
375   --icon "${ALX_SESSIONS_ICONS}/${item}.png" \   --icon "${ALX_SESSIONS_ICONS}/${item}.png" \
376   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \
377   --xres "${x}" \   --xres "${x}" \
378   --yres "${y}"   --yres "${y}" \
379     --default-icon "default_item.png"
380    
381   y=$((${y} + 80))   y=$((${y} + 80))
382   done   done
383    
384    
385    
386   # last but not least gen a icon with some sys informations   # last but not least gen a icon with some sys informations
387   local sysinfo   local sysinfo
388   local hostname   local hostname
389   local osversion   local osversion
390    
391   osversion="$(< /etc/mageversion)"   osversion="$(< /etc/mageversion)"
392   hostname=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   hostname=$(mysqldo "select hostname from cfg_network where serial='${ALX_SERIAL}'")
  "select hostname from cfg_network where serial='${ALX_SERIAL}'")  
393   sysinfo="Hostname: ${hostname} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)"   sysinfo="Hostname: ${hostname} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)"
394    
395   # now get the right position:   # now get the right position:
# Line 341  config_sessions() Line 420  config_sessions()
420   # first of all get the vars   # first of all get the vars
421   get_sessions_settings   get_sessions_settings
422   get_autostart_settings   get_autostart_settings
423     get_screensaver_settings
424    
425   local count=${#ALX_SESSIONS[*]}   local count=${#ALX_SESSIONS[*]}
426   local icon   local icon
427   local i   local i
428    
  # DEBUG  
 # declare -i i=0  
 # echo count=${count}  
 # echo "Number of new sessions: ${count}"  
 # for ((i=0; i < count; i++))  
 # do  
 # echo "${i} - ${ALX_SESSIONS[${i}]}"  
 # done  
   
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 371  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   # add autostart session
462   if [[ ${ALX_AUTOSTART} != "" ]]   if [[ ${ALX_AUTOSTART} != "" ]]
463   then   then
# Line 379  config_sessions() Line 466  config_sessions()
466   fi   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
# Line 419  config_sessions() Line 506  config_sessions()
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}/.xtdesktop   chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
510   chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc   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.304  
changed lines
  Added in v.342