Magellan Linux

Annotation of /alx-src/trunk/alxconfig-ng/functions/config_sessions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 311 - (hide annotations) (download) (as text)
Sun Aug 28 22:50:09 2005 UTC (18 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 11714 byte(s)
fixed a typo

1 niro 311 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.12 2005-08-28 22:50:09 niro Exp $
2 niro 236 # configures ica-sessions on the host via mysql db settings
3    
4     get_sessions_settings()
5     {
6     local x i all count
7    
8 niro 291 # all arrays:
9 niro 236 # -> session1 session2 ... sessionN
10    
11 niro 291 # get settings from database
12 niro 236 all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
13 niro 246 "select filename from cfg_sessions where serial='${ALX_SERIAL}'")
14 niro 236
15 niro 291 # split'em up and put in an array (only if $all not zero)
16 niro 236 declare -i i=0
17     if [ -n "${all}" ]
18     then
19     for x in ${all}
20     do
21     ALX_SESSIONS[${i}]=${x}
22     ((i++))
23     done
24     count=${i}
25     else
26     count=0
27     fi
28    
29     export ALX_SESSIONS
30     }
31    
32 niro 246 get_autostart_settings()
33     {
34 niro 291 # get settings from database
35 niro 246 ALX_AUTOSTART=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
36     "select session from cfg_autostart where serial='${ALX_SERIAL}'")
37    
38 niro 272 export ALX_AUTOSTART
39 niro 246 }
40    
41     generate_ica_session_files()
42     {
43     local all_ids
44     local i
45     local x
46     local server
47     local ses_session
48     local ses_filename
49     local ses_username
50     local ses_domain
51     local ses_password
52     local ses_browseradrs
53 niro 272 local ses_colors
54 niro 246
55 niro 291 # get settings from database
56 niro 246 all_ids=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
57     "select id from cfg_sessions where serial='${ALX_SERIAL}'")
58    
59     for i in ${all_ids}
60     do
61     # get settings
62 niro 272 ses_session=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
63 niro 246 "select session from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
64    
65 niro 272 ses_filename=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
66 niro 246 "select filename from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
67    
68 niro 272 ses_username=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
69 niro 246 "select username from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
70    
71 niro 272 ses_domain=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
72 niro 246 "select domain from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
73    
74 niro 272 ses_password=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
75 niro 246 "select password from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
76    
77 niro 272 ses_browseradrs=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
78 niro 246 "select browseradrs from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
79    
80 niro 272 # get the right colors
81     ses_colors=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
82     "select depth from cfg_graphic where serial='${ALX_SERIAL}'")
83     case ${ses_colors} in
84     24) ses_colors="8";;
85     16) ses_colors="4";;
86     8) ses_colors="2";;
87     *) ses_colors="2";;
88     esac
89    
90 niro 246 # write session files
91     echo '[WFClient]' > ${ALX_ICA_SESSIONS}/${ses_filename}
92     echo 'Version=2' >> ${ALX_ICA_SESSIONS}/${ses_filename}
93     OLD_IFS="$IFS"
94     IFS=";"
95 niro 272 declare -i x=0
96     for server in ${ses_browseradrs}
97 niro 246 do
98 niro 272 (( x++ ))
99     echo "TcpBrowserAddress${x}=${server}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
100 niro 246 done
101     IFS="${OLD_IFS}"
102 niro 272 unset x
103 niro 246 unset OLD_IFS
104    
105     echo 'ScreenPercent=0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
106    
107     echo '[ApplicationServers]' >> ${ALX_ICA_SESSIONS}/${ses_filename}
108 niro 272 echo "${ses_session}=" >> ${ALX_ICA_SESSIONS}/${ses_filename}
109 niro 246
110 niro 272 echo "[${ses_session}]" >> ${ALX_ICA_SESSIONS}/${ses_filename}
111     echo "Address=${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
112     echo "InitialProgram=#${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
113 niro 273 echo "DesiredColor=${ses_colors}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
114 niro 246 echo 'TransportDriver=TCP/IP' >> ${ALX_ICA_SESSIONS}/${ses_filename}
115     echo 'WinStationDriver=ICA 3.0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
116 niro 272 echo "ClearPassword=${ses_password}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
117     echo "Username=${ses_username}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
118     echo "Domain=${ses_domain}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
119 niro 246 echo 'UseFullScreen=Yes' >> ${ALX_ICA_SESSIONS}/${ses_filename}
120     echo 'NoWindowManager=True' >> ${ALX_ICA_SESSIONS}/${ses_filename}
121     done
122     }
123    
124 niro 277 get_other_menuitems()
125     {
126     local x i count name exec icon workdir
127    
128 niro 291 # all arrays:
129 niro 277 # -> session1 session2 ... sessionN
130    
131 niro 291 # get settings from database
132 niro 277 count=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
133     "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'")
134    
135     # get all instances and put them into an array
136     if [ -n "${count}" ]
137     then
138     for x in ${count}
139     do
140     # to be sure
141     unset name
142     unset exec
143     unset workdir
144     unset icon
145    
146     name=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
147     "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
148    
149     exec=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
150     "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
151    
152     workdir=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
153     "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
154    
155     icon=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
156     "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
157    
158     # debug only
159     #echo "DEBUG: ${x}: name:'${name}' exec:'${exec}' workdir:'${workdir}' ic$
160    
161     # now echo config line for fluxbox-menu
162     # make it "configureable" :P
163     [ -n "${workdir}" ] && workdir="cd ${workdir};"
164     [ -n "${icon}" ] && icon="[${icon}]"
165     echo "[exec] (${name}) {${workdir}${exec}} ${icon}"
166     done
167     fi
168     }
169    
170 niro 304
171     # helper functions for generate all desktop icons
172     generate_icon()
173     {
174     local name
175     local icon
176     local command
177     local dest
178     local yres
179     local xres
180     local iwidth
181     local iheight
182    
183     # very basic getops
184     for i in $*
185     do
186     case $1 in
187     --name|-n) shift; name="$1" ;;
188     --command|-c) shift; command="$1" ;;
189     --icon|-i) shift; icon="$1" ;;
190     --dest|-d) shift; dest="$1" ;;
191     --xres|-x) shift; xres="$1" ;;
192     --yres|-y) shift; yres="$1" ;;
193     --icon-width|-w) shift; iwidth="$1" ;;
194     --icon-height|-h) shift; iheight="$1" ;;
195     esac
196     shift
197     done
198    
199     # some sanity checks :
200    
201     # abort if name or command not given
202     [ -z "${name}" ] && return 1
203     [ -z "${command}" ] && return 1
204    
205     # use some defaults for icon, dest, {x,y}res
206     [ -z "${xres}" ] && xres=20
207     [ -z "${yres}" ] && xres=20
208     [ -z "${dest}" ] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"
209     if [ -z "${icon}" ] || [ ! -f "${icon}" ]
210     then
211     icon="${ALX_SESSIONS_ICONS}/default.png"
212     fi
213    
214     echo "table Icon" > ${dest}
215     echo " Type: Program" >> ${dest}
216     echo " Caption: ${name}" >> ${dest}
217     echo " Command: ${command}" >> ${dest}
218     echo " Icon: ${icon}" >> ${dest}
219     echo " X: ${xres}" >> ${dest}
220     echo " Y: ${yres}" >> ${dest}
221    
222     # add these only if not zero
223     if [ -n "${iwidth}" ] && [ -n "${iheight}" ]
224     then
225     echo " IconWidth: ${iwidth}" >> ${dest}
226     echo " IconHeight: ${iheight}" >> ${dest}
227     fi
228    
229     echo "end" >> ${dest}
230     }
231    
232     generate_all_desktop_icons()
233     {
234     local res
235     local xres
236     local yres
237     local icon_list
238     local x
239     local y
240     local item
241    
242     # get the resolution
243     res=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
244     "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")
245    
246     # split res to x & y
247     xres="$(echo ${res} | cut -dx -f1)"
248     yres="$(echo ${res} | cut -dx -f2)"
249    
250     # top left edge of the icon is given in config file
251     # remove a little bit to simulate the bottom-right edge
252     xres="$(( ${xres} - 120 ))"
253     yres="$(( ${yres} - 80 ))"
254    
255     # basic config
256     cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc
257    
258     # clean desktop icon location
259     [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop
260     install -d ${ALX_UNPRIV_HOME}/.xtdesktop
261    
262    
263     # default settings
264     declare -i x=20
265     declare -i y=20
266    
267     # first all ica sessions
268     local count=${#ALX_SESSIONS[*]}
269     for (( i=0; i < count; i++ ))
270     do
271 niro 311 icon_list="${icon_list} $(basename ${ALX_SESSIONS[${i}]} .ica)"
272 niro 304 done
273    
274     for item in ${icon_list}
275     do
276     # abort if empty
277     [ -z "${item}" ] && continue
278    
279     # new line if x > xres
280     if [ ${x} -ge ${xres} ];then
281     x=20
282     y=$((${y} + 80))
283     fi
284    
285     # new row if y > yres
286     if [ ${y} -ge ${yres} ];then
287     x=$((${x} + 120))
288     y=20
289    
290     # re-check x
291     [ ${x} -ge ${xres} ] && x=20
292     fi
293    
294     generate_icon \
295     --name "${item}" \
296     --command "wfica ${ALX_ICA_SESSIONS}/${item}.ica" \
297     --icon "${ALX_SESSIONS_ICONS}/${item}.png" \
298     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/${item}.lnk" \
299     --xres "${x}" \
300     --yres "${y}"
301    
302     y=$((${y} + 80))
303     done
304    
305    
306     # last but not least gen a icon with some sys informations
307     local sysinfo
308     local hostname
309     local osversion
310    
311     osversion="$(< /etc/mageversion)"
312     hostname=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
313     "select hostname from cfg_network where serial='${ALX_SERIAL}'")
314     sysinfo="Hostname: ${hostname} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)"
315    
316     # now get the right position:
317     # restore orig values of xres
318     xres="$(( ${xres} + 120 ))"
319     # default y pos (full yres -22 = cur yres + 58 !)
320     yres="$(( ${yres} + 58 ))"
321     # middle of the screen
322     # (no txt - length required, xtdesk manage that itself)
323     xres="$(( ${xres} / 2))"
324    
325     generate_icon \
326     --name "${sysinfo}" \
327     --command "exit 0" \
328     --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \
329     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \
330     --xres "${xres}" \
331     --yres "${yres}" \
332     --icon-width "1" \
333     --icon-height "1"
334     }
335    
336 niro 236 config_sessions()
337     {
338 niro 246 # generate ica session files
339     generate_ica_session_files
340    
341 niro 291 # first of all get the vars
342 niro 236 get_sessions_settings
343 niro 246 get_autostart_settings
344 niro 236
345     local count=${#ALX_SESSIONS[*]}
346     local icon
347 niro 272 local i
348 niro 236
349     # DEBUG
350 niro 241 # declare -i i=0
351     # echo count=${count}
352     # echo "Number of new sessions: ${count}"
353     # for ((i=0; i < count; i++))
354     # do
355     # echo "${i} - ${ALX_SESSIONS[${i}]}"
356     # done
357 niro 236
358     # now setup fluxbox for user station
359    
360     # create a fresh fluxbox directory
361     [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox
362     install -d ${ALX_UNPRIV_HOME}/.fluxbox
363    
364     # now generate fluxbox config files
365    
366     # fluxbox main config
367     cat ${ALX_SKELETONS}/fluxbox/init \
368     > ${ALX_UNPRIV_HOME}/.fluxbox/init
369    
370     # fluxbox autostart
371     cat ${ALX_SKELETONS}/fluxbox/apps \
372     > ${ALX_UNPRIV_HOME}/.fluxbox/apps
373    
374 niro 246 # add autostart session
375     if [[ ${ALX_AUTOSTART} != "" ]]
376     then
377     echo "[startup] {wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART}}" \
378     >> ${ALX_UNPRIV_HOME}/.fluxbox/apps
379     fi
380    
381 niro 236 # fluxbox hotkeys
382     cat ${ALX_SKELETONS}/fluxbox/apps \
383     > ${ALX_UNPRIV_HOME}/.fluxbox/keys
384    
385     # fluxbox menu header
386     cat ${ALX_SKELETONS}/fluxbox/menu.header \
387     > ${ALX_UNPRIV_HOME}/.fluxbox/menu
388    
389 niro 291 # now fix it with proper messages :P
390     local ver="$(< /etc/mageversion)"
391     sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" \
392     ${ALX_UNPRIV_HOME}/.fluxbox/menu
393    
394 niro 239 # add a newline (maybe there is no crlf in the header)
395     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
396    
397 niro 236 # fluxbox menu sessions
398     for (( i=0; i < count; i++ ))
399     do
400 niro 277 [ -n "${ALX_SESSIONS[${i}]}" ] && \
401     echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \
402     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
403 niro 236 done
404    
405 niro 277 # add other menuitems
406     get_other_menuitems >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
407    
408 niro 236 # fluxbox menu footer
409     cat ${ALX_SKELETONS}/fluxbox/menu.footer \
410     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
411    
412 niro 239 # add a newline (maybe there is no crlf in the footer)
413     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
414 niro 236
415 niro 304 # now it's a good time to generate *all* icons :)
416     generate_all_desktop_icons
417 niro 236
418     # set correct permissions
419     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
420     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
421     chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
422 niro 304 chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
423     chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc
424 niro 236
425     # unset vars
426     unset ALX_SESSIONS
427     }