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 2401 by niro, Wed Jun 15 12:43:55 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'
198    fi
199  }  }
200    
201  generate_all_desktop_icons()  generate_all_desktop_icons()
# Line 180  generate_all_desktop_icons() Line 207  generate_all_desktop_icons()
207   local yres   local yres
208   local x   local x
209   local y   local y
210   local item   local i
211   local name   local name
212   local progsh_path   local progsh_path
213     local utility
214     local dest
215     local rc
216    
217     # which utility are we using idesk|xtdesk ?
218     if [ -x /usr/bin/idesk ]
219     then
220     utility="idesk"
221     dest="${ALX_UNPRIV_HOME}/.idesktop"
222     rc="${ALX_UNPRIV_HOME}/.ideskrc"
223     else
224     utility="xtdesk"
225     dest="${ALX_UNPRIV_HOME}/.xtdesktop"
226     rc="${ALX_UNPRIV_HOME}/.xtdeskrc"
227     fi
228    
229    
230   # progsh path   # progsh path
231   progsh_path=${ALX_UNPRIV_HOME}/.alxprogs   progsh_path="${ALX_UNPRIV_HOME}/.alxprogs"
232    
233   # get the resolution   # get the resolution
234   res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")   res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")
235    
236   # split res to x & y   # split res to x & y
237   xres="${res%x*}"   xres="${res%x*}"
238   xres="${res#*x}"   yres="${res#*x}"
239    
240   # top left edge of the icon is given in config file   # top left edge of the icon is given in config file
241   # remove a little bit to simulate the bottom-right edge   # remove a little bit to simulate the bottom-right edge
242   xres="$(( ${xres} - 120 ))"   xres="$(( ${xres} - 120 ))"
243   yres="$(( ${yres} - 80 ))"   yres="$(( ${yres} - 80 ))"
244    
  # basic config  
  cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc  
   
245   # clean desktop icon location   # clean desktop icon location
246   [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop   [ -d ${dest} ] && rm -rf ${dest}
247   install -d ${ALX_UNPRIV_HOME}/.xtdesktop   [ -f ${rc} ] && rm -f ${rc}
248     install -d ${dest}
249    
250    if [[ ${utility} = xtdesk ]]
251    then
252     # basic config
253     cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdesktop/xtdeskrc
254    fi
255    
256   # default settings   # default settings
257   declare -i x=30   declare -i x=30
258   declare -i y=30   declare -i y=30
259    
260   # ica icons   # ica icons
261   for item in ${session_list}   for i in ${session_list}
262   do   do
263   # abort if empty   # abort if empty
264   [[ -z ${item} ]] && continue   [[ -z ${i} ]] && continue
265    
266     # get database information
267     evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"
268    
269   # new line if x > xres   # new line if x > xres
270   if [ ${x} -ge ${xres} ]   if [ ${x} -ge ${xres} ]
# Line 233  generate_all_desktop_icons() Line 283  generate_all_desktop_icons()
283   [ ${x} -ge ${xres} ] && x=30   [ ${x} -ge ${xres} ] && x=30
284   fi   fi
285    
  name="$(basename ${item} .ica)"  
286   generate_icon \   generate_icon \
287   --name "${name}" \   --name "${cfg_sessions_session}" \
288   --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/${item}" \   --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_sessions_filename})" \
289   --icon "${ALX_SESSIONS_ICONS}/${name}.png" \   --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_sessions_session}).png" \
290   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk" \   --dest "${dest}/$(fix_whitespaces ${cfg_sessions_session}).lnk" \
291   --xres "${x}" \   --xres "${x}" \
292   --yres "${y}"   --yres "${y}"
293    
294   y=$((${y} + 80))   y=$((${y} + 80))
295   done   done
296    
297   for item in ${other_menuitem_list}   for i in ${other_menuitem_list}
298   do   do
299   # abort if empty   # abort if empty
300   [[ -z ${item} ]] && continue   [[ -z ${i} ]] && continue
301    
302     # get database information
303     evaluate_table cfg_other_menuitems "where serial='${ALX_SERIAL}' and id='${i}'"
304    
305   # new line if x > xres   # new line if x > xres
306   if [ ${x} -ge ${xres} ]   if [ ${x} -ge ${xres} ]
# Line 268  generate_all_desktop_icons() Line 320  generate_all_desktop_icons()
320   fi   fi
321    
322   generate_icon \   generate_icon \
323   --name "${item}" \   --name "${cfg_other_menuitems_name}" \
324   --command "${progsh_path}/${item}" \   --command "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \
325   --icon "${ALX_SESSIONS_ICONS}/${item}.png" \   --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_other_menuitems_name}).png" \
326   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \   --dest "${dest}/$(fix_whitespaces ${cfg_other_menuitems_name}).lnk" \
327   --xres "${x}" \   --xres "${x}" \
328   --yres "${y}" \   --yres "${y}" \
329   --default-icon "default_item.png"   --default-icon "default_item.png"
# Line 301  generate_all_desktop_icons() Line 353  generate_all_desktop_icons()
353   --name "${sysinfo}" \   --name "${sysinfo}" \
354   --command "exit 0" \   --command "exit 0" \
355   --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \   --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \
356   --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \   --dest "${dest}/sysinfo.lnk" \
357   --xres "${xres}" \   --xres "${xres}" \
358   --yres "${yres}" \   --yres "${yres}" \
359   --icon-width "1" \   --icon-width "1" \
# Line 315  config_sessions() Line 367  config_sessions()
367   local all_other_ids   local all_other_ids
368   local CONFIG   local CONFIG
369   local screensaver_passwd_cmd   local screensaver_passwd_cmd
  local all_sessions  
  local all_other_menuitems  
370    
371   # get all session ids from database   # get all session ids from database
372   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 409  config_sessions()
409   # add autostart session   # add autostart session
410   if [[ ! -z ${cfg_autostart_session} ]]   if [[ ! -z ${cfg_autostart_session} ]]
411   then   then
412   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
413     addconfig "[startup] {sleep 1 && nohup nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_autostart_session}) &}"
414   fi   fi
415    
416   # fluxbox hotkeys   # fluxbox hotkeys
417   cat ${ALX_SKELETONS}/fluxbox/keys > ${ALX_UNPRIV_HOME}/.fluxbox/keys   cat ${ALX_SKELETONS}/fluxbox/keys > ${ALX_UNPRIV_HOME}/.fluxbox/keys
418    
419   # generate a fluxbox menu   # generate a fluxbox menu
420   CONFIG=${ALX_UNPRIV_HOME}/.fluxbox/menu   CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/menu"
421   clearconfig   clearconfig
422    
423   # fluxbox menu header   # fluxbox menu header
# Line 383  config_sessions() Line 434  config_sessions()
434   evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"   evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"
435   generate_ica_session_file \   generate_ica_session_file \
436   --session "${cfg_sessions_session}" \   --session "${cfg_sessions_session}" \
437   --filename "${cfg_sessions_filename}" \   --filename "$(fix_whitespaces ${cfg_sessions_filename})" \
438   --username "${cfg_sessions_username}" \   --username "${cfg_sessions_username}" \
439   --password "${cfg_sessions_password}" \   --password "${cfg_sessions_password}" \
440   --domain "${cfg_sessions_domain}" \   --domain "${cfg_sessions_domain}" \
441   --server "${cfg_sessions_browseradrs}"   --server "${cfg_sessions_browseradrs}"
442    
443   # fluxbox menusession   # fluxbox menusession
444   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}"  
445   done   done
446    
447   # delete all progs   # delete all progs
# Line 421  config_sessions() Line 469  config_sessions()
469   generate_program_sh \   generate_program_sh \
470   --name "${cfg_other_menuitems_name}" \   --name "${cfg_other_menuitems_name}" \
471   --exec "${cfg_other_menuitems_exec}" \   --exec "${cfg_other_menuitems_exec}" \
472   --dest "${progsh_path}/${cfg_other_menuitems_name}" \   --param "${cfg_other_menuitems_param}" \
473   "${cfg_other_menuitems_workdir}"   --dest "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \
474     "${workdir}"
  addconfig "[exec] (${cfg_other_menuitems_name}) {${progsh_path}/${cfg_other_menuitems_name}} ${cfg_other_menuitems_icon}"  
475    
476   # 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}"  
477   done   done
478    
479   # fluxbox menu footer   # fluxbox menu footer
# Line 436  config_sessions() Line 482  config_sessions()
482   addconfig   addconfig
483    
484   # now it's a good time to generate *all* icons :)   # now it's a good time to generate *all* icons :)
485   generate_all_desktop_icons "${all_sessions}" "${all_other_menuitems}"   generate_all_desktop_icons "${all_ses_ids}" "${all_other_ids}"
486    
487   # fix permissions   # fix permissions
488   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.2401