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 2565 by niro, Mon Jul 4 20:17:25 2011 UTC revision 6780 by niro, Tue Jul 21 14:47:40 2015 UTC
# Line 7  fix_whitespaces() Line 7  fix_whitespaces()
7   echo "${var//\ /_}"   echo "${var//\ /_}"
8  }  }
9    
10    sanitize_store()
11    {
12     local var="$@"
13     echo "$(fix_whitespaces ${var})" | sed -e 's:\::_:g' -e 's:\/:_:g' | tr '[A-Z]' '[a-z]'
14    }
15    
16  # helper function to create citrix session files  # helper function to create citrix session files
17  generate_ica_session_file()  generate_ica_session_file()
18  {  {
# Line 33  generate_ica_session_file() Line 39  generate_ica_session_file()
39   --domain) shift; ses_domain="$1" ;;   --domain) shift; ses_domain="$1" ;;
40   --server) shift; ses_browseradrs="$1" ;;   --server) shift; ses_browseradrs="$1" ;;
41   --colordepth) shift; ses_colors="$1" ;;   --colordepth) shift; ses_colors="$1" ;;
42           esac   esac
43   shift   shift
44   done   done
45    
# Line 59  generate_ica_session_file() Line 65  generate_ica_session_file()
65   # the first address must be named TcpBrowserAddress, but not TcpBrowserAddress1 !!   # the first address must be named TcpBrowserAddress, but not TcpBrowserAddress1 !!
66   [[ ${i} -eq 1 ]] && num=""   [[ ${i} -eq 1 ]] && num=""
67   addconfig "TcpBrowserAddress${num}=${server}"   addconfig "TcpBrowserAddress${num}=${server}"
68     addconfig "HttpBrowserAddress${num}=${server}"
69   done   done
70    
71   addconfig 'ScreenPercent=0'   addconfig 'ScreenPercent=0'
# Line 78  generate_ica_session_file() Line 85  generate_ica_session_file()
85   addconfig "DesiredColor=${ses_colors}"   addconfig "DesiredColor=${ses_colors}"
86   addconfig 'TransportDriver=TCP/IP'   addconfig 'TransportDriver=TCP/IP'
87   addconfig 'WinStationDriver=ICA 3.0'   addconfig 'WinStationDriver=ICA 3.0'
88   addconfig "ClearPassword=${ses__password}"   addconfig "ClearPassword=${ses_password}"
89   addconfig "Username=${ses_username}"   addconfig "Username=${ses_username}"
90   addconfig "Domain=${ses_domain}"   addconfig "Domain=${ses_domain}"
91   addconfig 'UseFullScreen=Yes'   addconfig 'UseFullScreen=Yes'
92   addconfig 'NoWindowManager=True'   addconfig 'NoWindowManager=True'
93  }  }
94    
95    generate_storefront_sh()
96    {
97     local server
98     local ses_session
99     local ses_filename
100     local ses_username
101     local ses_domain
102     local ses_password
103     local ses_browseradrs
104     local method
105     local ses_method
106     local name
107    
108     # very basic getops
109     for i in $*
110     do
111     case $1 in
112     --session) shift; ses_session="$1" ;;
113     --filename) shift; ses_filename="$1" ;;
114     --username) shift; ses_username="$1" ;;
115     --password) shift; ses_password="$1" ;;
116     --domain) shift; ses_domain="$1" ;;
117     --server) shift; ses_browseradrs="$1" ;;
118     --method) shift; method="$1" ;;
119     esac
120     shift
121     done
122    
123     # abort if name, dest or exec not given
124     [[ -z ${ses_filename} ]] && return 1
125     [[ -z ${ses_username} ]] && return 1
126     [[ -z ${ses_password} ]] && return 1
127     [[ -z ${ses_domain} ]] && return 1
128     [[ -z ${ses_browseradrs} ]] && return 1
129    
130     case "${method}" in
131     enumerate)
132     ses_method="${method}"
133     name="store-enumerate"
134     ;;
135     launch)
136     ses_method="${method}"
137     name="${ses_session}"
138     [[ -z ${ses_session} ]] && return 1
139     ;;
140     *) echo "generate_storefront_sh(): wrong method given, either 'launch' or 'enumerate' are allowed."
141     return 1
142     ;;
143     esac
144    
145     generate_program_sh \
146     --name "${name}" \
147     --exec "storefront-resolver" \
148     --param "${method} '${ses_username}' '${ses_password}' '${ses_domain}' '${ses_session}'" \
149     --dest "${ALX_UNPRIV_HOME}/.alxprogs/$(fix_whitespaces ${ses_filename})" \
150     --environment "STORE=${ses_browseradrs}"
151    }
152    
153  # generates a sh file to start programs  # generates a sh file to start programs
154  generate_program_sh()  generate_program_sh()
155  {  {
# Line 104  generate_program_sh() Line 169  generate_program_sh()
169   --param|-p) shift; param="$1" ;;   --param|-p) shift; param="$1" ;;
170   --dest|-d) shift; dest="$1" ;;   --dest|-d) shift; dest="$1" ;;
171   --workdir|-w) shift; workdir="$1" ;;   --workdir|-w) shift; workdir="$1" ;;
172           esac   --environment|-e)  shift; environment="$1" ;;
173     esac
174   shift   shift
175   done   done
176    
# Line 115  generate_program_sh() Line 181  generate_program_sh()
181    
182   CONFIG="${dest}"   CONFIG="${dest}"
183   addconfig "#!/bin/sh"   addconfig "#!/bin/sh"
184   [ -n "${workdir}" ] && addconfig "cd ${workdir}"   [[ -n ${environment} ]] && addconfig "export ${environment}"
185     [[ -n ${workdir} ]] && addconfig "cd ${workdir}"
186   addconfig "exec ${exec} ${param}"   addconfig "exec ${exec} ${param}"
187    
188   chmod 0755 "${dest}"   chmod 0755 "${dest}"
# Line 149  generate_icon() Line 216  generate_icon()
216   --icon-width|-w) shift; iwidth="$1" ;;   --icon-width|-w) shift; iwidth="$1" ;;
217   --icon-height|-h) shift; iheight="$1" ;;   --icon-height|-h) shift; iheight="$1" ;;
218   --default-icon) shift; deficon="$1" ;;   --default-icon) shift; deficon="$1" ;;
219           esac   esac
220   shift   shift
221   done   done
222    
# Line 195  generate_all_desktop_icons() Line 262  generate_all_desktop_icons()
262  {  {
263   local session_list="$1"   local session_list="$1"
264   local other_menuitem_list="$2"   local other_menuitem_list="$2"
265     local plugin_list="$3"
266   local res   local res
267   local xres   local xres
268   local yres   local yres
# Line 262  generate_all_desktop_icons() Line 330  generate_all_desktop_icons()
330    
331   generate_icon \   generate_icon \
332   --name "${cfg_sessions_session}" \   --name "${cfg_sessions_session}" \
333   --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_sessions_filename})" \   --command "${progsh_path}/$(fix_whitespaces ${cfg_sessions_filename})" \
334   --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_sessions_session}).png" \   --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_sessions_session}).png" \
335   --dest "${dest}/$(fix_whitespaces ${cfg_sessions_session}).lnk" \   --dest "${dest}/$(fix_whitespaces ${cfg_sessions_session}).lnk" \
336   --xres "${x}" \   --xres "${x}" \
# Line 299  generate_all_desktop_icons() Line 367  generate_all_desktop_icons()
367   generate_icon \   generate_icon \
368   --name "${cfg_other_menuitems_name}" \   --name "${cfg_other_menuitems_name}" \
369   --command "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \   --command "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \
370   --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_other_menuitems_name}).png" \   --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_other_menuitems_icon}).png" \
371   --dest "${dest}/$(fix_whitespaces ${cfg_other_menuitems_name}).lnk" \   --dest "${dest}/$(fix_whitespaces ${cfg_other_menuitems_name}).lnk" \
372   --xres "${x}" \   --xres "${x}" \
373   --yres "${y}" \   --yres "${y}" \
# Line 307  generate_all_desktop_icons() Line 375  generate_all_desktop_icons()
375    
376   y=$((${y} + 80))   y=$((${y} + 80))
377   done   done
378    
379     for i in ${plugin_list}
380     do
381     # abort if empty
382     [[ -z ${i} ]] && continue
383    
384     evaluate_table cfg_plugins "where serial='${ALX_SERIAL}' and id='${i}'"
385     if [[ -x ${ALX_PLUGINS}/${cfg_plugins_plugin}/plugin.sh ]]
386     then
387     eval $(${ALX_PLUGINS}/${cfg_plugins_plugin}/plugin.sh menuitem)
388    
389     # abort if name or exec is empty
390     [[ -z ${PLUGIN_MENUITEM_NAME} ]] && continue
391     [[ -z ${PLUGIN_MENUITEM_EXEC} ]] && continue
392    
393     # new line if x > xres
394     if [ ${x} -ge ${xres} ]
395     then
396     x=50
397     y=$((${y} + 80))
398     fi
399    
400     # new row if y > yres
401     if [ ${y} -ge ${yres} ]
402     then
403     x=$((${x} + 120))
404     y=50
405    
406     # re-check x
407     [ ${x} -ge ${xres} ] && x=50
408     fi
409    
410     generate_icon \
411     --name "${PLUGIN_MENUITEM_NAME}" \
412     --command "${progsh_path}/$(fix_whitespaces ${PLUGIN_MENUITEM_NAME})" \
413     --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${PLUGIN_MENUITEM_NAME}).png" \
414     --dest "${dest}/$(fix_whitespaces ${PLUGIN_MENUITEM_NAME}).lnk" \
415     --xres "${x}" \
416     --yres "${y}" \
417     --default-icon "default_item.png"
418    
419     y=$((${y} + 80))
420     fi
421    
422     # unset all variables
423     unset PLUGIN_MENUITEM_NAME
424     unset PLUGIN_MENUITEM_EXEC
425     unset PLUGIN_MENUITEM_PARAM
426     unset PLUGIN_MENUITEM_WORKDIR
427     unset PLUGIN_MENUITEM_ICON
428     done
429    
430   # add shutdown, reboot icons   # add shutdown, reboot icons
431   for i in shutdown reboot   for i in shutdown reboot
# Line 384  config_sessions() Line 503  config_sessions()
503   local screensaver_passwd_cmd   local screensaver_passwd_cmd
504   local fbinit   local fbinit
505   local fbkeys   local fbkeys
506     local progsh_path
507     local storefront_enumerate=0
508     local storefront_store
509     local _store
510     local all_storefront_stores=""
511    
512     progsh_path="${ALX_UNPRIV_HOME}/.alxprogs"
513    
514   # get all session ids from database   # get all session ids from database
515   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}'")
516   # get all other_menutiem ids from database   # get all other_menuitem ids from database
517   all_other_ids=$(mysqldo "select id from cfg_other_menuitems where serial='${ALX_SERIAL}'")   all_other_ids=$(mysqldo "select id from cfg_other_menuitems where serial='${ALX_SERIAL}'")
518     # get all plugin ids from database
519     all_plugin_ids=$(mysqldo "select id from cfg_plugins where serial='${ALX_SERIAL}'")
520    
521   # get screensaver settings   # get screensaver settings
522   evaluate_table cfg_screensaver   evaluate_table cfg_screensaver
# Line 441  config_sessions() Line 569  config_sessions()
569   addconfig "[startup] {nohup xautolock -time ${cfg_screensaver_timeout} -locker 'xlock -mode ${cfg_screensaver_screensaver} ${screensaver_passwd_cmd}' > /dev/null &}"   addconfig "[startup] {nohup xautolock -time ${cfg_screensaver_timeout} -locker 'xlock -mode ${cfg_screensaver_screensaver} ${screensaver_passwd_cmd}' > /dev/null &}"
570   fi   fi
571    
572   # add autostart session   # add plugins autostart
573   if [[ ! -z ${cfg_autostart_session} ]]   for i in ${all_plugin_ids}
574   then   do
575   # sleep one second to wait until busybox is fully initialized and the screen is really centered   evaluate_table cfg_plugins "where serial='${ALX_SERIAL}' and id='${i}'"
576   addconfig "[startup] {sleep 1 && nohup nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_autostart_session}) &}"   if [[ -x ${ALX_PLUGINS}/${cfg_plugins_plugin}/plugin.sh ]]
577   fi   then
578     eval $(${ALX_PLUGINS}/${cfg_plugins_plugin}/plugin.sh autostart)
579    
580     if [[ ${PLUGIN_AUTOSTART} = 1 ]]
581     then
582     addconfig "[startup] {${progsh_path}/$(fix_whitespaces ${PLUGIN_MENUITEM_NAME}) &}"
583     fi
584     # unset all variables
585     unset PLUGIN_AUTOSTART
586     unset PLUGIN_MENUITEM_NAME
587     fi
588     done
589    
590   # fluxbox hotkeys   # fluxbox hotkeys
591   if [ -f ${ALX_SKELETONS}/fluxbox/keys ]   if [ -f ${ALX_SKELETONS}/fluxbox/keys ]
# Line 469  config_sessions() Line 608  config_sessions()
608   # add a newline (maybe there is no crlf in the header)   # add a newline (maybe there is no crlf in the header)
609   addconfig   addconfig
610    
611     # delete all progs
612     [ -d ${progsh_path} ] && rm -rf ${progsh_path}
613     install -d ${progsh_path}
614    
615   # first generate session files   # first generate session files
616   for i in ${all_ses_ids}   for i in ${all_ses_ids}
617   do   do
618   evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"   evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"
619   generate_ica_session_file \  
620   --session "${cfg_sessions_session}" \   # generate STOREFRONT/PNABROWSE compatible session
621   --filename "$(fix_whitespaces ${cfg_sessions_filename})" \   case "${cfg_sessions_browseradrs}" in
622   --username "${cfg_sessions_username}" \   "http://"*|"https://"* )
623   --password "${cfg_sessions_password}" \   # run storefront_enumerate on startup to get all available sessions
624   --domain "${cfg_sessions_domain}" \   storefront_enumerate=1
625   --server "${cfg_sessions_browseradrs}" \   storefront_store="$(sanitize_store ${cfg_sessions_browseradrs})"
626   --colordepth "${cfg_graphic_depth}"   store_found=0
627     for _store in ${all_storefront_stores}
628     do
629     if [[ ${storefront_store} = ${_store} ]]
630     then
631     store_found=1
632     fi
633     done
634     if [[ ${store_found} = 0 ]]
635     then
636     all_storefront_stores="${all_storefront_stores} ${storefront_store}"
637     generate_storefront_sh \
638     --method "enumerate" \
639     --filename "store-enumerate_${storefront_store}_.sh" \
640     --username "${cfg_sessions_username}" \
641     --password "${cfg_sessions_password}" \
642     --domain "${cfg_sessions_domain}" \
643     --server "${cfg_sessions_browseradrs}"
644     fi
645    
646     # generate STOREFRONT/PNABROWSE compatible session
647     generate_storefront_sh \
648     --method "launch" \
649     --session "${cfg_sessions_session}" \
650     --filename "$(fix_whitespaces ${cfg_sessions_filename})" \
651     --username "${cfg_sessions_username}" \
652     --password "${cfg_sessions_password}" \
653     --domain "${cfg_sessions_domain}" \
654     --server "${cfg_sessions_browseradrs}"
655     ;;
656     *)
657     # generate ICA compatible session
658     generate_ica_session_file \
659     --session "${cfg_sessions_session}" \
660     --filename "$(fix_whitespaces ${cfg_sessions_filename})" \
661     --username "${cfg_sessions_username}" \
662     --password "${cfg_sessions_password}" \
663     --domain "${cfg_sessions_domain}" \
664     --server "${cfg_sessions_browseradrs}" \
665     --colordepth "${cfg_graphic_depth}"
666     # gen prog startup wrapper
667     generate_program_sh \
668     --name "$(fix_whitespaces ${cfg_sessions_filename})" \
669     --exec "wfica-launcher" \
670     --param "${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_sessions_filename})" \
671     --dest "${progsh_path}/$(fix_whitespaces ${cfg_sessions_filename})" \
672     "${workdir}"
673     ;;
674     esac
675    
676   # fluxbox menusession   # fluxbox menusession
677   addconfig "[exec] (${cfg_sessions_session}) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_sessions_filename})}"   addconfig "[exec] (${cfg_sessions_session}) {${progsh_path}/$(fix_whitespaces ${cfg_sessions_filename})}"
678   done   done
679     if [[ ${storefront_enumerate} = 1 ]]
680   # delete all progs   then
681   progsh_path="${ALX_UNPRIV_HOME}/.alxprogs"   for _store in ${all_storefront_stores}
682   [ -d ${progsh_path} ] && rm -rf ${progsh_path}   do
683   install -d ${progsh_path}   CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/apps"
684     addconfig "[startup] {${progsh_path}/store-enumerate_${_store}_.sh &}"
685     done
686     fi
687    
688   # add other menuitems   # add other menuitems
689   for i in ${all_other_ids}   for i in ${all_other_ids}
# Line 515  config_sessions() Line 709  config_sessions()
709   --dest "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \   --dest "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \
710   "${workdir}"   "${workdir}"
711    
712     CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/menu"
713   addconfig "[exec] (${cfg_other_menuitems_name}) {${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})} ${cfg_other_menuitems_icon}"   addconfig "[exec] (${cfg_other_menuitems_name}) {${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})} ${cfg_other_menuitems_icon}"
714   done   done
715    
716     # add plugins
717     for i in ${all_plugin_ids}
718     do
719     evaluate_table cfg_plugins "where serial='${ALX_SERIAL}' and id='${i}'"
720     if [[ -x ${ALX_PLUGINS}/${cfg_plugins_plugin}/plugin.sh ]]
721     then
722     eval $(${ALX_PLUGINS}/${cfg_plugins_plugin}/plugin.sh menuitem)
723    
724     # abort if name or exec is empty
725     [[ -z ${PLUGIN_MENUITEM_NAME} ]] && continue
726     [[ -z ${PLUGIN_MENUITEM_EXEC} ]] && continue
727    
728     # now echo config line for fluxbox-menu
729     # make it "configureable" :p
730     if [[ -n ${PLUGIN_MENUITEM_WORKDIR} ]]
731     then
732     workdir="--workdir ${PLUGIN_MENUITEM_WORKDIR}"
733     fi
734     if [[ -n ${PLUGIN_MENUITEM_ICON} ]]
735     then
736     PLUGIN_MENUITEM_ICON="<${PLUGIN_MENUITEM_ICON}>"
737     fi
738    
739     # gen prog startup wrapper
740     generate_program_sh \
741     --name "${PLUGIN_MENUITEM_NAME}" \
742     --exec "${PLUGIN_MENUITEM_EXEC}" \
743     --param "${PLUGIN_MENUITEM_PARAM}" \
744     --dest "${progsh_path}/$(fix_whitespaces ${PLUGIN_MENUITEM_NAME})" \
745     "${workdir}"
746    
747     CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/menu"
748     addconfig "[exec] (${PLUGIN_MENUITEM_NAME}) {${progsh_path}/$(fix_whitespaces ${PLUGIN_MENUITEM_NAME})} ${PLUGIN_MENUITEM_ICON}"
749     fi
750    
751     # unset all variables
752     unset PLUGIN_MENUITEM_NAME
753     unset PLUGIN_MENUITEM_EXEC
754     unset PLUGIN_MENUITEM_PARAM
755     unset PLUGIN_MENUITEM_WORKDIR
756     unset PLUGIN_MENUITEM_ICON
757     done
758    
759     # add autostart session
760     if [[ ! -z ${cfg_autostart_session} ]]
761     then
762     CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/apps"
763     # sleep one second to wait until busybox is fully initialized and the screen is really centered
764     addconfig "[startup] {sleep 1 && ${progsh_path}/$(fix_whitespaces ${cfg_autostart_session}) &}"
765     fi
766    
767   # fluxbox menu footer   # fluxbox menu footer
768   cat ${ALX_SKELETONS}/fluxbox/menu.footer >> ${ALX_UNPRIV_HOME}/.fluxbox/menu   CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/menu"
769     cat ${ALX_SKELETONS}/fluxbox/menu.footer >> ${CONFIG}
770   # add a newline (maybe there is no crlf in the footer)   # add a newline (maybe there is no crlf in the footer)
771   addconfig   addconfig
772    
773   # now it's a good time to generate *all* icons :)   # now it's a good time to generate *all* icons :)
774   generate_all_desktop_icons "${all_ses_ids}" "${all_other_ids}"   generate_all_desktop_icons "${all_ses_ids}" "${all_other_ids}" "${all_plugin_ids}"
775    
776   # fix permissions   # fix permissions
777   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
778   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox   chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
779   chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox   chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
780   chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop   chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop
  chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc  
781  }  }

Legend:
Removed from v.2565  
changed lines
  Added in v.6780