--- alx-src/trunk/alxconfig-ng/functions/config_sessions.sh 2005/08/28 19:28:58 303 +++ alx-src/trunk/alxconfig-ng/functions/config_sessions.sh 2005/08/28 19:29:35 304 @@ -1,4 +1,4 @@ -# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.10 2005-08-18 02:51:16 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() @@ -167,6 +167,172 @@ 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 + + # 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() { # generate ica session files @@ -246,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