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 2149 by niro, Tue May 17 11:47:17 2011 UTC revision 2408 by niro, Wed Jun 15 12:54:42 2011 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2  # configures ica-sessions on the host via mysql db settings  # configures ica-sessions on the host via mysql db settings
3    
4    fix_whitespaces()
5    {
6     local var="$@"
7     echo "${var//\ /_}"
8    }
9    
10  # helper function to create citrix session files  # helper function to create citrix session files
11  generate_ica_session_file()  generate_ica_session_file()
12  {  {
# Line 24  generate_ica_session_file() Line 30  generate_ica_session_file()
30   --username) shift; ses_username="$1" ;;   --username) shift; ses_username="$1" ;;
31   --password) shift; ses_password="$1" ;;   --password) shift; ses_password="$1" ;;
32   --domain) shift; ses_domain="$1" ;;   --domain) shift; ses_domain="$1" ;;
33   --server) ses_browseradrs="$1" ;;   --server) shift; ses_browseradrs="$1" ;;
34           esac           esac
35   shift   shift
36   done   done
37    
38   # abort if session, filename or server not given   # abort if session, filename or server not given
39   [[ -z ${session} ]] && return 1   [[ -z ${ses_session} ]] && return 1
40   [[ -z ${file} ]] && return 1   [[ -z ${ses_filename} ]] && return 1
41   [[ -z ${server} ]] && return 1   [[ -z ${ses_browseradrs} ]] && return 1
42    
43   # write session files   # write session files
44   CONFIG="${ALX_ICA_SESSIONS}/${ses_filename}"   CONFIG="${ALX_ICA_SESSIONS}/${ses_filename}"
# Line 74  generate_program_sh() Line 80  generate_program_sh()
80   local dest   local dest
81   local name   local name
82   local exec   local exec
83     local param
84   local workdir   local workdir
85   local CONFIG   local CONFIG
86    
# Line 83  generate_program_sh() Line 90  generate_program_sh()
90   case $1 in   case $1 in
91   --name|-n) shift; name="$1" ;;   --name|-n) shift; name="$1" ;;
92   --exec|-x) shift; exec="$1" ;;   --exec|-x) shift; exec="$1" ;;
93     --param|-p) shift; param="$1" ;;
94   --dest|-d) shift; dest="$1" ;;   --dest|-d) shift; dest="$1" ;;
95   --workdir|-w) shift; workdir="$1" ;;   --workdir|-w) shift; workdir="$1" ;;
96           esac           esac
# Line 97  generate_program_sh() Line 105  generate_program_sh()
105   CONFIG="${dest}"   CONFIG="${dest}"
106   addconfig "#!/bin/sh"   addconfig "#!/bin/sh"
107   [ -n "${workdir}" ] && addconfig "cd ${workdir}"   [ -n "${workdir}" ] && addconfig "cd ${workdir}"
108   addconfig "exec ${exec}"   addconfig "exec ${exec} ${param}"
109    
110   chmod 0755 "${dest}"   chmod 0755 "${dest}"
111  }  }
# Line 115  generate_icon() Line 123  generate_icon()
123   local iheight   local iheight
124   local deficon   local deficon
125   local CONFIG   local CONFIG
126     local utility
127    
128   # very basic getops   # very basic getops
129   for i in $*   for i in $*
# Line 134  generate_icon() Line 143  generate_icon()
143   done   done
144    
145   # some sanity checks:   # some sanity checks:
146    
147   # abort if name or command not given   # abort if name or command not given
148   [[ -z ${name} ]] && return 1   [[ -z ${name} ]] && return 1
149   [[ -z ${command} ]] && return 1   [[ -z ${command} ]] && return 1
150    
151     # which utility are we using idesk|xtdesk ?
152     if [ -x /usr/bin/idesk ]
153     then
154     utility="idesk"
155     [[ -z ${dest} ]] && dest="${ALX_UNPRIV_HOME}/.idesktop/${name}.lnk"
156     else
157     utility="xtdesk"
158     [[ -z ${dest} ]] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"
159     fi
160    
161   # use some defaults for icon, dest, {x,y}res   # use some defaults for icon, dest, {x,y}res
162   [[ -z ${xres} ]] && xres=30   [[ -z ${xres} ]] && xres=30
163   [[ -z ${yres} ]] && xres=30   [[ -z ${yres} ]] && xres=30
  [[ -z ${dest} ]] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"  
164   if [[ -z ${icon} ]] || [ ! -f ${icon} ]   if [[ -z ${icon} ]] || [ ! -f ${icon} ]
165   then   then
166   # if no default icon is given use default.png   # if no default icon is given use default.png
# Line 150  generate_icon() Line 168  generate_icon()
168   icon="${ALX_SESSIONS_ICONS}/${deficon}"   icon="${ALX_SESSIONS_ICONS}/${deficon}"
169   fi   fi
170    
171   CONFIG=${dest}   CONFIG="${dest}"
172   clearconfig   clearconfig
173    
174   addconfig 'table Icon'   addconfig 'table Icon'
175   addconfig '  Type: Program'   [[ ${utility} = xtdesk ]] && addconfig '  Type: Program'
176   addconfig "  Caption: ${name}"   addconfig "  Caption: ${name}"
177   addconfig "  Command: ${command}"   addconfig "  Command: ${command}"
178   addconfig "  Icon: ${icon}"   addconfig "  Icon: ${icon}"
# Line 164  generate_icon() Line 182  generate_icon()
182   # add these only if not zero   # add these only if not zero
183   if [[ ! -z ${iwidth} ]] && [[ ! -z ${iheight} ]]   if [[ ! -z ${iwidth} ]] && [[ ! -z ${iheight} ]]
184   then   then
185   addconfig "  IconWidth: ${iwidth}"   if [[ ${utility} = xtdesk ]]
186   addconfig "  IconHeight: ${iheight}"   then
187     addconfig "  IconWidth: ${iwidth}"
188     addconfig "  IconHeight: ${iheight}"
189     fi
190     if [[ ${utility} = idesk ]]
191     then
192     addconfig "  Width: ${iwidth}"
193     addconfig "  Height: ${iheight}"
194     fi
195   fi   fi
196    
197   addconfig 'end'   addconfig 'end'
# Line 180  generate_all_desktop_icons() Line 206  generate_all_desktop_icons()
206   local yres   local yres
207   local x   local x
208   local y   local y
209   local item   local i
210   local name   local name
211   local progsh_path   local progsh_path
212     local utility
213     local dest
214     local rc
215    
216     # which utility are we using idesk|xtdesk ?
217     if [ -x /usr/bin/idesk ]
218     then
219     utility="idesk"
220     dest="${ALX_UNPRIV_HOME}/.idesktop"
221     rc="${ALX_UNPRIV_HOME}/.ideskrc"
222     else
223     utility="xtdesk"
224     dest="${ALX_UNPRIV_HOME}/.xtdesktop"
225     rc="${ALX_UNPRIV_HOME}/.xtdeskrc"
226     fi
227    
228    
229   # progsh path   # progsh path
230   progsh_path=${ALX_UNPRIV_HOME}/.alxprogs   progsh_path="${ALX_UNPRIV_HOME}/.alxprogs"
231    
232   # get the resolution   # get the resolution
233   res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")   res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")
234    
235   # split res to x & y   # split res to x & y
236   xres="${res%x*}"   xres="${res%x*}"
237   xres="${res#*x}"   yres="${res#*x}"
238    
239   # top left edge of the icon is given in config file   # top left edge of the icon is given in config file
240   # remove a little bit to simulate the bottom-right edge   # remove a little bit to simulate the bottom-right edge
241   xres="$(( ${xres} - 120 ))"   xres="$(( ${xres} - 120 ))"
242   yres="$(( ${yres} - 80 ))"   yres="$(( ${yres} - 80 ))"
243    
  # basic config  
  cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc  
   
244   # clean desktop icon location   # clean desktop icon location
245   [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop   [ -d ${dest} ] && rm -rf ${dest}
246   install -d ${ALX_UNPRIV_HOME}/.xtdesktop   [ -f ${rc} ] && rm -f ${rc}
247     install -d ${dest}
248    
249    if [[ ${utility} = xtdesk ]]
250    then
251     # basic config
252     cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdesktop/xtdeskrc
253    fi
254    
255   # default settings   # default settings
256   declare -i x=30   declare -i x=30
257   declare -i y=30   declare -i y=30
258    
259   # ica icons   # ica icons
260   for item in ${session_list}   for i in ${session_list}
261   do   do
262   # abort if empty   # abort if empty
263   [[ -z ${item} ]] && continue   [[ -z ${i} ]] && continue
264    
265     # get database information
266     evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"
267    
268   # new line if x > xres   # new line if x > xres
269   if [ ${x} -ge ${xres} ]   if [ ${x} -ge ${xres} ]
# Line 233  generate_all_desktop_icons() Line 282  generate_all_desktop_icons()
282   [ ${x} -ge ${xres} ] && x=30   [ ${x} -ge ${xres} ] && x=30
283   fi   fi
284    
  name="$(basename ${item} .ica)"  
285   generate_icon \   generate_icon \
286   --name "${name}" \   --name "${cfg_sessions_session}" \
287   --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/${item}" \   --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_sessions_filename})" \
288   --icon "${ALX_SESSIONS_ICONS}/${name}.png" \   --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_sessions_session}).png" \
289   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk" \   --dest "${dest}/$(fix_whitespaces ${cfg_sessions_session}).lnk" \
290   --xres "${x}" \   --xres "${x}" \
291   --yres "${y}"   --yres "${y}"
292    
293   y=$((${y} + 80))   y=$((${y} + 80))
294   done   done
295    
296   for item in ${other_menuitem_list}   for i in ${other_menuitem_list}
297   do   do
298   # abort if empty   # abort if empty
299   [[ -z ${item} ]] && continue   [[ -z ${i} ]] && continue
300    
301     # get database information
302     evaluate_table cfg_other_menuitems "where serial='${ALX_SERIAL}' and id='${i}'"
303    
304   # new line if x > xres   # new line if x > xres
305   if [ ${x} -ge ${xres} ]   if [ ${x} -ge ${xres} ]
# Line 268  generate_all_desktop_icons() Line 319  generate_all_desktop_icons()
319   fi   fi
320    
321   generate_icon \   generate_icon \
322   --name "${item}" \   --name "${cfg_other_menuitems_name}" \
323   --command "${progsh_path}/${item}" \   --command "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \
324   --icon "${ALX_SESSIONS_ICONS}/${item}.png" \   --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_other_menuitems_name}).png" \
325   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \   --dest "${dest}/$(fix_whitespaces ${cfg_other_menuitems_name}).lnk" \
326   --xres "${x}" \   --xres "${x}" \
327   --yres "${y}" \   --yres "${y}" \
328   --default-icon "default_item.png"   --default-icon "default_item.png"
# Line 301  generate_all_desktop_icons() Line 352  generate_all_desktop_icons()
352   --name "${sysinfo}" \   --name "${sysinfo}" \
353   --command "exit 0" \   --command "exit 0" \
354   --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \   --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \
355   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \   --dest "${dest}/sysinfo.lnk" \
356   --xres "${xres}" \   --xres "${xres}" \
357   --yres "${yres}" \   --yres "${yres}" \
358   --icon-width "1" \   --icon-width "1" \
# Line 315  config_sessions() Line 366  config_sessions()
366   local all_other_ids   local all_other_ids
367   local CONFIG   local CONFIG
368   local screensaver_passwd_cmd   local screensaver_passwd_cmd
  local all_sessions  
  local all_other_menuitems  
369    
370   # get all session ids from database   # get all session ids from database
371   all_ses_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'")   all_ses_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'")
# Line 359  config_sessions() Line 408  config_sessions()
408   # add autostart session   # add autostart session
409   if [[ ! -z ${cfg_autostart_session} ]]   if [[ ! -z ${cfg_autostart_session} ]]
410   then   then
411   addconfig "[startup] {nohup nice -n 19 wfica ${ALX_ICA_SESSIONS}/${cfg_autostart_session} &}"   # sleep one second to wait until busybox is fully initialized and the screen is really centered
412     addconfig "[startup] {sleep 1 && nohup nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_autostart_session}) &}"
413   fi   fi
414    
415   # fluxbox hotkeys   # fluxbox hotkeys
416   cat ${ALX_SKELETONS}/fluxbox/keys > ${ALX_UNPRIV_HOME}/.fluxbox/keys   cat ${ALX_SKELETONS}/fluxbox/keys > ${ALX_UNPRIV_HOME}/.fluxbox/keys
417    
418   # generate a fluxbox menu   # generate a fluxbox menu
419   CONFIG=${ALX_UNPRIV_HOME}/.fluxbox/menu   CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/menu"
420   clearconfig   clearconfig
421    
422   # fluxbox menu header   # fluxbox menu header
# Line 383  config_sessions() Line 433  config_sessions()
433   evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"   evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"
434   generate_ica_session_file \   generate_ica_session_file \
435   --session "${cfg_sessions_session}" \   --session "${cfg_sessions_session}" \
436   --filename "${cfg_sessions_filename}" \   --filename "$(fix_whitespaces ${cfg_sessions_filename})" \
437   --username "${cfg_sessions_username}" \   --username "${cfg_sessions_username}" \
438   --password "${cfg_sessions_password}" \   --password "${cfg_sessions_password}" \
439   --domain "${cfg_sessions_domain}" \   --domain "${cfg_sessions_domain}" \
440   --server "${cfg_sessions_browseradrs}"   --server "${cfg_sessions_browseradrs}"
441    
442   # fluxbox menusession   # fluxbox menusession
443   addconfig "[exec] (${cfg_sessions_session}) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${cfg_sessions_filename}}"   addconfig "[exec] (${cfg_sessions_session}) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_sessions_filename})}"
   
  # add to all_sessions variable to create icons later for these  
  all_sessions="${all_sessions} ${cfg_sessions_filename}"  
444   done   done
445    
446   # delete all progs   # delete all progs
# Line 421  config_sessions() Line 468  config_sessions()
468   generate_program_sh \   generate_program_sh \
469   --name "${cfg_other_menuitems_name}" \   --name "${cfg_other_menuitems_name}" \
470   --exec "${cfg_other_menuitems_exec}" \   --exec "${cfg_other_menuitems_exec}" \
471   --dest "${progsh_path}/${cfg_other_menuitems_name}" \   --param "${cfg_other_menuitems_param}" \
472   "${cfg_other_menuitems_workdir}"   --dest "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \
473     "${workdir}"
  addconfig "[exec] (${cfg_other_menuitems_name}) {${progsh_path}/${cfg_other_menuitems_name}} ${cfg_other_menuitems_icon}"  
474    
475   # add to all_other_menuitems variable to create icons later for these   addconfig "[exec] (${cfg_other_menuitems_name}) {${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})} ${cfg_other_menuitems_icon}"
  all_other_menuitems="${all_other_menuitems} ${cfg_other_menuitems_name}"  
476   done   done
477    
478   # fluxbox menu footer   # fluxbox menu footer
# Line 436  config_sessions() Line 481  config_sessions()
481   addconfig   addconfig
482    
483   # now it's a good time to generate *all* icons :)   # now it's a good time to generate *all* icons :)
484   generate_all_desktop_icons "${all_sessions}" "${all_other_menuitems}"   generate_all_desktop_icons "${all_ses_ids}" "${all_other_ids}"
485    
486   # fix permissions   # fix permissions
487   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}

Legend:
Removed from v.2149  
changed lines
  Added in v.2408