--- alx-src/trunk/alxconfig-ng/functions/config_sessions.sh 2005/04/21 08:46:44 271 +++ alx-src/trunk/alxconfig-ng/functions/config_sessions.sh 2005/08/28 19:29:35 304 @@ -1,19 +1,18 @@ -# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.6 2005-04-21 08:46:44 niro Exp $ +# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.11 2005-08-28 19:29:35 niro Exp $ # configures ica-sessions on the host via mysql db settings get_sessions_settings() { local x i all count - #all arrays: + # all arrays: # -> session1 session2 ... sessionN - #get settings from database + # get settings from database all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "select filename from cfg_sessions where serial='${ALX_SERIAL}'") - #"select session from cfg_sessions where serial='${ALX_SERIAL}'") - #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) declare -i i=0 if [ -n "${all}" ] then @@ -32,11 +31,11 @@ get_autostart_settings() { - #get settings from database + # get settings from database ALX_AUTOSTART=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "select session from cfg_autostart where serial='${ALX_SERIAL}'") - export ALX_SESSIONS + export ALX_AUTOSTART } generate_ica_session_files() @@ -44,7 +43,6 @@ local all_ids local i local x - local k local server local ses_session local ses_filename @@ -52,67 +50,287 @@ local ses_domain local ses_password local ses_browseradrs + local ses_colors - #get settings from database + # get settings from database all_ids=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "select id from cfg_sessions where serial='${ALX_SERIAL}'") - declare -i x=0 for i in ${all_ids} do # get settings - ses_session[${x}]=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + ses_session=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "select session from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") - ses_filename[${x}]=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + ses_filename=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "select filename from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") - ses_username[${x}]=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + 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[${x}]=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + 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[${x}]=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + 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[${x}]=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + ses_browseradrs=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "select browseradrs from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") + # get the right colors + ses_colors=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "select depth from cfg_graphic where serial='${ALX_SERIAL}'") + case ${ses_colors} in + 24) ses_colors="8";; + 16) ses_colors="4";; + 8) ses_colors="2";; + *) ses_colors="2";; + esac + # write session files echo '[WFClient]' > ${ALX_ICA_SESSIONS}/${ses_filename} echo 'Version=2' >> ${ALX_ICA_SESSIONS}/${ses_filename} OLD_IFS="$IFS" IFS=";" - declare -i k=0 - for server in ${ses_browseradrs[${x}]} + declare -i x=0 + for server in ${ses_browseradrs} do - (( k++ )) - echo "TcpBrowserAddress${k}=${server}" >> ${ALX_ICA_SESSIONS}/${ses_filename} + (( x++ )) + echo "TcpBrowserAddress${x}=${server}" >> ${ALX_ICA_SESSIONS}/${ses_filename} done IFS="${OLD_IFS}" - unset k + unset x unset OLD_IFS echo 'ScreenPercent=0' >> ${ALX_ICA_SESSIONS}/${ses_filename} echo '[ApplicationServers]' >> ${ALX_ICA_SESSIONS}/${ses_filename} - echo "${ses_session[${x}]}=" >> ${ALX_ICA_SESSIONS}/${ses_filename} + echo "${ses_session}=" >> ${ALX_ICA_SESSIONS}/${ses_filename} - echo "[${ses_session[${x}]}]" >> ${ALX_ICA_SESSIONS}/${ses_filename} - echo "Address=${ses_session[${x}]}" >> ${ALX_ICA_SESSIONS}/${ses_filename} - echo "InitialProgram=#${ses_session[${x}]}" >> ${ALX_ICA_SESSIONS}/${ses_filename} - echo 'DesiredColor=8' >> ${ALX_ICA_SESSIONS}/${ses_filename} + echo "[${ses_session}]" >> ${ALX_ICA_SESSIONS}/${ses_filename} + echo "Address=${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename} + echo "InitialProgram=#${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename} + echo "DesiredColor=${ses_colors}" >> ${ALX_ICA_SESSIONS}/${ses_filename} echo 'TransportDriver=TCP/IP' >> ${ALX_ICA_SESSIONS}/${ses_filename} echo 'WinStationDriver=ICA 3.0' >> ${ALX_ICA_SESSIONS}/${ses_filename} - echo "ClearPassword=${ses_password[${x}]}" >> ${ALX_ICA_SESSIONS}/${ses_filename} - echo "Username=${ses_username[${x}]}" >> ${ALX_ICA_SESSIONS}/${ses_filename} - echo "Domain=${ses_domain[${x}]}" >> ${ALX_ICA_SESSIONS}/${ses_filename} + echo "ClearPassword=${ses_password}" >> ${ALX_ICA_SESSIONS}/${ses_filename} + echo "Username=${ses_username}" >> ${ALX_ICA_SESSIONS}/${ses_filename} + echo "Domain=${ses_domain}" >> ${ALX_ICA_SESSIONS}/${ses_filename} echo 'UseFullScreen=Yes' >> ${ALX_ICA_SESSIONS}/${ses_filename} echo 'NoWindowManager=True' >> ${ALX_ICA_SESSIONS}/${ses_filename} done +} + +get_other_menuitems() +{ + local x i count name exec icon workdir + + # all arrays: + # -> session1 session2 ... sessionN + + # get settings from database + count=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'") + + # get all instances and put them into an array + if [ -n "${count}" ] + then + for x in ${count} + do + # to be sure + 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 +} + + +# helper functions for generate all desktop icons +generate_icon() +{ + local name + local icon + local command + local dest + local yres + local xres + local iwidth + local iheight + + # very basic getops + for i in $* + do + case $1 in + --name|-n) shift; name="$1" ;; + --command|-c) shift; command="$1" ;; + --icon|-i) shift; icon="$1" ;; + --dest|-d) shift; dest="$1" ;; + --xres|-x) shift; xres="$1" ;; + --yres|-y) shift; yres="$1" ;; + --icon-width|-w) shift; iwidth="$1" ;; + --icon-height|-h) shift; iheight="$1" ;; + esac + shift + done + + # some sanity checks : + + # abort if name or command not given + [ -z "${name}" ] && return 1 + [ -z "${command}" ] && return 1 + + # use some defaults for icon, dest, {x,y}res + [ -z "${xres}" ] && xres=20 + [ -z "${yres}" ] && xres=20 + [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk" + if [ -z "${icon}" ] || [ ! -f "${icon}" ] + then + icon="${ALX_SESSIONS_ICONS}/default.png" + fi + + echo "table Icon" > ${dest} + echo " Type: Program" >> ${dest} + echo " Caption: ${name}" >> ${dest} + echo " Command: ${command}" >> ${dest} + echo " Icon: ${icon}" >> ${dest} + echo " X: ${xres}" >> ${dest} + echo " Y: ${yres}" >> ${dest} + + # add these only if not zero + if [ -n "${iwidth}" ] && [ -n "${iheight}" ] + then + echo " IconWidth: ${iwidth}" >> ${dest} + echo " IconHeight: ${iheight}" >> ${dest} + fi + + echo "end" >> ${dest} +} + +generate_all_desktop_icons() +{ + local res + local xres + local yres + local icon_list + local x + local y + local item + + # get the resolution + res=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "select resolution from cfg_graphic where serial='${ALX_SERIAL}'") + + # split res to x & y + xres="$(echo ${res} | cut -dx -f1)" + yres="$(echo ${res} | cut -dx -f2)" + + # top left edge of the icon is given in config file + # remove a little bit to simulate the bottom-right edge + xres="$(( ${xres} - 120 ))" + yres="$(( ${yres} - 80 ))" + + # basic config + cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc + + # clean desktop icon location + [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop + install -d ${ALX_UNPRIV_HOME}/.xtdesktop + + + # default settings + declare -i x=20 + declare -i y=20 + + # first all ica sessions + local count=${#ALX_SESSIONS[*]} + for (( i=0; i < count; i++ )) + do + icon_list="${icon_list} $(basename ${ALX_SESSIONS[${i}] .ica})" + done + + for item in ${icon_list} + do + # abort if empty + [ -z "${item}" ] && continue - (( x++ )) + # new line if x > xres + if [ ${x} -ge ${xres} ];then + x=20 + y=$((${y} + 80)) + fi + + # new row if y > yres + if [ ${y} -ge ${yres} ];then + x=$((${x} + 120)) + y=20 + + # re-check x + [ ${x} -ge ${xres} ] && x=20 + fi + + generate_icon \ + --name "${item}" \ + --command "wfica ${ALX_ICA_SESSIONS}/${item}.ica" \ + --icon "${ALX_SESSIONS_ICONS}/${item}.png" \ + --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \ + --xres "${x}" \ + --yres "${y}" + + y=$((${y} + 80)) + done + + + # last but not least gen a icon with some sys informations + local sysinfo + local hostname + local osversion + + osversion="$(< /etc/mageversion)" + hostname=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "select hostname from cfg_network where serial='${ALX_SERIAL}'") + sysinfo="Hostname: ${hostname} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)" + + # now get the right position: + # restore orig values of xres + xres="$(( ${xres} + 120 ))" + # default y pos (full yres -22 = cur yres + 58 !) + yres="$(( ${yres} + 58 ))" + # middle of the screen + # (no txt - length required, xtdesk manage that itself) + xres="$(( ${xres} / 2))" + + generate_icon \ + --name "${sysinfo}" \ + --command "exit 0" \ + --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \ + --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \ + --xres "${xres}" \ + --yres "${yres}" \ + --icon-width "1" \ + --icon-height "1" } config_sessions() @@ -120,12 +338,13 @@ # generate ica session files generate_ica_session_files - #first of all get the vars + # first of all get the vars get_sessions_settings get_autostart_settings local count=${#ALX_SESSIONS[*]} local icon + local i # DEBUG # declare -i i=0 @@ -167,16 +386,25 @@ cat ${ALX_SKELETONS}/fluxbox/menu.header \ > ${ALX_UNPRIV_HOME}/.fluxbox/menu + # now fix it with proper messages :P + local ver="$(< /etc/mageversion)" + sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" \ + ${ALX_UNPRIV_HOME}/.fluxbox/menu + # add a newline (maybe there is no crlf in the header) echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu # fluxbox menu sessions for (( i=0; i < count; i++ )) do - echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \ - >> ${ALX_UNPRIV_HOME}/.fluxbox/menu + [ -n "${ALX_SESSIONS[${i}]}" ] && \ + echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \ + >> ${ALX_UNPRIV_HOME}/.fluxbox/menu done + # add other menuitems + get_other_menuitems >> ${ALX_UNPRIV_HOME}/.fluxbox/menu + # fluxbox menu footer cat ${ALX_SKELETONS}/fluxbox/menu.footer \ >> ${ALX_UNPRIV_HOME}/.fluxbox/menu @@ -184,40 +412,15 @@ # add a newline (maybe there is no crlf in the footer) echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu - # now we generate the desktop icons - cat ${ALX_SKELETONS}/idesk/ideskrc \ - > ${ALX_UNPRIV_HOME}/.ideskrc - - # whipe out old stuff and install a fresh directory - [ -d ${ALX_UNPRIV_HOME}/.idesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.idesktop - install -d ${ALX_UNPRIV_HOME}/.idesktop - - local name - for (( i=0; i < count; i++ )) - do - name="$(basename ${ALX_SESSIONS[${i}]} .ica)" - - if [ -f ${ALX_SESSIONS_ICONS}/${name}.png ] - then - icon="${ALX_SESSIONS_ICONS}/${name}.png" - else - icon="${ALX_SESSIONS_ICONS}/default.png" - fi - - echo "table Icon -Caption: ${name} -Command: wfica ${ALX_ICA_SESSIONS}/${name}.ica -Icon: ${icon} -end" > ${ALX_UNPRIV_HOME}/.idesktop/${name}.lnk - done + # now it's a good time to generate *all* icons :) + generate_all_desktop_icons # set correct permissions chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME} chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox - chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop - chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc - + chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop + chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc # unset vars unset ALX_SESSIONS