--- alx-src/trunk/alxconfig-ng/functions/config_sessions.sh 2005/08/28 22:50:09 311 +++ alx-src/branches/alxconf_20060908/alxconfig-ng/functions/config_sessions.sh 2009/02/04 19:51:39 543 @@ -1,4 +1,4 @@ -# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.12 2005-08-28 22:50:09 niro Exp $ +# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.18 2006-01-26 19:55:53 niro Exp $ # configures ica-sessions on the host via mysql db settings get_sessions_settings() @@ -9,8 +9,7 @@ # -> 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}'") + all=$(mysqldo "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 @@ -26,18 +25,32 @@ count=0 fi + # get settings from database + ALX_PROGRAMS=$(mysqldo "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}'") + ALX_AUTOSTART=$(mysqldo "select session from cfg_autostart where serial='${ALX_SERIAL}'") export ALX_AUTOSTART } +get_screensaver_settings() +{ + ALX_SCRN_SAVER=$(mysqldo "select screensaver from cfg_screensaver where serial='${ALX_SERIAL}'") + ALX_SCRN_TIMEOUT=$(mysqldo "select timeout from cfg_screensaver where serial='${ALX_SERIAL}'") + ALX_SCRN_PASSWD=$(mysqldo "select password from cfg_screensaver where serial='${ALX_SERIAL}'") + + export ALX_SCRN_SAVER + export ALX_SCRN_TIMEOUT + export ALX_SCRN_PASSWD +} + generate_ica_session_files() { local all_ids @@ -53,33 +66,21 @@ 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}'") + all_ids=$(mysqldo "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}'") + ses_session=$(mysqldo "select session from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") + ses_filename=$(mysqldo "select filename from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") + ses_username=$(mysqldo "select username from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") + ses_domain=$(mysqldo "select domain from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") + ses_password=$(mysqldo "select password from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'") + ses_browseradrs=$(mysqldo "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}'") + ses_colors=$(mysqldo "select depth from cfg_graphic where serial='${ALX_SERIAL}'") + # convert to ica session file values case ${ses_colors} in 24) ses_colors="8";; 16) ses_colors="4";; @@ -121,52 +122,83 @@ 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 count name exec icon workdir + local x i progsh_path 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 settings from database -> now stored in ALX_PROGRAMS - # 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 -} + # 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=$(mysqldo "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") + exec=$(mysqldo "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") + workdir=$(mysqldo "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") + icon=$(mysqldo "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'") + + # now echo config line for fluxbox-menu + # make it "configureable" :P + [ -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() @@ -179,6 +211,7 @@ local xres local iwidth local iheight + local deficon # very basic getops for i in $* @@ -192,6 +225,7 @@ --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 @@ -208,7 +242,9 @@ [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk" if [ -z "${icon}" ] || [ ! -f "${icon}" ] then - icon="${ALX_SESSIONS_ICONS}/default.png" + # if no default icon is given use default.png + [ -z "${deficon}" ] && deficon="default.png" + icon="${ALX_SESSIONS_ICONS}/${deficon}" fi echo "table Icon" > ${dest} @@ -238,10 +274,11 @@ local x local y local item + local basename_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}'") + res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'") # split res to x & y xres="$(echo ${res} | cut -dx -f1)" @@ -268,7 +305,8 @@ local count=${#ALX_SESSIONS[*]} for (( i=0; i < count; i++ )) do - icon_list="${icon_list} $(basename ${ALX_SESSIONS[${i}]} .ica)" + # filenames ! + icon_list="${icon_list} ${ALX_SESSIONS[${i}]}" done for item in ${icon_list} @@ -291,26 +329,67 @@ [ ${x} -ge ${xres} ] && x=20 fi + # ica icons + # get basename (.ica must be suffix) + basename_item="$(basename ${item} .ica)" + generate_icon \ + --name "${basename_item}" \ + --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/${item}" \ + --icon "${ALX_SESSIONS_ICONS}/${basename_item}.png" \ + --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${basename_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 "wfica ${ALX_ICA_SESSIONS}/${item}.ica" \ + --command "${progsh_path}/${item}" \ --icon "${ALX_SESSIONS_ICONS}/${item}.png" \ --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \ --xres "${x}" \ - --yres "${y}" + --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}'") + hostname=$(mysqldo "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: @@ -341,20 +420,12 @@ # first of all get the vars get_sessions_settings get_autostart_settings + get_screensaver_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 @@ -371,15 +442,31 @@ cat ${ALX_SKELETONS}/fluxbox/apps \ > ${ALX_UNPRIV_HOME}/.fluxbox/apps + # add screensaver + if [[ -n ${ALX_SCRN_SAVER} ]] && [[ -n ${ALX_SCRN_TIMEOUT} ]] + then + local ALX_PASSWD_CMD + + if [[ -z ${ALX_SCRN_PASSWD} ]] || [[ ${ALX_SCRN_PASSWD} = NULL ]] + then + ALX_PASSWD_CMD="-nolock" + else + ALX_PASSWD_CMD="-cpasswd $(openssl passwd ${ALX_SCRN_PASSWD})" + fi + + echo "[startup] {nohup xautolock -time ${ALX_SCRN_TIMEOUT} -locker 'xlock -mode ${ALX_SCRN_SAVER} ${ALX_PASSWD_CMD}' > /dev/null &}" \ + >> ${ALX_UNPRIV_HOME}/.fluxbox/apps + fi + # add autostart session if [[ ${ALX_AUTOSTART} != "" ]] then - echo "[startup] {wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART}}" \ + echo "[startup] {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART}}" \ >> ${ALX_UNPRIV_HOME}/.fluxbox/apps fi # fluxbox hotkeys - cat ${ALX_SKELETONS}/fluxbox/apps \ + cat ${ALX_SKELETONS}/fluxbox/keys \ > ${ALX_UNPRIV_HOME}/.fluxbox/keys # fluxbox menu header @@ -398,7 +485,7 @@ 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}]}}" \ + echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \ >> ${ALX_UNPRIV_HOME}/.fluxbox/menu done @@ -419,9 +506,14 @@ 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 + chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop + chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc # unset vars unset ALX_SESSIONS + unset ALX_PROGRAMS + unset ALX_SCRN_SAVER + unset ALX_SCRN_TIMEOUT + unset ALX_SCRN_PASSWD } +