# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.13 2005-09-01 18:27:44 niro Exp $ # configures ica-sessions on the host via mysql db settings get_sessions_settings() { local x i all count # all arrays: # -> session1 session2 ... sessionN # get settings from database all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "select filename from cfg_sessions where serial='${ALX_SERIAL}'") # split'em up and put in an array (only if $all not zero) declare -i i=0 if [ -n "${all}" ] then for x in ${all} do ALX_SESSIONS[${i}]=${x} ((i++)) done count=${i} else count=0 fi # get settings from database ALX_PROGRAMS=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'") export ALX_SESSIONS export ALX_PROGRAMS } get_autostart_settings() { # 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_AUTOSTART } generate_ica_session_files() { local all_ids local i local x local server local ses_session local ses_filename local ses_username local ses_domain local ses_password local ses_browseradrs local ses_colors # 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}'") for i in ${all_ids} do # get settings 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=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "select filename from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") 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=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "select domain from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") 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=$(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 x=0 for server in ${ses_browseradrs} do (( x++ )) echo "TcpBrowserAddress${x}=${server}" >> ${ALX_ICA_SESSIONS}/${ses_filename} done IFS="${OLD_IFS}" unset x unset OLD_IFS echo 'ScreenPercent=0' >> ${ALX_ICA_SESSIONS}/${ses_filename} echo '[ApplicationServers]' >> ${ALX_ICA_SESSIONS}/${ses_filename} echo "${ses_session}=" >> ${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}" >> ${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 } # generates a sh file to start programs generate_program_sh() { local dest local name local exec local workdir # very basic getops for i in $* do case $1 in --name|-n) shift; name="$1" ;; --exec|-x) shift; exec="$1" ;; --dest|-d) shift; dest="$1" ;; --workdir|-w) shift; workdir="$1" ;; esac shift done # abort if name, dest or exec not given [ -z "${name}" ] && return 1 [ -z "${exec}" ] && return 1 [ -z "${dest}" ] && return 1 echo "#!/bin/sh" > ${dest} [ -n "${workdir}" ] && echo "cd ${workdir}" >> ${dest} echo "exec ${exec}" >> ${dest} chmod 0755 ${dest} } get_other_menuitems() { local x i progsh_path name exec icon workdir # all arrays: # -> session1 session2 ... sessionN # get settings from database -> now stored in ALX_PROGRAMS # abort if empty [ -z "${ALX_PROGRAMS}" ] && return 0 progsh_path=${ALX_UNPRIV_HOME}/.alxprogs [ -d ${progsh_path} ] && rm -rf ${progsh_path} install -d ${progsh_path} # gen menu items for x in ${ALX_PROGRAMS} 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 "${workdir}" ] && workdir="--workdir ${workdir}" [ -n "${icon}" ] && icon="<${icon}>" # gen prog startup wrapper generate_program_sh \ --name "${name}" \ --exec "${exec}" \ --dest "${progsh_path}/${name}" \ "${workdir}" echo "[exec] (${name}) {${progsh_path}/${name}} ${icon}" done } # 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 local deficon # 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" ;; --default-icon) shift; deficon="$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 # if no default icon is given use default.png [ -z "${deficon}" ] && deficon="default.png" icon="${ALX_SESSIONS_ICONS}/${deficon}" 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 local progsh_path # 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 "${progsh_path}/${item}" \ --icon "${ALX_SESSIONS_ICONS}/${item}.png" \ --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \ --xres "${x}" \ --yres "${y}" y=$((${y} + 80)) done # generate program icons icon_list="${ALX_PROGRAMS}" progsh_path=${ALX_UNPRIV_HOME}/.alxprogs 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 "${progsh_path}/${item}" \ --icon "${ALX_SESSIONS_ICONS}/${item}.png" \ --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \ --xres "${x}" \ --yres "${y}" \ --default-icon "default_item.png" 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 generate_ica_session_files # 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 # echo count=${count} # echo "Number of new sessions: ${count}" # for ((i=0; i < count; i++)) # do # echo "${i} - ${ALX_SESSIONS[${i}]}" # done # now setup fluxbox for user station # create a fresh fluxbox directory [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox install -d ${ALX_UNPRIV_HOME}/.fluxbox # now generate fluxbox config files # fluxbox main config cat ${ALX_SKELETONS}/fluxbox/init \ > ${ALX_UNPRIV_HOME}/.fluxbox/init # fluxbox autostart cat ${ALX_SKELETONS}/fluxbox/apps \ > ${ALX_UNPRIV_HOME}/.fluxbox/apps # add autostart session if [[ ${ALX_AUTOSTART} != "" ]] then echo "[startup] {wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART}}" \ >> ${ALX_UNPRIV_HOME}/.fluxbox/apps fi # fluxbox hotkeys cat ${ALX_SKELETONS}/fluxbox/apps \ > ${ALX_UNPRIV_HOME}/.fluxbox/keys # fluxbox menu header 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 [ -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 # add a newline (maybe there is no crlf in the footer) echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu # 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}/.xtdesktop chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc # unset vars unset ALX_SESSIONS unset ALX_PROGRAMS }